diff --git a/index.js b/index.js new file mode 100644 index 0000000..d4ef98c --- /dev/null +++ b/index.js @@ -0,0 +1,242 @@ +// FAQ BOR BY LISA NIGHTSHADE +// EMAIL: lisahonkay@gmail.com +// CC-BY-SA-4.0 +// VERSION 2 + +const { Client, GatewayIntentBits, MessageEmbed, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); +const natural = require('natural'); +const { BayesClassifier } = natural; +const classifier = new BayesClassifier +const tokenizer = new natural.WordTokenizer(); +const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); + +const channelId = ''; // Replace with your channel ID + +// COINS CATEGORY +classifier.addDocument('how can I get more coins', 'coins'); +classifier.addDocument('any advice on earning coins', 'coins'); +classifier.addDocument('tips for getting coins quickly', 'coins'); +classifier.addDocument('best ways to earn coins', 'coins'); +classifier.addDocument('methods for obtaining coins', 'coins'); +classifier.addDocument('how can I gather coins', 'coins'); +classifier.addDocument('strategies to collect coins', 'coins'); +classifier.addDocument('what are the techniques to get coins', 'coins'); +// INVITE REWARD CATEGORY +classifier.addDocument('how to claim invite reward', 'invite'); +classifier.addDocument('claim invite reward', 'invite'); +classifier.addDocument('can I get an invite reward', 'invite'); +classifier.addDocument('is there an invite reward', 'invite'); +classifier.addDocument('steps to claim invite reward', 'invite'); +classifier.addDocument('redeem invite reward', 'invite'); +classifier.addDocument('process to get invite reward', 'invite'); +classifier.addDocument('guide to claim invite reward', 'invite'); +classifier.addDocument('how do I earn invite reward', 'invite'); +classifier.addDocument('how can I receive invite reward', 'invite'); +classifier.addDocument('getting reward for invites', 'invite'); +classifier.addDocument('can I receive a reward for inviting friends', 'invite'); +classifier.addDocument('how to get reward for inviting others', 'invite'); +classifier.addDocument('steps to redeem invite reward', 'invite'); +classifier.addDocument('how to obtain invite reward', 'invite'); +// NEGATIVE COINS/INVITE CATEGORY +classifier.addDocument('how many coins do I need', 'not related'); +classifier.addDocument('coins are used for', 'not related'); +classifier.addDocument('what can I buy with coins', 'not related'); +classifier.addDocument('you need to claim invite reward', 'not related'); +classifier.addDocument('what is the invite reward', 'not related'); +classifier.addDocument('can I invite more friends', 'not related'); +classifier.addDocument('how many people can I invite', 'not related'); +classifier.addDocument('is there a limit to invites', 'not related'); +classifier.addDocument('how many invites are allowed', 'not related'); +classifier.addDocument('how to increase invite count', 'not related'); +classifier.addDocument('what are the rules for invites', 'not related'); +classifier.addDocument('what is the maximum number of invites', 'not related'); +classifier.addDocument('can I invite more than ten people', 'not related'); +classifier.addDocument('how many friends can I invite', 'not related'); +classifier.addDocument('is there an invite limit', 'not related'); +classifier.addDocument('what is the invite threshold', 'not related'); +classifier.addDocument('how does the invite system work', 'not related'); +classifier.addDocument('rules for inviting people', 'not related'); +classifier.addDocument('guidelines for inviting friends', 'not related'); +classifier.addDocument('how to handle multiple invites', 'not related'); +classifier.addDocument('coins', 'not related'); +classifier.addDocument('invite', 'not related'); +classifier.addDocument('what is coins', 'not related'); +classifier.addDocument('tell me about coins', 'not related'); +// NOT RELATED CATEGORY \\ +classifier.addDocument('how is the weather today', 'not related'); +classifier.addDocument('good afternoon', 'not related'); +classifier.addDocument('see you later', 'not related'); +classifier.addDocument('can you help me with something else', 'not related'); +classifier.addDocument('what do you think about this', 'not related'); +classifier.addDocument('where are you from', 'not related'); +classifier.addDocument('what is your favorite color', 'not related'); +classifier.addDocument('tell me a joke', 'not related'); +classifier.addDocument('what is your opinion', 'not related'); +classifier.addDocument('do you like movies', 'not related'); +classifier.addDocument('how old are you', 'not related'); +classifier.addDocument('what are your hobbies', 'not related'); +classifier.addDocument('where did you go', 'not related'); +classifier.addDocument('can you suggest a book', 'not related'); +classifier.addDocument('what music do you like', 'not related'); +classifier.addDocument('goodbye', 'not related'); +classifier.addDocument('what are your plans', 'not related'); +classifier.addDocument('how was your day', 'not related'); +classifier.addDocument('tell me a story', 'not related'); +classifier.addDocument('what is your dream', 'not related'); +classifier.addDocument('do you like sports', 'not related'); +classifier.addDocument('what is your favorite food', 'not related'); +classifier.addDocument('where is the nearest restaurant', 'not related'); +classifier.addDocument('do you have a pet', 'not related'); +classifier.addDocument('what are you thinking about', 'not related'); +classifier.addDocument('what do you do for fun', 'not related'); +classifier.addDocument('tell me something interesting', 'not related'); +classifier.addDocument('what is your favorite book', 'not related'); +classifier.addDocument('how do you spend your weekends', 'not related'); +classifier.addDocument('what is your favorite movie', 'not related'); +classifier.addDocument('can you recommend a song', 'not related'); +classifier.addDocument('what are your interests', 'not related'); +classifier.addDocument('how is everything', 'not related'); +classifier.addDocument('do you watch TV', 'not related'); +classifier.addDocument('what do you like to eat', 'not related'); +classifier.addDocument('how is your family', 'not related'); +classifier.addDocument('what are your favorite hobbies', 'not related'); +classifier.addDocument('what is the time', 'not related'); +classifier.addDocument('how do you feel today', 'not related'); +classifier.addDocument('do you play video games', 'not related'); +classifier.addDocument('what is your job', 'not related'); +classifier.addDocument('what do you do for a living', 'not related'); +classifier.addDocument('how do you relax', 'not related'); +classifier.addDocument('what is your favorite sport', 'not related'); +classifier.addDocument('do you have any siblings', 'not related'); +classifier.addDocument('what is your favorite season', 'not related'); +classifier.addDocument('how was your weekend', 'not related'); +classifier.addDocument('where do you live', 'not related'); +classifier.addDocument('do you like to travel', 'not related'); +classifier.addDocument('what languages do you speak', 'not related'); +classifier.addDocument('what is your favorite place', 'not related'); +classifier.addDocument('can you tell me about yourself', 'not related'); +classifier.addDocument('what are you doing now', 'not related'); +classifier.addDocument('do you enjoy reading', 'not related'); +classifier.addDocument('where do you work', 'not related'); +classifier.addDocument('what is your favorite TV show', 'not related'); +classifier.addDocument('do you have any hobbies', 'not related'); +classifier.addDocument('how do you spend your free time', 'not related'); +classifier.addDocument('what do you think about this situation', 'not related'); +classifier.addDocument('what is your favorite game', 'not related'); +classifier.addDocument('do you like cooking', 'not related'); +classifier.addDocument('what are your thoughts on this', 'not related'); +classifier.addDocument('what is your favorite animal', 'not related'); +classifier.addDocument('do you like to dance', 'not related'); +classifier.addDocument('how do you celebrate holidays', 'not related'); +classifier.addDocument('what is your favorite drink', 'not related'); + +classifier.train(); + +client.on('ready', () => { + console.log(`Logged in as ${client.user.tag}!`); +}); + + +client.on('messageCreate', async message => { + if (message.channel.id === channelId && !message.author.bot) { + const userMessage = message.content.toLowerCase(); + const tokens = tokenizer.tokenize(userMessage); + const normalizedMessage = tokens.join(' '); + const classifications = classifier.getClassifications(normalizedMessage); + const confidence = classifications[0].value; + + console.log(userMessage); + console.log(tokens); + console.log(confidence); + console.log(classifications[0].label); + + const coinsKeywords = [ + 'how can I get more coins', + 'how to get coins', + 'any advice on earning coins', + 'tips for getting coins', + 'best ways to earn coins', + 'methods for obtaining coins', + 'how can I gather coins', + 'strategies to collect coins', + 'what are the techniques to get coins', + 'coins', + 'claim reward' + ]; + + const inviteKeywords = [ + 'how to claim invite reward', + 'claim invite reward', + 'can I get an invite reward', + 'is there an invite reward', + 'steps to claim invite reward', + 'redeem invite reward', + 'process to get invite reward', + 'guide to claim invite reward', + 'how do I earn invite reward', + 'how can I receive invite reward', + 'getting reward for invites', + 'can I receive a reward for inviting friends', + 'how to get reward for inviting others', + 'steps to redeem invite reward', + 'how to obtain invite reward', + 'invite', + 'claim reward' + ]; + + const containsCoinsKeyword = coinsKeywords.some(keyword => userMessage.includes(keyword)); + const containsInviteKeyword = inviteKeywords.some(keyword => userMessage.includes(keyword)); + + const isRelevantContext = (message) => { + const irrelevantPhrases = [ + 'why do', + 'what is', + 'tell me about', + 'explain', + 'how does' + ]; + return !irrelevantPhrases.some(phrase => message.includes(phrase)); + }; + + if (classifications[0].label === 'coins' && confidence > 0.03 && userMessage !== "coins" && containsCoinsKeyword && isRelevantContext(userMessage)) { + const embed = new EmbedBuilder() + .setTitle('How to Get Coins') + .setDescription(`Here are some tips on how to get coins...\nConfidence: ${confidence}`) + .setColor('#00FF00'); + + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('delete') + .setLabel('🗑️ Delete') + .setStyle(ButtonStyle.Danger) + ); + + message.reply({ embeds: [embed], components: [row] }); + } else if (classifications[0].label === 'invite' && confidence > 0.03 && userMessage !== "invite" && containsInviteKeyword && isRelevantContext(userMessage)) { + const embed = new EmbedBuilder() + .setTitle('How to Claim Invite Reward') + .setDescription(`Here are some tips on how to claim invite reward...\nConfidence: ${confidence}`) + .setColor('#00FF00'); + + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('delete') + .setLabel('🗑️ Delete') + .setStyle(ButtonStyle.Danger) + ); + + message.reply({ embeds: [embed], components: [row] }); + } + } +}); + +client.on('interactionCreate', async interaction => { + if (!interaction.isButton()) return; + if (interaction.customId === 'delete') { + await interaction.message.delete(); + await interaction.reply({ content: 'Message deleted', ephemeral: true }); + } +}); +client.login(''); // Replace with your bot token