Skip to content

Instantly share code, notes, and snippets.

@Corex24
Forked from icy-r/icy.js
Created February 21, 2025 03:39
Show Gist options
  • Select an option

  • Save Corex24/89a8d661aee2495776fd263952de8f66 to your computer and use it in GitHub Desktop.

Select an option

Save Corex24/89a8d661aee2495776fd263952de8f66 to your computer and use it in GitHub Desktop.
auto reply
// 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