-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (61 loc) · 2.67 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
const { Client, Intents, Interaction } = require("discord.js");
const helpCommandHandler = require("./commands/help");
const pingCommandHandler = require("./commands/ping");
const leaderboardsCommandHandler = require("./commands/leaderboards");
const profileCommandHandler = require("./commands/profile");
const coinsCommandHandler = require("./commands/coins");
const logsCommandHandler = require("./commands/logs");
const { notYetImplemented, unknownInteraction, serverError } = require("./standard.responses");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const db = require("./territorial-db.js");
client.on("ready", () => console.log(`Logged in as ${client.user.tag}.`));
client.on("interactionCreate", async (interaction) => {
if (interaction.isCommand()) {
const { commandName } = interaction;
console.log("Command received: ", commandName);
console.log("User: ", interaction.user.username);
switch (commandName) {
case "help":
await helpCommandHandler.execute(interaction);
break;
case "ping":
await pingCommandHandler.execute(interaction);
break;
case "logs":
await logsCommandHandler.execute(interaction, db);
break;
case "leaderboard":
await leaderboardsCommandHandler.execute(interaction, db);
break;
case "profile":
await profileCommandHandler.execute(interaction, db);
break;
case "coins":
const subcommandName = interaction.options.getSubcommand();
switch (subcommandName) {
case "add":
await coinsCommandHandler.addCoins(interaction);
break;
case "remove":
await coinsCommandHandler.removeCoins(interaction);
break;
case "show":
await coinsCommandHandler.showUserCoins(interaction, db);
break;
default:
await unknownInteraction(interaction);
break;
}
break;
default:
await unknownInteraction(interaction);
break;
} // end commands switch
} else if (interaction.isButton()) {
// for now buttons are only used for commands that require confirmation
coinsCommandHandler.confirmButtonHandler(interaction, db);
} else {
await unknownInteraction(interaction);
}
});
client.login(process.env.TOKEN);