-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (48 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { EmbedAssertions } = require('@discordjs/builders');
const { Client, GatewayIntentBits, EmbedBuilder, Message } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const googleIt = require('google-it') // node i google-it
client.once('ready', () => {
console.log('Ready!');
});
client.on('messageCreate', async (message) => {
if(message.interaction){
if(message.interaction.commandName.toLocaleLowerCase() === "trivia"){
// keeping all 4 option in var
op1 = message.components[0].components[0].label;
op2 = message.components[0].components[1].label;
op3 = message.components[0].components[2].label;
op4 = message.components[0].components[3].label;
text = message.embeds[0].description;
subsval = text.lastIndexOf("You have");
subsval = subsval - 4;
triviaquestion = text.substring(2, subsval); // question of the trivia
const questionembed = new EmbedBuilder()
.setDescription(`**Q. ${triviaquestion}**`)
.setTitle("Couldn't find the answer, check your luck! :wink: ")
.setFooter({text: "NOTE: Sometimes the option maybe incorrect."})
const item = await googleIt({'query': `${triviaquestion}`}) // googles the question
let a = 0;
let i = 0;
while(!a >= 1){ // checking for answers in google
searchedtext = item[i].snippet.toLocaleLowerCase();
if(searchedtext.search(op1.toLocaleLowerCase()) >= 0){
questionembed.setTitle(`Answer: ${op1}`);
break;
} else if(searchedtext.search(op2.toLocaleLowerCase()) >= 0){
questionembed.setTitle(`Answer: ${op2}`);
break;
}else if(searchedtext.search(op3.toLocaleLowerCase()) >= 0){
questionembed.setTitle(`Answer: ${op3}`);
break;
}else if(searchedtext.search(op4.toLocaleLowerCase()) >= 0){
questionembed.setTitle(`Answer: ${op4}`);
break;
}
i++;
// if(i>4) break;
}
await message.channel.send({ content: `<@${message.interaction.user.id}>`, embeds: [questionembed] }) // prints the result
}
})
client.login(TOKEN);