diff --git a/index.mjs b/index.mjs index 24f89a2..1558e33 100644 --- a/index.mjs +++ b/index.mjs @@ -20,30 +20,6 @@ const client = new Client(process.env.TWITTER_BEARER_TOKEN); //twitter api clien const botName = process.env.BOT_USERNAME; //Use the same Twitter username whose API key and token are being used. - - -/*################################## OPENAI API #########################################*/ -const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); -const openai = new OpenAIApi(configuration); - -/*############################# GET THE RESP. FROM OPENAI API ##########################*/ -async function getJoke(questions) { - try { - const response = await openai.createCompletion({ - model: "text-davinci-002", - prompt: `Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: ${questions}\nMarv:`, - temperature: 0.5, - max_tokens: 60, - top_p: 0.3, - frequency_penalty: 0.5, - presence_penalty: 0, - }); - return response.data.choices[0].text; - } catch (error) { - console.log(error); - } -} - /*############################# REPLY TO TWITTER API #################################*/ async function replyToTweet(joke, author_id, id) { const data = { @@ -122,16 +98,21 @@ async function getMentionedTweet() { /* IF BOT IS MENTIONED **IN** THE TWEET */ if (response.includes.tweets === undefined) { //check if the tweet is a reply to another tweet - const tweet = JSON.stringify(response.data.text, null, 2).replace(/(https?:\/\/[^\s]+)/g, '').replace(/"/g, '').trim(); - const joke = "works" - await replyToTweet(joke, response.data.author_id, response.data.id); + const tweet = JSON.stringify(response.data.text, null, 2).replace(/(https?:\/\/[^\s]+)/g, '').replace(/"/g, '').trim();r + + console.log(response.data) + const reply = "works" + await replyToTweet(reply, response.data.author_id, response.data.id); } else { /* IF BOT IS MENTIONED **UNDER** THE TWEET THEN IT WILL REPLY TO WHOEVER MENTIONED THE BOT BUT WILL TAKE QUESTIONS FROM THE ORIGINAL AUTHORS TWEET */ + let userID = response.data.author_id + + console.log("User ID: ") const tweet = JSON.stringify(response.includes.tweets[0].text, null, 2).replace(/(https?:\/\/[^\s]+)/g, '').replace(/"/g, '').trim(); //remove the urls and double quotes from the tweet and trim the spaces - const joke = "WORKS" //get the joke from the openai api - await replyToTweet(joke, response.data.author_id, response.data.id); // reply to the + const reply = "Not Programmed Yet!" //get the joke from the openai api + await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the } } }