Begining logic

This commit is contained in:
Raven Scott 2022-12-07 19:24:52 +02:00
parent db0daf5963
commit f541ced203

View File

@ -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. 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 #################################*/ /*############################# REPLY TO TWITTER API #################################*/
async function replyToTweet(joke, author_id, id) { async function replyToTweet(joke, author_id, id) {
const data = { const data = {
@ -122,16 +98,21 @@ async function getMentionedTweet() {
/* IF BOT IS MENTIONED **IN** THE TWEET */ /* IF BOT IS MENTIONED **IN** THE TWEET */
if (response.includes.tweets === undefined) { //check if the tweet is a reply to another 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 tweet = JSON.stringify(response.data.text, null, 2).replace(/(https?:\/\/[^\s]+)/g, '').replace(/"/g, '').trim();r
const joke = "works"
await replyToTweet(joke, response.data.author_id, response.data.id); console.log(response.data)
const reply = "works"
await replyToTweet(reply, response.data.author_id, response.data.id);
} else { } else {
/* IF BOT IS MENTIONED **UNDER** THE TWEET THEN IT WILL REPLY TO WHOEVER MENTIONED /* 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 */ 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 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 const reply = "Not Programmed Yet!" //get the joke from the openai api
await replyToTweet(joke, response.data.author_id, response.data.id); // reply to the await replyToTweet(reply, response.data.author_id, response.data.id); // reply to the
} }
} }
} }