xernerx 2.1.7 → 2.3.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/models/Client.js +19 -5
- package/models/commands/ContextMenuCommand.js +4 -1
- package/models/commands/InteractionCommand.js +10 -1
- package/models/data/Util.js +90 -3
- package/models/events/interactionCreate.js +16 -4
- package/models/events/messageCreate.js +2 -2
- package/models/events/messageUpdate.js +2 -2
- package/models/events/readyOnce.js +23 -0
- package/models/handlers/CommandHandler.js +12 -101
- package/models/handlers/EventHandler.js +5 -7
- package/models/handlers/LanguageHandler.js +5 -21
- package/models/handlers/Loader.js +205 -0
- package/package.json +4 -4
package/models/Client.js
CHANGED
|
@@ -4,6 +4,7 @@ const { color, config } = require('./data/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 Loader = require('./handlers/Loader.js');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {string} guildId - Test guild ID.
|
|
@@ -28,10 +29,14 @@ class Client extends Discord.Client {
|
|
|
28
29
|
ownerId: s.array(s.string).optional,
|
|
29
30
|
ignoreOwner: s.boolean.optional,
|
|
30
31
|
defaultCooldown: s.number.optional,
|
|
31
|
-
logging: s.
|
|
32
|
+
logging: s.array(s.string).optional,
|
|
32
33
|
cacheTime: s.number.optional,
|
|
33
34
|
userPermissions: s.array(s.string).optional,
|
|
34
|
-
clientPermissions: s.array(s.string).optional
|
|
35
|
+
clientPermissions: s.array(s.string).optional,
|
|
36
|
+
defer: s.object({
|
|
37
|
+
reply: s.boolean.optional,
|
|
38
|
+
ephemeral: s.boolean.optional
|
|
39
|
+
}).optional,
|
|
35
40
|
}).parse(options)
|
|
36
41
|
|
|
37
42
|
this.client = new Discord.Client({ intents: [options.intents || 0], partials: [options.partials] });
|
|
@@ -49,13 +54,20 @@ class Client extends Discord.Client {
|
|
|
49
54
|
|
|
50
55
|
defaultCooldown: options.defaultCooldown || 0,
|
|
51
56
|
|
|
52
|
-
logging: options.logging ||
|
|
57
|
+
logging: options.logging || undefined,
|
|
53
58
|
|
|
54
59
|
cacheTime: options.cacheTime || 300000,
|
|
55
60
|
|
|
56
61
|
userPermissions: options.userPermissions || [],
|
|
57
62
|
|
|
58
|
-
clientPermissions: options.clientPermissions || []
|
|
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
|
+
language: options.language
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
this.client.color = color({ client: this.client, options: options });
|
|
@@ -69,7 +81,9 @@ class Client extends Discord.Client {
|
|
|
69
81
|
|
|
70
82
|
eventHandler: new EventHandler({ client: this.client }),
|
|
71
83
|
|
|
72
|
-
|
|
84
|
+
languageHandler: new LanguageHandler(this.client),
|
|
85
|
+
|
|
86
|
+
loader: new Loader(this.client)
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
return this.client;
|
|
@@ -19,7 +19,8 @@ class ContextMenuCommand {
|
|
|
19
19
|
channels: s.array(s.string).optional,
|
|
20
20
|
guilds: s.array(s.string).optional,
|
|
21
21
|
userPermissions: s.array(s.string).optional,
|
|
22
|
-
clientPermissions: s.array(s.string).optional
|
|
22
|
+
clientPermissions: s.array(s.string).optional,
|
|
23
|
+
description: s.string.optional
|
|
23
24
|
}).parse(options)
|
|
24
25
|
|
|
25
26
|
this.data = new Discord.ContextMenuCommandBuilder()
|
|
@@ -45,6 +46,8 @@ class ContextMenuCommand {
|
|
|
45
46
|
this.clientPermissions = options.clientPermissions || [];
|
|
46
47
|
|
|
47
48
|
this.config = options.config;
|
|
49
|
+
|
|
50
|
+
this.description = options.description || undefined;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
exec(interaction) {
|
|
@@ -27,7 +27,11 @@ class InteractionCommand {
|
|
|
27
27
|
channels: s.array(s.string).optional,
|
|
28
28
|
guilds: s.array(s.string).optional,
|
|
29
29
|
userPermissions: s.array(s.string).optional,
|
|
30
|
-
clientPermissions: s.array(s.string).optional
|
|
30
|
+
clientPermissions: s.array(s.string).optional,
|
|
31
|
+
defer: s.object({
|
|
32
|
+
reply: s.boolean.optional,
|
|
33
|
+
ephemeral: s.boolean.optional
|
|
34
|
+
}).optional
|
|
31
35
|
}).parse(options);
|
|
32
36
|
|
|
33
37
|
this.data = new SlashCommandBuilder()
|
|
@@ -75,6 +79,11 @@ class InteractionCommand {
|
|
|
75
79
|
this.userPermissions = options.userPermissions || [];
|
|
76
80
|
|
|
77
81
|
this.clientPermissions = options.clientPermissions || [];
|
|
82
|
+
|
|
83
|
+
this.defer = {
|
|
84
|
+
reply: options?.defer?.reply === undefined ? null : options?.defer?.reply,
|
|
85
|
+
ephemeral: options?.defer?.ephemeral === undefined ? null : options?.defer?.ephemeral
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
exec(interaction) {
|
package/models/data/Util.js
CHANGED
|
@@ -63,12 +63,72 @@ function selectMenuPaginator(interaction, embeds, options = {}) {
|
|
|
63
63
|
})();
|
|
64
64
|
}
|
|
65
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.name = command?.data?.name + " " + option?.name + " " + opt?.name;
|
|
83
|
+
|
|
84
|
+
commandInfo.description = opt.description;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
else {
|
|
88
|
+
commandInfo.name = command?.data?.name + " " + option?.name;
|
|
89
|
+
|
|
90
|
+
commandInfo.description = option?.description;
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
else {
|
|
96
|
+
commandInfo.name = command?.data?.name + " " + option?.name;
|
|
97
|
+
|
|
98
|
+
commandInfo.description = option?.description;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
else {
|
|
103
|
+
commandInfo.name = command?.data?.name || command?.id;
|
|
104
|
+
|
|
105
|
+
commandInfo.description = command?.data?.description || command?.description;
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
else {
|
|
111
|
+
commandInfo.name = command?.data?.name || command?.id;
|
|
112
|
+
|
|
113
|
+
commandInfo.description = command?.data?.description || command?.description;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
cmds.push(commandInfo);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
return cmds;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
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();
|
|
124
|
+
}
|
|
125
|
+
|
|
66
126
|
function buttonPaginator(interaction, embeds, options = {}) {
|
|
67
127
|
if (!options.buttons) options.buttons = ["⏪", "◀️", "⏹️", "▶️", "⏩"];
|
|
68
128
|
|
|
69
|
-
if (options.buttons.length <= 4 || options.buttons.length > 5) throw new Error('Must specify 5 emotes.')
|
|
129
|
+
if (options.buttons.length <= 4 || options.buttons.length > 5) throw new Error('Must specify 5 emotes.');
|
|
70
130
|
|
|
71
|
-
options.row = new ActionRowBuilder()
|
|
131
|
+
options.row = new ActionRowBuilder();
|
|
72
132
|
|
|
73
133
|
for (const button of options.buttons) {
|
|
74
134
|
options.row
|
|
@@ -78,7 +138,7 @@ function buttonPaginator(interaction, embeds, options = {}) {
|
|
|
78
138
|
.setStyle(ButtonStyle[options.style || 'Primary'])
|
|
79
139
|
.setEmoji(button)
|
|
80
140
|
)
|
|
81
|
-
}
|
|
141
|
+
};
|
|
82
142
|
|
|
83
143
|
(async () => {
|
|
84
144
|
let embed = embeds[options.index || 0];
|
|
@@ -121,6 +181,25 @@ function buttonPaginator(interaction, embeds, options = {}) {
|
|
|
121
181
|
})();
|
|
122
182
|
}
|
|
123
183
|
|
|
184
|
+
function uptime(interaction, timestamp) {
|
|
185
|
+
if (!timestamp) timestamp = interaction.client.uptime;
|
|
186
|
+
let totalSeconds = timestamp / 1000;
|
|
187
|
+
let years = Math.floor(totalSeconds / 31536000);
|
|
188
|
+
totalSeconds %= 31536000;
|
|
189
|
+
let days = Math.floor(totalSeconds / 86400);
|
|
190
|
+
totalSeconds %= 86400;
|
|
191
|
+
let hours = Math.floor(totalSeconds / 3600);
|
|
192
|
+
totalSeconds %= 3600;
|
|
193
|
+
let minutes = Math.floor(totalSeconds / 60);
|
|
194
|
+
let seconds = Math.floor(totalSeconds % 60);
|
|
195
|
+
|
|
196
|
+
if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`
|
|
197
|
+
else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
|
|
198
|
+
else if (hours >= 1) return `${hours}h ${minutes}m`;
|
|
199
|
+
else if (minutes >= 1) return `${minutes}m ${seconds}s`;
|
|
200
|
+
else return `${seconds}s`;
|
|
201
|
+
}
|
|
202
|
+
|
|
124
203
|
class Util {
|
|
125
204
|
async messageUtil(message, type) {
|
|
126
205
|
setTimeout(() => {
|
|
@@ -135,6 +214,10 @@ class Util {
|
|
|
135
214
|
|
|
136
215
|
message.util.buttonPaginator = (embeds, options) => buttonPaginator(message, embeds, options);
|
|
137
216
|
|
|
217
|
+
message.util.commandName = (command) => commandName(message, command);
|
|
218
|
+
|
|
219
|
+
message.util.uptime = (timestamp) => uptime(message, timestamp);
|
|
220
|
+
|
|
138
221
|
if (type == "create") {
|
|
139
222
|
message.client.messages[message.id] = null;
|
|
140
223
|
|
|
@@ -212,6 +295,10 @@ class Util {
|
|
|
212
295
|
interaction.util.selectMenuPaginator = (embeds, options) => selectMenuPaginator(interaction, embeds, options);
|
|
213
296
|
|
|
214
297
|
interaction.util.buttonPaginator = (embeds, options) => buttonPaginator(interaction, embeds, options);
|
|
298
|
+
|
|
299
|
+
interaction.util.commandName = (command) => commandName(interaction, command);
|
|
300
|
+
|
|
301
|
+
interaction.util.uptime = (timestamp) => uptime(interaction, timestamp);
|
|
215
302
|
}
|
|
216
303
|
}
|
|
217
304
|
|
|
@@ -19,8 +19,10 @@ class BuildInInteractionEvent extends Event {
|
|
|
19
19
|
await interactionUtil(interaction)
|
|
20
20
|
|
|
21
21
|
if (interaction.type == InteractionType.ApplicationCommand) {
|
|
22
|
-
if (interaction.client.
|
|
23
|
-
let command = interaction.client.
|
|
22
|
+
if (interaction.client.commands.interaction.has(interaction.commandName)) {
|
|
23
|
+
let command = interaction.client.commands.interaction.get(interaction.commandName);
|
|
24
|
+
|
|
25
|
+
await this.defer(interaction, command);
|
|
24
26
|
|
|
25
27
|
command.client = interaction.client;
|
|
26
28
|
|
|
@@ -42,8 +44,10 @@ class BuildInInteractionEvent extends Event {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
if (interaction.client.
|
|
46
|
-
let command = interaction.client.
|
|
47
|
+
if (interaction.client.commands.contextMenu.has(interaction.commandName)) {
|
|
48
|
+
let command = interaction.client.commands.contextMenu.get(interaction.commandName);
|
|
49
|
+
|
|
50
|
+
await this.defer(interaction, command);
|
|
47
51
|
|
|
48
52
|
command.client = interaction.client;
|
|
49
53
|
|
|
@@ -58,6 +62,14 @@ class BuildInInteractionEvent extends Event {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
}
|
|
65
|
+
|
|
66
|
+
async defer(interaction, command) {
|
|
67
|
+
if (command?.defer?.reply) return await interaction.deferReply({ ephemeral: command?.defer?.ephemeral });
|
|
68
|
+
|
|
69
|
+
else if (command?.defer?.reply === false && interaction.client?.settings?.defer?.reply) return;
|
|
70
|
+
|
|
71
|
+
else if (interaction.client?.settings?.defer?.reply) return await interaction.deferReply({ ephemeral: interaction.client?.settings?.defer?.ephemeral || command?.defer?.ephemeral });
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
module.exports = BuildInInteractionEvent;
|
|
@@ -26,9 +26,9 @@ class BuildInMessageEvent extends Event {
|
|
|
26
26
|
|
|
27
27
|
let command = message.content.replace(prefix, "").split(/ +/).shift().toLowerCase();
|
|
28
28
|
|
|
29
|
-
if (!message.client.
|
|
29
|
+
if (!message.client.commands.message.has(command) || command == '') return;
|
|
30
30
|
|
|
31
|
-
command = message.client.
|
|
31
|
+
command = message.client.commands.message.get(command);
|
|
32
32
|
|
|
33
33
|
command.client = message.client;
|
|
34
34
|
|
|
@@ -29,9 +29,9 @@ class BuildInMessageUpdateEvent extends Event {
|
|
|
29
29
|
|
|
30
30
|
let command = newMessage.content.replace(prefix, "").split(/ +/).shift().toLowerCase();
|
|
31
31
|
|
|
32
|
-
if (!newMessage.client.
|
|
32
|
+
if (!newMessage.client.commands.message.has(command) || command === '') return;
|
|
33
33
|
|
|
34
|
-
command = newMessage.client.
|
|
34
|
+
command = newMessage.client.commands.message.get(command);
|
|
35
35
|
|
|
36
36
|
command.client = newMessage.client;
|
|
37
37
|
|
|
@@ -14,6 +14,29 @@ class BuildInReadyOnceEvent extends Event {
|
|
|
14
14
|
|
|
15
15
|
async run(client) {
|
|
16
16
|
if (client.logging) console.log(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} server(s).`, "text", "green"))
|
|
17
|
+
|
|
18
|
+
if (client.settings.logging) {
|
|
19
|
+
let loaded = [];
|
|
20
|
+
|
|
21
|
+
for (const [type, commands] of Object.entries(client.commands)) {
|
|
22
|
+
for (let [id, command] of commands) {
|
|
23
|
+
command.name = command?.data?.name || command?.aliases[0] || command.id;
|
|
24
|
+
|
|
25
|
+
command.description = command?.data?.description || command.description;
|
|
26
|
+
|
|
27
|
+
command.runType = type;
|
|
28
|
+
|
|
29
|
+
if (!loaded.includes(command)) loaded.push(command);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const [id, event] of [...client.events]) {
|
|
33
|
+
event.runType = 'event'
|
|
34
|
+
|
|
35
|
+
loaded.push(event)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.table(loaded, client.settings.logging);
|
|
39
|
+
}
|
|
17
40
|
}
|
|
18
41
|
};
|
|
19
42
|
|
|
@@ -3,7 +3,8 @@ const Discord = require('discord.js');
|
|
|
3
3
|
const { REST } = require('@discordjs/rest');
|
|
4
4
|
const { Routes, GatewayVersion } = require('discord-api-types/v10');
|
|
5
5
|
const { delay, logStyle } = require('dumfunctions')
|
|
6
|
-
const paths = require("path")
|
|
6
|
+
const paths = require("path");
|
|
7
|
+
const Loader = require('./Loader.js');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {object} client - The client.
|
|
@@ -16,117 +17,27 @@ class CommandHandler {
|
|
|
16
17
|
|
|
17
18
|
this.commands = [];
|
|
18
19
|
|
|
19
|
-
client.
|
|
20
|
+
client.commands = {
|
|
21
|
+
message: new Discord.Collection(),
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
interaction: new Discord.Collection(),
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
loadAllInteractionCommands(path, logging = false) {
|
|
27
|
-
let commands = [];
|
|
28
|
-
|
|
29
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'))
|
|
30
|
-
|
|
31
|
-
for (const file of commandFiles) {
|
|
32
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
33
|
-
|
|
34
|
-
let command = require(filepath);
|
|
35
|
-
|
|
36
|
-
command = new command;
|
|
37
|
-
|
|
38
|
-
command.filepath = filepath;
|
|
39
|
-
|
|
40
|
-
this.commands.push(command.data.toJSON());
|
|
41
|
-
|
|
42
|
-
commands.push(command.data.name);
|
|
43
|
-
|
|
44
|
-
this.client.interactionCommands.set(command.data.name, command);
|
|
25
|
+
contextMenu: new Discord.Collection()
|
|
45
26
|
}
|
|
46
27
|
|
|
47
|
-
this
|
|
28
|
+
this.load = new Loader(client);
|
|
29
|
+
}
|
|
48
30
|
|
|
49
|
-
|
|
31
|
+
loadAllInteractionCommands(path, logging = false) {
|
|
32
|
+
this.load.loadAllInteractionCommands(path, logging);
|
|
50
33
|
}
|
|
51
34
|
|
|
52
35
|
loadAllContextMenuCommands(path, logging = false) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
|
|
56
|
-
|
|
57
|
-
for (const file of commandFiles) {
|
|
58
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
59
|
-
|
|
60
|
-
let command = require(filepath);
|
|
61
|
-
|
|
62
|
-
command = new command;
|
|
63
|
-
|
|
64
|
-
command.filepath = filepath;
|
|
65
|
-
|
|
66
|
-
this.commands.push(command.data.toJSON());
|
|
67
|
-
|
|
68
|
-
commands.push(command.data.name);
|
|
69
|
-
|
|
70
|
-
this.client.contextMenuCommands.set(command.data.name, command);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.#deployCommands("context menu commands", logging);
|
|
74
|
-
|
|
75
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loading context menu commands: ${commands.join(', ')}`, 'text', 'yellow'));
|
|
36
|
+
this.load.loadAllContextMenuCommands(path, logging);
|
|
76
37
|
}
|
|
77
38
|
|
|
78
39
|
loadAllMessageCommands(path, logging = false) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
|
|
82
|
-
|
|
83
|
-
for (const file of commandFiles) {
|
|
84
|
-
let filepath = `${require("path").resolve(path)}/${file}`
|
|
85
|
-
|
|
86
|
-
let command = require(filepath);
|
|
87
|
-
|
|
88
|
-
command = new command;
|
|
89
|
-
|
|
90
|
-
command.filepath = filepath;
|
|
91
|
-
|
|
92
|
-
command.aliases.forEach((alias) => {
|
|
93
|
-
if (this.client.messageCommands.has(alias)) throw new Error('Cannot have duplicated aliases.');
|
|
94
|
-
|
|
95
|
-
this.client.messageCommands.set(alias, command);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
commands.push(command.name || command.id);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded message commands: ${commands.join(', ')}`, 'text', 'purple'));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
#deployCommands(type, logging = false) {
|
|
105
|
-
this.client.once('ready', client => {
|
|
106
|
-
const rest = new REST({ version: GatewayVersion }).setToken(client.token);
|
|
107
|
-
|
|
108
|
-
(async () => {
|
|
109
|
-
if (type === "interaction commands" && client.settings.logging) console.log(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} servers.`, "text", "cyan"));
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
if (client.settings.global == true) {
|
|
113
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} in ${(await client.guilds.fetch()).size} server(s) globally.`, 'text', 'purple'));
|
|
114
|
-
rest.put(Routes.applicationCommands(client.user.id), {
|
|
115
|
-
body: this.commands
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} locally.`, 'text', 'purple'));
|
|
120
|
-
rest.put(Routes.applicationGuildCommands(client.user.id, client.settings.guildId), {
|
|
121
|
-
body: this.commands
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
throw new Error(e)
|
|
127
|
-
}
|
|
128
|
-
})();
|
|
129
|
-
})
|
|
40
|
+
this.load.loadAllMessageCommands(path, logging);
|
|
130
41
|
}
|
|
131
42
|
}
|
|
132
43
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { logStyle } = require('dumfunctions');
|
|
2
1
|
const fs = require('fs');
|
|
2
|
+
const Discord = require('discord.js');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {object} client - Client object.
|
|
@@ -7,13 +7,13 @@ const fs = require('fs');
|
|
|
7
7
|
class EventHandler {
|
|
8
8
|
constructor({ client: client }) {
|
|
9
9
|
this.client = client;
|
|
10
|
+
|
|
11
|
+
client.events = new Discord.Collection()
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
loadAllEvents(path, logging) {
|
|
13
15
|
const eventFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'))
|
|
14
16
|
|
|
15
|
-
let events = [];
|
|
16
|
-
|
|
17
17
|
for (const file of eventFiles) {
|
|
18
18
|
let event = require(`${require("path").resolve(path)}/${file}`);
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ class EventHandler {
|
|
|
21
21
|
|
|
22
22
|
event.client = this.client;
|
|
23
23
|
|
|
24
|
-
events.
|
|
24
|
+
this.client.events.set(event.name, event);
|
|
25
25
|
|
|
26
26
|
if (event.once) {
|
|
27
27
|
this.emitter(event.type).once(event.name, (...args) => {
|
|
@@ -35,8 +35,6 @@ class EventHandler {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (logging || this.client.settings.logging) console.info(logStyle(`Loaded events: ${events.join(', ')}`, 'text', 'purple'));
|
|
39
|
-
|
|
40
38
|
const builderFiles = fs.readdirSync(`${__dirname}/../events`).filter(file => file.endsWith('.js'))
|
|
41
39
|
|
|
42
40
|
for (const file of builderFiles) {
|
|
@@ -3,25 +3,15 @@ const fs = require('fs');
|
|
|
3
3
|
const i = require('i18next');
|
|
4
4
|
|
|
5
5
|
class LanguageHandler {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(client) {
|
|
7
7
|
this.client = client;
|
|
8
8
|
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
this.fallbackLang = fallbackLang;
|
|
12
|
-
|
|
13
|
-
this.ns = ns;
|
|
14
|
-
|
|
15
|
-
i.init({
|
|
16
|
-
lng: lang,
|
|
17
|
-
fallbackLng: fallbackLang,
|
|
18
|
-
ns: ns
|
|
19
|
-
})
|
|
9
|
+
i.init(this.client.settings.language)
|
|
20
10
|
|
|
21
11
|
this.client.languages = []
|
|
22
12
|
}
|
|
23
13
|
|
|
24
|
-
|
|
14
|
+
loadAllLanguages(path, deep = true, overwrite = true) {
|
|
25
15
|
let langs = [];
|
|
26
16
|
|
|
27
17
|
const languages = fs.readdirSync(path).filter(file => file.endsWith('.json'));
|
|
@@ -29,20 +19,14 @@ class LanguageHandler {
|
|
|
29
19
|
for (const file of languages) {
|
|
30
20
|
const language = require(`${require("path").resolve(path)}/${file}`);
|
|
31
21
|
|
|
32
|
-
i.addResourceBundle(
|
|
33
|
-
file.replace('.json', ""),
|
|
34
|
-
this.ns,
|
|
35
|
-
language,
|
|
36
|
-
resources,
|
|
37
|
-
deep
|
|
38
|
-
)
|
|
22
|
+
i.addResourceBundle(file.replace('.json', ""), this.ns, language, deep, overwrite)
|
|
39
23
|
|
|
40
24
|
this.client.languages.push(file.replace('.json', ""));
|
|
41
25
|
|
|
42
26
|
langs.push(file.replace('.json', ""));
|
|
43
27
|
}
|
|
44
28
|
|
|
45
|
-
if (
|
|
29
|
+
if (this.client.settings.logging) console.info(logStyle(`Loaded languages: ${langs.join(', ')}`, 'text', 'purple'))
|
|
46
30
|
}
|
|
47
31
|
}
|
|
48
32
|
|
|
@@ -0,0 +1,205 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xernerx",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A bot framework for discord.js. [BETA]",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@discordjs/rest": "1.0.1",
|
|
21
21
|
"@sapphire/shapeshift": "3.5.1",
|
|
22
|
-
"discord-api-types": "^0.37.
|
|
23
|
-
"discord.js": "^14.
|
|
22
|
+
"discord-api-types": "^0.37.3",
|
|
23
|
+
"discord.js": "^14.2.0",
|
|
24
24
|
"dumfunctions": "^1.0.7",
|
|
25
|
-
"i18next": "^21.
|
|
25
|
+
"i18next": "^21.9.1"
|
|
26
26
|
},
|
|
27
27
|
"packageManager": "npm@8.5.5"
|
|
28
28
|
}
|