xernerx 2.4.5 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +3 -0
- package/models/Client.js +30 -64
- package/models/commands/ContextMenuCommand.js +5 -3
- package/models/commands/Inhibitor.js +31 -0
- package/models/commands/MessageCommand.js +6 -1
- package/models/events/interactionCreate.js +14 -5
- package/models/events/messageCreate.js +49 -19
- package/models/events/messageUpdate.js +50 -22
- package/models/events/readyOnce.js +19 -4
- package/models/handlers/CommandHandler.js +2 -9
- package/models/handlers/EventHandler.js +5 -3
- package/models/handlers/Handler.js +111 -0
- package/models/handlers/InhibitorHandler.js +16 -0
- package/models/{data → utils}/Arguments.js +34 -22
- package/models/{data → utils}/CommandValidation.js +7 -11
- package/models/utils/CommandsUtil.js +70 -0
- package/models/utils/Functions.js +259 -0
- package/models/utils/InhibitorsUtil.js +24 -0
- package/models/utils/InhibitorsValidation.js +40 -0
- package/models/utils/Util.js +96 -0
- package/package.json +4 -4
- package/models/data/Functions.js +0 -44
- package/models/data/Util.js +0 -320
- package/models/handlers/Loader.js +0 -205
package/models/data/Functions.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const colors = require('./colors.json');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {object} Functions - Build in functions of the bot hidden away in the handlers/setters.
|
|
5
|
-
*/
|
|
6
|
-
class Functions {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {object} client - Client object.
|
|
10
|
-
* @param {object} options - Client options.
|
|
11
|
-
* @returns an object of default colors and custom colors to be imported anywhere without having to import them.
|
|
12
|
-
*/
|
|
13
|
-
color({ client: client, options: options }) {
|
|
14
|
-
client.color = { FLAGS: colors }
|
|
15
|
-
|
|
16
|
-
if (options.color) {
|
|
17
|
-
for (const [name, color] of Object.entries(options.color)) {
|
|
18
|
-
client.color[name] = color;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return client.color;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param {object} client - Client object.
|
|
28
|
-
* @param {object} options - Client options.
|
|
29
|
-
* @returns custom config settings for the bot.
|
|
30
|
-
*/
|
|
31
|
-
config({ client: client, options: options }) {
|
|
32
|
-
client.config = {}
|
|
33
|
-
|
|
34
|
-
if (options.config) {
|
|
35
|
-
for (const [key, value] of Object.entries(options.config)) {
|
|
36
|
-
client.config[key] = value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return client.config;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = new Functions();
|
package/models/data/Util.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, Embed, ButtonBuilder, ButtonStyle } = require('discord.js');
|
|
2
|
-
const opts = require('./options.json');
|
|
3
|
-
|
|
4
|
-
function reply(interaction, text) {
|
|
5
|
-
return (interaction.replied || interaction.deferred) ? interaction.editReply(text) : interaction.reply(text);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function selectMenuPaginator(interaction, embeds, options = {}) {
|
|
9
|
-
if (!embeds) return interaction.client.emit('error', interaction, "no embeds");
|
|
10
|
-
|
|
11
|
-
if (!Array.isArray(embeds)) return interaction.client.emit('error', interaction, "no array of embeds")
|
|
12
|
-
|
|
13
|
-
if (!options.index) {
|
|
14
|
-
options.index = new EmbedBuilder()
|
|
15
|
-
.setTitle(`${embeds.length} pages`)
|
|
16
|
-
|
|
17
|
-
embeds.map((embed, i = 0) => options.index.addFields([{ name: embed?.data?.title || embed?.data?.author?.name || "No name", value: embed?.data?.description || `Page ${i + 1}` }]))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!options.row) {
|
|
21
|
-
options.row = new ActionRowBuilder();
|
|
22
|
-
|
|
23
|
-
if (!options.id) options.id = `${interaction.id}-menu`;
|
|
24
|
-
|
|
25
|
-
options.comp = new SelectMenuBuilder()
|
|
26
|
-
.setCustomId(options.id)
|
|
27
|
-
.setMaxValues(1)
|
|
28
|
-
.setMinValues(1)
|
|
29
|
-
.setPlaceholder('Select a page.')
|
|
30
|
-
.addOptions({ label: 'Index', description: 'Index Page', value: 'index' })
|
|
31
|
-
|
|
32
|
-
embeds.map((embed, i = 0) => options.comp.addOptions({ label: embed?.data?.title || embed?.data?.author?.name, description: embed?.data?.description?.slice(0, 100) || `Page ${i + 1}`, value: opts[embeds.indexOf(embed)] }))
|
|
33
|
-
|
|
34
|
-
options.row.addComponents(options.comp);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!options.id) options.id = options.row.components[0].data.custom_id;
|
|
38
|
-
|
|
39
|
-
(async () => {
|
|
40
|
-
let embed = options.index;
|
|
41
|
-
|
|
42
|
-
let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] })
|
|
43
|
-
|
|
44
|
-
interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
|
|
45
|
-
|
|
46
|
-
.on('collect', async (a) => {
|
|
47
|
-
if (a.customId != options.id) return;
|
|
48
|
-
|
|
49
|
-
let chosen = a.values[0];
|
|
50
|
-
|
|
51
|
-
if (chosen === options.row.components[0]?.options[0]?.data?.value) embed = options.index;
|
|
52
|
-
|
|
53
|
-
else embed = embeds[opts.indexOf(chosen)];
|
|
54
|
-
|
|
55
|
-
a.update({ embeds: [embed] });
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
.on('end', async () => {
|
|
59
|
-
if (interaction.editReply) interaction.editReply({ components: [] });
|
|
60
|
-
|
|
61
|
-
if (interaction.edit) await m.edit({ components: [] });
|
|
62
|
-
})
|
|
63
|
-
})();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function commandName(interaction, cmd) {
|
|
67
|
-
if (cmd) {
|
|
68
|
-
cmds = [];
|
|
69
|
-
|
|
70
|
-
for (const commands of Object.values(interaction.client.commands)) {
|
|
71
|
-
let commandInfo = {};
|
|
72
|
-
|
|
73
|
-
if (commands.has(cmd)) {
|
|
74
|
-
const command = commands.get(cmd);
|
|
75
|
-
|
|
76
|
-
if (command?.data?.options?.length > 0) {
|
|
77
|
-
command?.data?.options?.map(option => {
|
|
78
|
-
if (!option?.type) {
|
|
79
|
-
if (option?.options?.length > 0) {
|
|
80
|
-
option?.options?.map(opt => {
|
|
81
|
-
if (!opt.type) {
|
|
82
|
-
commandInfo = {
|
|
83
|
-
name: command?.data?.name + " " + option?.name + " " + opt?.name,
|
|
84
|
-
description: opt.description,
|
|
85
|
-
category: command.category
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
else {
|
|
90
|
-
commandInfo = {
|
|
91
|
-
name: command?.data?.name + " " + option?.name,
|
|
92
|
-
description: option?.description,
|
|
93
|
-
category: command.category
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
else {
|
|
100
|
-
commandInfo = {
|
|
101
|
-
name: command?.data?.name + " " + option?.name,
|
|
102
|
-
description: option?.description,
|
|
103
|
-
category: command.category
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
else {
|
|
109
|
-
commandInfo = {
|
|
110
|
-
name: command?.data?.name || command?.id,
|
|
111
|
-
description: command?.data?.description || command?.description,
|
|
112
|
-
category: command.category
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
else {
|
|
119
|
-
commandInfo = {
|
|
120
|
-
name: command?.data?.name || command?.id,
|
|
121
|
-
description: command?.data?.description || command?.description,
|
|
122
|
-
category: command.category
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
cmds.push(commandInfo);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
return cmds;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!cmd) return [interaction?.commandName || interaction.content?.replace(interaction.client.settings.prefix.find(p => interaction.content.startsWith(p)), "").split(/ +/)[0], interaction?.options?._group, interaction?.options?._subcommand].join(' ').replace(/ +/g, " ").trim();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function buttonPaginator(interaction, embeds, options = {}) {
|
|
137
|
-
if (!options.buttons) options.buttons = ["⏪", "◀️", "⏹️", "▶️", "⏩"];
|
|
138
|
-
|
|
139
|
-
if (options.buttons.length <= 4 || options.buttons.length > 5) throw new Error('Must specify 5 emotes.');
|
|
140
|
-
|
|
141
|
-
options.row = new ActionRowBuilder();
|
|
142
|
-
|
|
143
|
-
for (const button of options.buttons) {
|
|
144
|
-
options.row
|
|
145
|
-
.addComponents(
|
|
146
|
-
new ButtonBuilder()
|
|
147
|
-
.setCustomId(`${interaction.id}-${opts[options.buttons.indexOf(button)]}`)
|
|
148
|
-
.setStyle(ButtonStyle[options.style || 'Primary'])
|
|
149
|
-
.setEmoji(button)
|
|
150
|
-
)
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
(async () => {
|
|
154
|
-
let embed = embeds[options.index || 0];
|
|
155
|
-
|
|
156
|
-
let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] });
|
|
157
|
-
|
|
158
|
-
interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
|
|
159
|
-
|
|
160
|
-
.on('collect', async (a) => {
|
|
161
|
-
if (a.customId == `${interaction.id}-one`) {
|
|
162
|
-
embed = embeds[0];
|
|
163
|
-
a.update({ embeds: [embed] });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (a.customId == `${interaction.id}-two`) {
|
|
167
|
-
embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
|
|
168
|
-
a.update({ embeds: [embed] });
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (a.customId == `${interaction.id}-three`) {
|
|
172
|
-
a.update({ components: [] });
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (a.customId == `${interaction.id}-four`) {
|
|
176
|
-
embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
|
|
177
|
-
a.update({ embeds: [embed] });
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (a.customId == `${interaction.id}-five`) {
|
|
181
|
-
embed = embeds[embeds.length - 1];
|
|
182
|
-
a.update({ embeds: [embed] });
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
.on('end', async () => {
|
|
187
|
-
if (interaction.editReply) interaction.editReply({ components: [] });
|
|
188
|
-
|
|
189
|
-
if (interaction.edit) await m.edit({ components: [] });
|
|
190
|
-
})
|
|
191
|
-
})();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function uptime(interaction, timestamp) {
|
|
195
|
-
if (!timestamp) timestamp = interaction.client.uptime;
|
|
196
|
-
let totalSeconds = timestamp / 1000;
|
|
197
|
-
let years = Math.floor(totalSeconds / 31536000);
|
|
198
|
-
totalSeconds %= 31536000;
|
|
199
|
-
let days = Math.floor(totalSeconds / 86400);
|
|
200
|
-
totalSeconds %= 86400;
|
|
201
|
-
let hours = Math.floor(totalSeconds / 3600);
|
|
202
|
-
totalSeconds %= 3600;
|
|
203
|
-
let minutes = Math.floor(totalSeconds / 60);
|
|
204
|
-
let seconds = Math.floor(totalSeconds % 60);
|
|
205
|
-
|
|
206
|
-
if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`
|
|
207
|
-
else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
|
|
208
|
-
else if (hours >= 1) return `${hours}h ${minutes}m`;
|
|
209
|
-
else if (minutes >= 1) return `${minutes}m ${seconds}s`;
|
|
210
|
-
else return `${seconds}s`;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
class Util {
|
|
214
|
-
async messageUtil(message, type) {
|
|
215
|
-
setTimeout(() => {
|
|
216
|
-
if (message.client.messages[message.id] === null || message.client.messages[message.id]) delete message.client.messages[message.id];
|
|
217
|
-
|
|
218
|
-
if (message.channel.messages.cache.has(message.id)) message.channel.messages.cache.delete(message.id);
|
|
219
|
-
}, message.client.settings.cacheTime);
|
|
220
|
-
|
|
221
|
-
message.util = {};
|
|
222
|
-
|
|
223
|
-
message.util.selectMenuPaginator = (embeds, options) => selectMenuPaginator(message, embeds, options);
|
|
224
|
-
|
|
225
|
-
message.util.buttonPaginator = (embeds, options) => buttonPaginator(message, embeds, options);
|
|
226
|
-
|
|
227
|
-
message.util.commandName = (command) => commandName(message, command);
|
|
228
|
-
|
|
229
|
-
message.util.uptime = (timestamp) => uptime(message, timestamp);
|
|
230
|
-
|
|
231
|
-
if (type == "create") {
|
|
232
|
-
message.client.messages[message.id] = null;
|
|
233
|
-
|
|
234
|
-
message.util.send = async (e) => {
|
|
235
|
-
const msg = await message.channel.send(e);
|
|
236
|
-
|
|
237
|
-
message.client.messages[message.id] = msg.id;
|
|
238
|
-
|
|
239
|
-
return msg;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
message.util.reply = async (e) => {
|
|
243
|
-
const msg = await message.reply(e);
|
|
244
|
-
|
|
245
|
-
message.client.messages[message.id] = msg.id;
|
|
246
|
-
|
|
247
|
-
return msg;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (type == 'edit') {
|
|
254
|
-
if (message.client.messages[message.id] === null) {
|
|
255
|
-
message.util.send = async (e) => {
|
|
256
|
-
const msg = await message.channel.send(e);
|
|
257
|
-
|
|
258
|
-
message.client.messages[message.id] = msg.id;
|
|
259
|
-
|
|
260
|
-
return msg;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
message.util.reply = async (e) => {
|
|
264
|
-
const msg = await message.reply(e);
|
|
265
|
-
|
|
266
|
-
message.client.messages[message.id] = msg.id;
|
|
267
|
-
|
|
268
|
-
return msg;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
else if (message.client.messages[message.id] !== null) {
|
|
275
|
-
const msg = await message.channel.messages.fetch(message.client.messages[message.id]);
|
|
276
|
-
|
|
277
|
-
message.util.send = async (e) => {
|
|
278
|
-
try {
|
|
279
|
-
return await msg.edit(e);
|
|
280
|
-
}
|
|
281
|
-
catch {
|
|
282
|
-
message.channel.send(e);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
message.util.reply = async (e) => {
|
|
287
|
-
try {
|
|
288
|
-
return await msg.edit(e);
|
|
289
|
-
}
|
|
290
|
-
catch {
|
|
291
|
-
message.reply(e);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
interactionUtil(interaction) {
|
|
301
|
-
interaction.util = {}
|
|
302
|
-
|
|
303
|
-
interaction.util.reply = (text) => reply(interaction, text);
|
|
304
|
-
|
|
305
|
-
interaction.util.selectMenuPaginator = (embeds, options) => selectMenuPaginator(interaction, embeds, options);
|
|
306
|
-
|
|
307
|
-
interaction.util.buttonPaginator = (embeds, options) => buttonPaginator(interaction, embeds, options);
|
|
308
|
-
|
|
309
|
-
interaction.util.commandName = (command) => commandName(interaction, command);
|
|
310
|
-
|
|
311
|
-
interaction.util.uptime = (timestamp) => uptime(interaction, timestamp);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
u = new Util;
|
|
316
|
-
|
|
317
|
-
module.exports = {
|
|
318
|
-
messageUtil: u.messageUtil,
|
|
319
|
-
interactionUtil: u.interactionUtil
|
|
320
|
-
};
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const Discord = require('discord.js');
|
|
3
|
-
const { REST } = require('@discordjs/rest');
|
|
4
|
-
const { Routes, GatewayVersion } = require('discord-api-types/v10');
|
|
5
|
-
const { logStyle } = require('dumfunctions');
|
|
6
|
-
|
|
7
|
-
class Loader {
|
|
8
|
-
constructor(client) {
|
|
9
|
-
this.client = client;
|
|
10
|
-
|
|
11
|
-
this.commands = [];
|
|
12
|
-
|
|
13
|
-
client.commands = {
|
|
14
|
-
message: new Discord.Collection(),
|
|
15
|
-
|
|
16
|
-
interaction: new Discord.Collection(),
|
|
17
|
-
|
|
18
|
-
contextMenu: new Discord.Collection()
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
loadAllInteractionCommands(path, logging = false) {
|
|
23
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'))
|
|
24
|
-
|
|
25
|
-
for (const file of commandFiles) {
|
|
26
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
27
|
-
|
|
28
|
-
let command = require(filepath);
|
|
29
|
-
|
|
30
|
-
command = new command;
|
|
31
|
-
|
|
32
|
-
command.filepath = filepath;
|
|
33
|
-
|
|
34
|
-
this.commands.push(command.data.toJSON());
|
|
35
|
-
|
|
36
|
-
this.client.commands.interaction.set(command.data.name, command);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.#deployCommands("interaction commands", logging);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
reloadAllInteractionCommands() {
|
|
43
|
-
let commands = this.client.commands.interaction.map(command => command.filepath);
|
|
44
|
-
|
|
45
|
-
this.commands = [];
|
|
46
|
-
|
|
47
|
-
this.client.commands.interaction.sweep(() => true);
|
|
48
|
-
|
|
49
|
-
commands.map(path => {
|
|
50
|
-
delete require.cache[require.resolve(path)];
|
|
51
|
-
|
|
52
|
-
let command = require(path);
|
|
53
|
-
|
|
54
|
-
command = new command;
|
|
55
|
-
|
|
56
|
-
command.filepath = path;
|
|
57
|
-
|
|
58
|
-
this.commands.push(command.data.toJSON());
|
|
59
|
-
|
|
60
|
-
this.client.commands.interaction.set(command.data.name, command);
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
return this.#redeployCommands()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
loadAllContextMenuCommands(path, logging = false) {
|
|
67
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
|
|
68
|
-
|
|
69
|
-
for (const file of commandFiles) {
|
|
70
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
71
|
-
|
|
72
|
-
let command = require(filepath);
|
|
73
|
-
|
|
74
|
-
command = new command;
|
|
75
|
-
|
|
76
|
-
command.filepath = filepath;
|
|
77
|
-
|
|
78
|
-
this.commands.push(command.data.toJSON());
|
|
79
|
-
|
|
80
|
-
this.client.commands.contextMenu.set(command.data.name, command);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this.#deployCommands("context menu commands", logging);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
reloadAllContextMenuCommands() {
|
|
87
|
-
let commands = this.client.commands.contextMenu.map(command => command.filepath);
|
|
88
|
-
|
|
89
|
-
this.commands = [];
|
|
90
|
-
|
|
91
|
-
this.client.commands.contextMenu.sweep(() => true);
|
|
92
|
-
|
|
93
|
-
commands.map(path => {
|
|
94
|
-
delete require.cache[require.resolve(path)];
|
|
95
|
-
|
|
96
|
-
let command = require(path);
|
|
97
|
-
|
|
98
|
-
command = new command;
|
|
99
|
-
|
|
100
|
-
command.filepath = path;
|
|
101
|
-
|
|
102
|
-
this.commands.push(command.data.toJSON());
|
|
103
|
-
|
|
104
|
-
this.client.commands.contextMenu.set(command.data.name, command);
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
return this.#redeployCommands()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
loadAllMessageCommands(path, logging = false) {
|
|
111
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
|
|
112
|
-
|
|
113
|
-
for (const file of commandFiles) {
|
|
114
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
115
|
-
|
|
116
|
-
let command = require(filepath);
|
|
117
|
-
|
|
118
|
-
command = new command;
|
|
119
|
-
|
|
120
|
-
command.filepath = filepath;
|
|
121
|
-
|
|
122
|
-
command.aliases.forEach((alias) => {
|
|
123
|
-
if (this.client.commands.message.has(alias)) throw new Error('Cannot have duplicated aliases.');
|
|
124
|
-
|
|
125
|
-
this.client.commands.message.set(alias, command);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
reloadAllMessageCommands() {
|
|
131
|
-
let commands = this.client.commands.message.map(command => command.filepath);
|
|
132
|
-
|
|
133
|
-
this.commands = [];
|
|
134
|
-
|
|
135
|
-
this.client.commands.message.sweep(() => true);
|
|
136
|
-
|
|
137
|
-
commands.map(path => {
|
|
138
|
-
delete require.cache[require.resolve(path)];
|
|
139
|
-
|
|
140
|
-
let command = require(path);
|
|
141
|
-
|
|
142
|
-
command = new command;
|
|
143
|
-
|
|
144
|
-
command.filepath = path;
|
|
145
|
-
|
|
146
|
-
this.client.commands.message.set(command.id, command);
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
return this.#redeployCommands()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
#deployCommands(type, logging = false) {
|
|
153
|
-
this.client.once('ready', client => {
|
|
154
|
-
const rest = new REST({ version: GatewayVersion }).setToken(client.token);
|
|
155
|
-
|
|
156
|
-
(async () => {
|
|
157
|
-
if (type === "interaction commands" && client.settings.logging) console.log(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} servers.`, "text", "cyan"));
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
if (client.settings.global == true) {
|
|
161
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} in ${(await client.guilds.fetch()).size} server(s) globally.`, 'text', 'purple'));
|
|
162
|
-
rest.put(Routes.applicationCommands(client.user.id), {
|
|
163
|
-
body: this.commands
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} locally.`, 'text', 'purple'));
|
|
168
|
-
rest.put(Routes.applicationGuildCommands(client.user.id, client.settings.guildId), {
|
|
169
|
-
body: this.commands
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
throw new Error(e)
|
|
175
|
-
}
|
|
176
|
-
})();
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
#redeployCommands() {
|
|
181
|
-
const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
|
|
182
|
-
|
|
183
|
-
(async () => {
|
|
184
|
-
try {
|
|
185
|
-
if (this.client.settings.global == true) {
|
|
186
|
-
rest.put(Routes.applicationCommands(this.client.user.id), {
|
|
187
|
-
body: this.commands
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
rest.put(Routes.applicationGuildCommands(this.client.user.id, this.client.settings.guildId), {
|
|
192
|
-
body: this.commands
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
throw new Error(e)
|
|
198
|
-
}
|
|
199
|
-
})();
|
|
200
|
-
|
|
201
|
-
return this.commands;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
module.exports = Loader;
|