xernerx 2.4.4 → 2.6.0
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 -321
- package/models/handlers/Loader.js +0 -205
package/main.js
CHANGED
|
@@ -4,6 +4,7 @@ const { Client } = require('./models/Client.js'),
|
|
|
4
4
|
{ MessageCommand } = require('./models/commands/MessageCommand.js'),
|
|
5
5
|
{ InteractionCommand } = require('./models/commands/InteractionCommand.js'),
|
|
6
6
|
{ Event } = require('./models/commands/Event.js'),
|
|
7
|
+
{ Inhibitor } = require('./models/commands/Inhibitor.js'),
|
|
7
8
|
{ LanguageHandler } = require('./models/handlers/LanguageHandler.js'),
|
|
8
9
|
{ ContextMenuCommand } = require('./models/commands/ContextMenuCommand.js'),
|
|
9
10
|
pkg = require('./package.json'),
|
|
@@ -28,6 +29,8 @@ module.exports = {
|
|
|
28
29
|
// Events
|
|
29
30
|
Event,
|
|
30
31
|
|
|
32
|
+
Inhibitor,
|
|
33
|
+
|
|
31
34
|
// Discord
|
|
32
35
|
Discord,
|
|
33
36
|
i18next,
|
package/models/Client.js
CHANGED
|
@@ -1,89 +1,55 @@
|
|
|
1
1
|
const Discord = require('discord.js');
|
|
2
2
|
const { s } = require('@sapphire/shapeshift');
|
|
3
|
-
const { color
|
|
3
|
+
const { color } = require('./utils/Functions.js');
|
|
4
4
|
const { CommandHandler } = require('./handlers/CommandHandler.js');
|
|
5
5
|
const { EventHandler } = require('./handlers/EventHandler.js');
|
|
6
6
|
const { LanguageHandler } = require('./handlers/LanguageHandler.js');
|
|
7
|
-
const
|
|
7
|
+
const InhibitorHandler = require('./handlers/InhibitorHandler.js');
|
|
8
|
+
const Handler = require('./handlers/Handler.js');
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
-
* @param {string} guildId - Test guild ID.
|
|
11
|
-
* @param {boolean} global - Whether the bot should be globally or locally loaded.
|
|
12
|
-
* @param {string[]} prefix - An array of prefix'.
|
|
13
|
-
* @param {string[]} ownerId - An array of bot owners.
|
|
14
|
-
* @param {boolean} ignoreOwner - Whether the bot should ignore owner privileges.
|
|
15
|
-
* @param {number} defaultCooldown - A cooldown between each command in milliseconds.
|
|
16
|
-
* @returns Discord client ready to login.
|
|
17
|
-
*/
|
|
18
10
|
class Client extends Discord.Client {
|
|
19
|
-
constructor(options = {}) {
|
|
11
|
+
constructor(options = {}, settings = {}, i18next = {}, config = {}) {
|
|
20
12
|
super(options)
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
// Required
|
|
24
|
-
guildId: s.string,
|
|
25
|
-
global: s.boolean,
|
|
14
|
+
this.client = new Discord.Client({ intents: options.intents });
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}).optional,
|
|
40
|
-
}).parse(options)
|
|
16
|
+
this.client.settings = s.object({
|
|
17
|
+
guildId: s.string.default(undefined),
|
|
18
|
+
global: s.boolean.default(false),
|
|
19
|
+
prefix: s.array(s.string).default([]),
|
|
20
|
+
ownerId: s.array(s.string).default([]),
|
|
21
|
+
ignoreOwner: s.boolean.default(false),
|
|
22
|
+
defaultCooldown: s.number.default(0),
|
|
23
|
+
cacheTime: s.number.default(300000),
|
|
24
|
+
userPermissions: s.array(s.string).default([]),
|
|
25
|
+
clientPermissions: s.array(s.string).default([]),
|
|
26
|
+
logging: s.union(s.boolean, s.array(s.string)).default(false),
|
|
27
|
+
}).parse(settings);
|
|
41
28
|
|
|
42
|
-
this.client =
|
|
29
|
+
this.client.language = i18next;
|
|
43
30
|
|
|
44
|
-
this.client.
|
|
45
|
-
prefix: options.prefix || [],
|
|
31
|
+
this.client.color = color({ client: this.client, options: settings });
|
|
46
32
|
|
|
47
|
-
|
|
33
|
+
this.client.config = config;
|
|
48
34
|
|
|
49
|
-
|
|
35
|
+
this.client.data = {
|
|
36
|
+
messages: {},
|
|
50
37
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ignoreOwner: options.ignoreOwner || false,
|
|
54
|
-
|
|
55
|
-
defaultCooldown: options.defaultCooldown || 0,
|
|
56
|
-
|
|
57
|
-
logging: options.logging || undefined,
|
|
58
|
-
|
|
59
|
-
cacheTime: options.cacheTime || 300000,
|
|
60
|
-
|
|
61
|
-
userPermissions: options.userPermissions || [],
|
|
62
|
-
|
|
63
|
-
clientPermissions: options.clientPermissions || [],
|
|
64
|
-
|
|
65
|
-
defer: {
|
|
66
|
-
reply: options?.defer?.reply === undefined ? null : options?.defer?.reply,
|
|
67
|
-
ephemeral: options?.defer?.ephemeral === undefined ? null : options?.defer?.ephemeral
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this.client.language = options.language;
|
|
72
|
-
|
|
73
|
-
this.client.color = color({ client: this.client, options: options });
|
|
74
|
-
|
|
75
|
-
this.client.config = config({ client: this.client, options: options });
|
|
76
|
-
|
|
77
|
-
this.client.messages = {};
|
|
38
|
+
cooldowns: {}
|
|
39
|
+
};
|
|
78
40
|
|
|
79
41
|
this.client.modules = {
|
|
80
42
|
commandHandler: new CommandHandler({ client: this.client }),
|
|
81
43
|
|
|
82
44
|
eventHandler: new EventHandler({ client: this.client }),
|
|
83
45
|
|
|
84
|
-
|
|
46
|
+
inhibitorHandler: new InhibitorHandler(this.client),
|
|
47
|
+
|
|
48
|
+
languageHandler: new LanguageHandler(this.client)
|
|
49
|
+
}
|
|
85
50
|
|
|
86
|
-
|
|
51
|
+
this.client.util = {
|
|
52
|
+
handler: new Handler(this.client)
|
|
87
53
|
}
|
|
88
54
|
|
|
89
55
|
return this.client;
|
|
@@ -57,9 +57,11 @@ class ContextMenuCommand {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
types(str) {
|
|
60
|
-
if (String(str)?.toLowerCase() == "message") str = 3
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if (String(str)?.toLowerCase() == "message") str = 3;
|
|
61
|
+
|
|
62
|
+
if (String(str)?.toLowerCase() == "user") str = 2;
|
|
63
|
+
|
|
64
|
+
return str;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { s } = require('@sapphire/shapeshift')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {String} id - The id of the event. @required
|
|
5
|
+
* @param {object} options - of the event. @required
|
|
6
|
+
* @param {string} name - The name of the event. @required
|
|
7
|
+
* @param {boolean} once - Whether the event should be ran once or continuously.
|
|
8
|
+
*/
|
|
9
|
+
class Inhibitor {
|
|
10
|
+
constructor(id, options = {}) {
|
|
11
|
+
s.object({
|
|
12
|
+
name: s.string,
|
|
13
|
+
type: s.string
|
|
14
|
+
}).parse(options)
|
|
15
|
+
|
|
16
|
+
this.id = id;
|
|
17
|
+
|
|
18
|
+
this.name = options.name;
|
|
19
|
+
|
|
20
|
+
this.type = options.type || undefined;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
check(event) {
|
|
25
|
+
/*
|
|
26
|
+
* Make your custom event here.
|
|
27
|
+
*/
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { Inhibitor };
|
|
@@ -17,6 +17,7 @@ class MessageCommand {
|
|
|
17
17
|
name: s.string,
|
|
18
18
|
aliases: s.array(s.string).optional,
|
|
19
19
|
description: s.string,
|
|
20
|
+
prefix: s.array(s.string).optional,
|
|
20
21
|
info: s.string.optional,
|
|
21
22
|
owner: s.boolean.optional,
|
|
22
23
|
admin: s.boolean.optional,
|
|
@@ -34,9 +35,13 @@ class MessageCommand {
|
|
|
34
35
|
|
|
35
36
|
this.id = id;
|
|
36
37
|
|
|
38
|
+
this.name = options.name;
|
|
39
|
+
|
|
37
40
|
this.aliases = [options.name, ...(options.aliases ? options.aliases : [])];
|
|
38
41
|
|
|
39
|
-
this.
|
|
42
|
+
this.regex = options.regex instanceof RegExp ? String(options.regex) : undefined;
|
|
43
|
+
|
|
44
|
+
this.prefix = options.prefix || [];
|
|
40
45
|
|
|
41
46
|
this.description = options.description || undefined;
|
|
42
47
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const { Event } = require('../commands/Event.js');
|
|
2
|
-
const { interactionArgs } = require('./../
|
|
2
|
+
const { interactionArgs } = require('./../utils/Arguments.js');
|
|
3
3
|
const { InteractionType } = require('discord.js')
|
|
4
|
-
const commandValidation = require('./../
|
|
5
|
-
const { interactionUtil } = require('./../
|
|
4
|
+
const { commandValidation } = require('./../utils/CommandValidation.js');
|
|
5
|
+
const { interactionUtil } = require('./../utils/Util.js');
|
|
6
|
+
const { inhibitorsValidation } = require('../utils/InhibitorsValidation.js');
|
|
6
7
|
/**
|
|
7
8
|
* @returns interaction command executor.
|
|
8
9
|
*/
|
|
@@ -16,12 +17,14 @@ class BuildInInteractionEvent extends Event {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async run(interaction) {
|
|
19
|
-
await interactionUtil(interaction)
|
|
20
|
+
await interactionUtil(interaction);
|
|
20
21
|
|
|
21
22
|
if (interaction.type == InteractionType.ApplicationCommand) {
|
|
22
23
|
if (interaction.client.commands.interaction.has(interaction.commandName)) {
|
|
23
24
|
let command = interaction.client.commands.interaction.get(interaction.commandName);
|
|
24
25
|
|
|
26
|
+
if (inhibitorsValidation(interaction, command)) return;
|
|
27
|
+
|
|
25
28
|
await this.defer(interaction, command);
|
|
26
29
|
|
|
27
30
|
command.client = interaction.client;
|
|
@@ -35,7 +38,9 @@ class BuildInInteractionEvent extends Event {
|
|
|
35
38
|
if (commandValidation(interaction, command)) return;
|
|
36
39
|
|
|
37
40
|
try {
|
|
38
|
-
|
|
41
|
+
if (command.conditions) return command.conditions(interaction, { group, subcommand, args });
|
|
42
|
+
|
|
43
|
+
await command.exec(interaction, { group, subcommand, args });
|
|
39
44
|
|
|
40
45
|
return interaction.client.emit('commandRun', interaction, "interaction", command)
|
|
41
46
|
}
|
|
@@ -47,11 +52,15 @@ class BuildInInteractionEvent extends Event {
|
|
|
47
52
|
if (interaction.client.commands.contextMenu.has(interaction.commandName)) {
|
|
48
53
|
let command = interaction.client.commands.contextMenu.get(interaction.commandName);
|
|
49
54
|
|
|
55
|
+
if (inhibitorsValidation(interaction)) return;
|
|
56
|
+
|
|
50
57
|
await this.defer(interaction, command);
|
|
51
58
|
|
|
52
59
|
command.client = interaction.client;
|
|
53
60
|
|
|
54
61
|
try {
|
|
62
|
+
if (command.conditions) return command.conditions(interaction);
|
|
63
|
+
|
|
55
64
|
await command.exec(interaction);
|
|
56
65
|
|
|
57
66
|
return interaction.client.emit('commandRun', interaction, 'contextMenu', command);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { Event } = require('../commands/Event.js');
|
|
2
|
-
const { messageArgs } = require("./../
|
|
3
|
-
const commandValidation = require('./../
|
|
4
|
-
const { messageUtil } = require('../
|
|
2
|
+
const { messageArgs } = require("./../utils/Arguments.js");
|
|
3
|
+
const { commandValidation } = require('./../utils/CommandValidation.js');
|
|
4
|
+
const { messageUtil } = require('../utils/Util.js');
|
|
5
|
+
const { inhibitorsValidation } = require('../utils/InhibitorsValidation.js');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @returns message command executor.
|
|
@@ -17,33 +18,62 @@ class BuildInMessageEvent extends Event {
|
|
|
17
18
|
|
|
18
19
|
async run(message) {
|
|
19
20
|
if (!message.author.bot) {
|
|
21
|
+
await messageUtil(message, "create");
|
|
22
|
+
|
|
23
|
+
let commands = message.client.commands.message;
|
|
24
|
+
|
|
25
|
+
commands.filter(c => c.regex).map(async command => {
|
|
26
|
+
let regex = command.regex.split(/\//).slice(1);
|
|
27
|
+
|
|
28
|
+
regex = RegExp(...regex);
|
|
29
|
+
|
|
30
|
+
if (message.content.match(regex)) {
|
|
31
|
+
try {
|
|
32
|
+
if (command.conditions && (await command.conditions(message))) return;
|
|
33
|
+
|
|
34
|
+
return await command.exec(message);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
message.client.emit("error", message, error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
|
|
20
42
|
if (message?.client?.settings?.prefix?.length <= 0) return;
|
|
21
43
|
|
|
22
|
-
|
|
44
|
+
commands.filter(c => !c.regex).map(async command => {
|
|
45
|
+
command.prefix.map(prefix => {
|
|
46
|
+
this.commandCheck(message, prefix, command);
|
|
47
|
+
})
|
|
23
48
|
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
message.client.settings.prefix.map(prefix => {
|
|
50
|
+
this.commandCheck(message, prefix, command);
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
26
55
|
|
|
27
|
-
|
|
56
|
+
async commandCheck(message, prefix, command) {
|
|
57
|
+
for (const alias of command.aliases) {
|
|
58
|
+
if (message.content.split(/ +/)[0] !== prefix + alias) continue;
|
|
28
59
|
|
|
29
|
-
|
|
60
|
+
if (inhibitorsValidation(message, command)) break;
|
|
30
61
|
|
|
31
|
-
|
|
62
|
+
const args = await messageArgs({ message: message, command: command });
|
|
32
63
|
|
|
33
|
-
|
|
64
|
+
if (commandValidation(message, command)) break;
|
|
34
65
|
|
|
35
|
-
|
|
66
|
+
try {
|
|
67
|
+
if (command.conditions && (await command.conditions(message, args))) break;
|
|
36
68
|
|
|
37
|
-
|
|
69
|
+
await command.exec(message, args);
|
|
38
70
|
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
return message.client.emit('commandRun', message, 'message', command);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
message.client.emit("error", message, error);
|
|
41
75
|
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
message.client.emit("error", message, error);
|
|
46
|
-
}
|
|
76
|
+
break;
|
|
47
77
|
}
|
|
48
78
|
}
|
|
49
79
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const { Event } = require('../commands/Event.js');
|
|
2
|
-
const { messageArgs } = require("./../
|
|
3
|
-
const commandValidation = require('./../
|
|
4
|
-
const { messageUtil } = require('../
|
|
2
|
+
const { messageArgs } = require("./../utils/Arguments.js");
|
|
3
|
+
const { commandValidation } = require('./../utils/CommandValidation.js');
|
|
4
|
+
const { messageUtil } = require('../utils/Util.js');
|
|
5
|
+
const { inhibitorsValidation } = require('../utils/InhibitorsValidation.js');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @returns message command executor.
|
|
@@ -16,37 +17,64 @@ class BuildInMessageUpdateEvent extends Event {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async run(oldMessage, newMessage) {
|
|
19
|
-
if (
|
|
20
|
+
if (!oldMessage.author.bot && !newMessage.author.bot) {
|
|
21
|
+
await messageUtil(newMessage, "edit");
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
let commands = newMessage.client.commands.message;
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
commands.filter(c => c.regex).map(async command => {
|
|
26
|
+
let regex = command.regex.split(/\//).slice(1);
|
|
27
|
+
|
|
28
|
+
regex = RegExp(...regex);
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
if (newMessage.content.match(regex)) {
|
|
31
|
+
try {
|
|
32
|
+
if (command.conditions && (await command.conditions(newMessage))) return;
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
return await command.exec(newMessage);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
newMessage.client.emit("error", newMessage, error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
})
|
|
29
41
|
|
|
30
|
-
|
|
42
|
+
if (newMessage?.client?.settings?.prefix?.length <= 0) return;
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
if (!newMessage.client.data.messages[newMessage.id] === undefined) return;
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
commands.filter(c => !c.regex).map(async command => {
|
|
47
|
+
command.prefix.map(prefix => {
|
|
48
|
+
this.commandCheck(newMessage, prefix, command);
|
|
49
|
+
})
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
newMessage.client.settings.prefix.map(prefix => {
|
|
52
|
+
this.commandCheck(newMessage, prefix, command);
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
37
57
|
|
|
38
|
-
|
|
58
|
+
async commandCheck(message, prefix, command) {
|
|
59
|
+
for (const alias of command.aliases) {
|
|
60
|
+
if (message.content.split(/ +/)[0] !== prefix + alias) continue;
|
|
39
61
|
|
|
40
|
-
|
|
62
|
+
if (inhibitorsValidation(message, command)) break;
|
|
41
63
|
|
|
42
|
-
|
|
43
|
-
command.exec(newMessage, args);
|
|
64
|
+
const args = await messageArgs({ message: message, command: command });
|
|
44
65
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
66
|
+
if (commandValidation(message, command)) break;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
if (command.conditions && (await command.conditions(message, args))) break;
|
|
70
|
+
|
|
71
|
+
await command.exec(message, args);
|
|
72
|
+
|
|
73
|
+
return message.client.emit('commandRun', message, 'message', command);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
message.client.emit("error", message, error);
|
|
77
|
+
break;
|
|
50
78
|
}
|
|
51
79
|
}
|
|
52
80
|
}
|
|
@@ -13,9 +13,9 @@ class BuildInReadyOnceEvent extends Event {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async run(client) {
|
|
16
|
-
if (client.logging) console.
|
|
16
|
+
if (client.settings.logging) console.info(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} servers.`, "text", "cyan"));
|
|
17
17
|
|
|
18
|
-
if (client.settings.logging) {
|
|
18
|
+
if (Array.isArray(client.settings.logging)) {
|
|
19
19
|
let loaded = [];
|
|
20
20
|
|
|
21
21
|
for (const [type, commands] of Object.entries(client.commands)) {
|
|
@@ -29,15 +29,30 @@ class BuildInReadyOnceEvent extends Event {
|
|
|
29
29
|
if (!loaded.includes(command)) loaded.push(command);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
|
|
32
33
|
for (const [id, event] of [...client.events]) {
|
|
33
|
-
event.runType = 'event'
|
|
34
|
+
event.runType = 'event';
|
|
35
|
+
|
|
36
|
+
loaded.push(event);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const [id, inhibitor] of [...client.inhibitors]) {
|
|
40
|
+
inhibitor.runType = 'inhibitor';
|
|
34
41
|
|
|
35
|
-
loaded.push(
|
|
42
|
+
loaded.push(inhibitor);
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
console.table(loaded, client.settings.logging);
|
|
39
46
|
}
|
|
47
|
+
else {
|
|
48
|
+
Object.entries(client.commands).map(([type, commands]) => {
|
|
49
|
+
console.info(logStyle(`Loaded ${type} commands: ${commands.map(command => command?.data?.name || command?.name || command?.id).join(', ')}`, "text", "cyan"));
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// add events and inhibitors;
|
|
53
|
+
}
|
|
40
54
|
}
|
|
55
|
+
|
|
41
56
|
};
|
|
42
57
|
|
|
43
58
|
module.exports = BuildInReadyOnceEvent;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
1
|
const Discord = require('discord.js');
|
|
3
|
-
const
|
|
4
|
-
const { Routes, GatewayVersion } = require('discord-api-types/v10');
|
|
5
|
-
const { delay, logStyle } = require('dumfunctions')
|
|
6
|
-
const paths = require("path");
|
|
7
|
-
const Loader = require('./Loader.js');
|
|
2
|
+
const Handler = require('./Handler.js');
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* @param {object} client - The client.
|
|
@@ -15,8 +10,6 @@ class CommandHandler {
|
|
|
15
10
|
|
|
16
11
|
this.client = client;
|
|
17
12
|
|
|
18
|
-
this.commands = [];
|
|
19
|
-
|
|
20
13
|
client.commands = {
|
|
21
14
|
message: new Discord.Collection(),
|
|
22
15
|
|
|
@@ -25,7 +18,7 @@ class CommandHandler {
|
|
|
25
18
|
contextMenu: new Discord.Collection()
|
|
26
19
|
}
|
|
27
20
|
|
|
28
|
-
this.load = new
|
|
21
|
+
this.load = new Handler(client);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
loadAllInteractionCommands(path, logging = false) {
|
|
@@ -56,9 +56,11 @@ class EventHandler {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
emitter(type) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const client = this.client;
|
|
60
|
+
|
|
61
|
+
if (type == 'client') return client;
|
|
62
|
+
if (type == 'rest') return client.rest;
|
|
63
|
+
else return eval(type);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
const { importCommands, reimportCommands } = require('../utils/CommandsUtil.js');
|
|
7
|
+
const { importInhibitors } = require('../utils/InhibitorsUtil.js');
|
|
8
|
+
|
|
9
|
+
module.exports = class Handler {
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
|
|
13
|
+
this.commands = [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
loadAllInteractionCommands(path, logging = false) {
|
|
17
|
+
const files = this.#readdir(path);
|
|
18
|
+
|
|
19
|
+
importCommands(this.client, path, files, this.commands, 'interaction');
|
|
20
|
+
|
|
21
|
+
this.#deployCommands("interaction commands", logging);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
reloadAllInteractionCommands() {
|
|
25
|
+
reimportCommands(this.client, this.commands, "interaction");
|
|
26
|
+
|
|
27
|
+
return this.#redeployCommands()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
loadAllContextMenuCommands(path, logging = false) {
|
|
31
|
+
const files = this.#readdir(path);
|
|
32
|
+
|
|
33
|
+
importCommands(this.client, path, files, this.commands, 'contextMenu');
|
|
34
|
+
|
|
35
|
+
this.#deployCommands("context menu commands", logging);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
reloadAllContextMenuCommands() {
|
|
39
|
+
reimportCommands(this.client, this.commands, "contextMenu");
|
|
40
|
+
|
|
41
|
+
return this.#redeployCommands()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
loadAllMessageCommands(path) {
|
|
45
|
+
const files = this.#readdir(path);
|
|
46
|
+
|
|
47
|
+
importCommands(this.client, path, files, this.commands, 'message');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
reloadAllMessageCommands() {
|
|
51
|
+
return reimportCommands(this.client, this.commands, "message");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
loadAllInhibitors(path) {
|
|
55
|
+
const files = this.#readdir(path);
|
|
56
|
+
|
|
57
|
+
importInhibitors(this.client, path, files);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#deployCommands(type, logging = false) {
|
|
61
|
+
this.client.once('ready', async client => {
|
|
62
|
+
const rest = new REST({ version: GatewayVersion }).setToken(client.token);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
if (client.settings.global == true) {
|
|
66
|
+
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} in ${(await client.guilds.fetch()).size} server(s) globally.`, 'text', 'purple'));
|
|
67
|
+
rest.put(Routes.applicationCommands(client.user.id), {
|
|
68
|
+
body: this.commands
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} locally.`, 'text', 'purple'));
|
|
73
|
+
rest.put(Routes.applicationGuildCommands(client.user.id, client.settings.guildId), {
|
|
74
|
+
body: this.commands
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error(e)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#redeployCommands() {
|
|
85
|
+
const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
|
|
86
|
+
|
|
87
|
+
(async () => {
|
|
88
|
+
try {
|
|
89
|
+
if (this.client.settings.global == true) {
|
|
90
|
+
rest.put(Routes.applicationCommands(this.client.user.id), {
|
|
91
|
+
body: this.commands
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
rest.put(Routes.applicationGuildCommands(this.client.user.id, this.client.settings.guildId), {
|
|
96
|
+
body: this.commands
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw new Error(e)
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
return this.commands;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#readdir(path) {
|
|
109
|
+
return fs.readdirSync(path).filter(file => file.endsWith('.js'));
|
|
110
|
+
}
|
|
111
|
+
}
|