-
-
Save Corex24/89a8d661aee2495776fd263952de8f66 to your computer and use it in GitHub Desktop.
auto reply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define the question and answer database | |
| const questionAnswers = [ | |
| { | |
| question: 'What is your name?', | |
| answer: 'My name is Bot.' | |
| }, | |
| { | |
| question: 'How old are you?', | |
| answer: 'I am a bot. I do not have an age.' | |
| }, | |
| // Add more question-answer pairs here | |
| ]; | |
| // Function to select a random question from the database | |
| function getRandomQuestion() { | |
| return questionAnswers[Math.floor(Math.random() * questionAnswers.length)].question; | |
| } | |
| // Function to get the answer for a given question | |
| function getAnswer(question) { | |
| const matchedQuestion = questionAnswers.find(qa => qa.question.toLowerCase() === question.toLowerCase()); | |
| if (matchedQuestion) { | |
| return matchedQuestion.answer; | |
| } else { | |
| return "I'm sorry, I don't have an answer for that question."; | |
| } | |
| } | |
| // Bot message handler | |
| bot( | |
| { | |
| pattern: /(.*)/, | |
| fromMe: false, | |
| desc: 'nothing', | |
| type: 'misc', | |
| }, | |
| async (message, match) => { | |
| const receivedQuestion = match ? match[1] : null; | |
| if (receivedQuestion) { | |
| // Get answer for the received question | |
| const answer = getAnswer(receivedQuestion); | |
| // Send the answer as a reply | |
| await message.reply(answer); | |
| } else { | |
| // If no question is received, ask a random question | |
| const randomQuestion = getRandomQuestion(); | |
| // Send the random question as a reply | |
| await message.reply(randomQuestion); | |
| } | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment