-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (75 loc) · 2.61 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// const { Client, GatewayIntentBits } = require('discord.js');
import { Client, GatewayIntentBits } from "discord.js";
import getRandomProblemFromBot from "./bot.js";
import "dotenv/config";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
],
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`); //message when bot is online
});
/*
Returns all commands available for this discord bot
*/
client.on("messageCreate",(message) => {
if(message.content.toLowerCase() === "help"){
const allCommands = ["random","easy","medium","hard","notify"];
let helpMsg = "To get started with using this bot, type any of the following commands" + "\n";
allCommands.forEach((command,index) => {
helpMsg += `**${index + 1}) ${command}**`;
helpMsg += "\n";
});
console.log(helpMsg);
message.reply(helpMsg);
}
});
/*
Returns a random problem from leetcode when the message "random" is typed
*/
client.on("messageCreate", async (message) => {
if (message.content.toLowerCase() === "random") {
const randomQuestionName = await getRandomProblemFromBot("HARD");
const name = randomQuestionName.data.randomQuestion.titleSlug;
const url = `https://leetcode.com/problems/${name}`
message.reply(url);
}
});
/*
Returns a hard random problem from leetcode when the message "hard" is typed
*/
client.on("messageCreate", async (message) => {
if (message.content.toLowerCase() === "hard") {
const randomQuestionName = await getRandomProblemFromBot("HARD");
const name = randomQuestionName.data.randomQuestion.titleSlug;
const url = `https://leetcode.com/problems/${name}`
message.reply(url);
}
});
/*
Returns a medium random problem from leetcode when the message "medium" is typed
*/
client.on("messageCreate", async (message) => {
if (message.content.toLowerCase() === "medium") {
const randomQuestionName = await getRandomProblemFromBot("MEDIUM");
const name = randomQuestionName.data.randomQuestion.titleSlug;
const url = `https://leetcode.com/problems/${name}`
message.reply(url);
}
});
/*
Returns a easy random problem from leetcode when the message "easy" is typed
*/
client.on("messageCreate", async (message) => {
if (message.content.toLowerCase() === "easy") {
const randomQuestionName = await getRandomProblemFromBot("EASY");
const name = randomQuestionName.data.randomQuestion.titleSlug;
const url = `https://leetcode.com/problems/${name}`
message.reply(url);
}
});
client.login(process.env.TOKEN);