-
Notifications
You must be signed in to change notification settings - Fork 0
/
checklist.js
117 lines (112 loc) · 4.17 KB
/
checklist.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const {
Client,
GatewayIntentBits,
Partials,
Collection,
Permissions,
ActionRowBuilder,
SelectMenuBuilder,
MessageButton,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
InteractionType,
ChannelType,
} = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildEmojisAndStickers, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildScheduledEvents, GatewayIntentBits.DirectMessages],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
const fs = require('fs');
const moment = require('moment');
const config = require('./config/config.json');
const SlashRegistry = require('./functions/slashRegistry.js');
const NewChecklist = require('./functions/newChecklist');
const EditChecklist = require('./functions/editChecklist');
client.on('ready', async () => {
console.log("ChecklistBot Logged In");
//Register Slash Commands
if (config.slashGuildIDs.length > 0) {
SlashRegistry.registerCommands(client);
}
}); //End of ready()
//Slash commands
client.on('interactionCreate', async interaction => {
if (interaction.type !== InteractionType.ApplicationCommand) {
return;
}
let user = interaction.user;
if (user.bot == true) {
return;
}
const command = client.commands.get(interaction.commandName);
if (!command) {
return;
}
try {
let slashReturn = await command.execute(client, interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
}).catch(console.error);
}
}); //End of slash commands
//List commands
client.on('interactionCreate', async interaction => {
if (interaction.type !== InteractionType.MessageComponent) {
return;
}
if (!interaction.guildId) {
return;
}
var interactionID = interaction.customId;
//Verify interaction
if (!interactionID.startsWith('ChecklistBot~')) {
return;
}
if (interactionID.startsWith(`ChecklistBot~`)) {
let interactionSplit = interactionID.split('~');
//Verify user
if (interaction.user.username == interactionSplit[2] && interaction.user.discriminator == interactionSplit[3]) {
if (interactionSplit[1] == 'select') {
EditChecklist.itemSelected(client, interaction);
} else if (interactionSplit[1] == 'premadeSelected') {
NewChecklist.modalChecklistPremade(client, interaction);
} else if (interactionSplit[1] == 'markFinished') {
EditChecklist.finishChecklist(client, interaction);
} else if (interactionSplit[1] == 'editChecklist') {
EditChecklist.editChecklist(client, interaction);
} else if (interactionSplit[1] == 'restartChecklist') {
EditChecklist.restartChecklist(client, interaction);
} else if (interactionSplit[1].startsWith('cancelChecklist')) {
EditChecklist.cancelChecklist(client, interaction, interactionSplit[1].replace('cancelChecklist', ''));
}
} //End of verified user
} //End of ChecklistBot~
}); //End of interactionCreate()
//Modal Interactions
client.on('interactionCreate', async interaction => {
if (!interaction.isModalSubmit()) return;
if (!interaction.guildId) {
return;
}
var interactionID = interaction.customId;
if (!interactionID.startsWith('ChecklistBot~modal~')) {
return;
}
interactionID = interactionID.replace('ChecklistBot~modal~', '');
if (interactionID == 'new') {
NewChecklist.createCustomChecklist(client, interaction, 'new');
} else if (interactionID == 'edit') {
NewChecklist.createCustomChecklist(client, interaction, 'edit');
} else if (interactionID == 'premade') {
NewChecklist.createCustomChecklist(client, interaction, 'premade');
} else if (interactionID == 'verifyDelete') {
EditChecklist.cancelChecklist(client, interaction, interactionID);
}
});
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.login(config.token);