xernerx 3.4.2 → 3.5.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/README.md +10 -10
- package/dist/build/ContextCommandBuilder.js +93 -88
- package/dist/build/EventBuilder.js +34 -35
- package/dist/build/InhibitorBuilder.js +27 -28
- package/dist/build/MessageCommandBuilder.js +90 -80
- package/dist/build/SlashCommandBuilder.js +125 -118
- package/dist/client/XernerxClient.js +101 -81
- package/dist/handlers/CommandHandler.js +42 -42
- package/dist/handlers/EventHandler.js +16 -16
- package/dist/handlers/Handler.js +250 -250
- package/dist/handlers/InhibitorHandler.js +21 -21
- package/dist/main.cjs +2012 -0
- package/dist/main.js +42 -42
- package/dist/models/CommandArguments.js +121 -123
- package/dist/models/Events.js +294 -304
- package/dist/models/Extensions.js +23 -23
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/package.js +37 -41
- package/dist/types/enums.js +35 -35
- package/dist/types/interfaces.js +1 -1
- package/dist/types/options.js +1 -1
- package/dist/types/types.js +1 -1
- package/dist/utils/ClientUtil.js +222 -218
- package/dist/utils/CommandUtil.js +248 -260
- package/dist/validators/CommandValidations.js +183 -185
- package/dist/validators/InhibitorValidations.js +42 -42
- package/dist/validators/Shapes.js +1 -0
- package/package.json +54 -39
- package/types/build/ContextCommandBuilder.d.ts +68 -0
- package/{dist → types}/build/EventBuilder.d.ts +21 -17
- package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
- package/types/build/MessageCommandBuilder.d.ts +59 -0
- package/types/build/SlashCommandBuilder.d.ts +64 -0
- package/{dist → types}/client/XernerxClient.d.ts +28 -28
- package/{dist → types}/handlers/CommandHandler.d.ts +27 -26
- package/{dist → types}/handlers/EventHandler.d.ts +13 -12
- package/{dist → types}/handlers/Handler.d.ts +57 -57
- package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -17
- package/{dist → types}/main.d.ts +44 -30
- package/{dist → types}/models/CommandArguments.d.ts +17 -17
- package/{dist → types}/models/Events.d.ts +24 -24
- package/{dist → types}/models/Extensions.d.ts +7 -7
- package/{dist → types}/tools/XernerxError.d.ts +5 -5
- package/{dist → types}/tools/package.d.ts +38 -38
- package/types/types/enums.d.ts +44 -0
- package/{dist → types}/types/interfaces.d.ts +25 -25
- package/{dist → types}/types/options.d.ts +241 -206
- package/{dist → types}/types/types.d.ts +61 -32
- package/{dist → types}/utils/ClientUtil.d.ts +25 -25
- package/{dist → types}/utils/CommandUtil.d.ts +58 -56
- package/{dist → types}/validators/CommandValidations.d.ts +12 -7
- package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
- package/types/validators/Shapes.d.ts +1 -0
- package/dist/build/ContextCommandBuilder.d.ts +0 -42
- package/dist/build/MessageCommandBuilder.d.ts +0 -42
- package/dist/build/SlashCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.js +0 -84
- package/dist/build/XEventBuilder.d.ts +0 -17
- package/dist/build/XEventBuilder.js +0 -35
- package/dist/build/XInhibitorBuilder.d.ts +0 -20
- package/dist/build/XInhibitorBuilder.js +0 -28
- package/dist/build/XMessageCommandBuilder.d.ts +0 -42
- package/dist/build/XMessageCommandBuilder.js +0 -80
- package/dist/build/XSlashCommandBuilder.d.ts +0 -36
- package/dist/build/XSlashCommandBuilder.js +0 -114
- package/dist/models/CommandValidations.d.ts +0 -4
- package/dist/models/CommandValidations.js +0 -183
- package/dist/models/InhibitorValidations.d.ts +0 -12
- package/dist/models/InhibitorValidations.js +0 -42
- package/dist/types/enums.d.ts +0 -35
package/dist/handlers/Handler.js
CHANGED
|
@@ -1,250 +1,250 @@
|
|
|
1
|
-
import fs from '
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { CommandType } from '../types/enums.js';
|
|
4
|
-
import { s } from '@sapphire/shapeshift';
|
|
5
|
-
import { Style } from 'dumfunctions';
|
|
6
|
-
/**
|
|
7
|
-
* @description - The Handler class.
|
|
8
|
-
* @param {XernerxClient} client - The XernerxClient.
|
|
9
|
-
*/
|
|
10
|
-
export class Handler {
|
|
11
|
-
client;
|
|
12
|
-
commands;
|
|
13
|
-
readyTimestamp;
|
|
14
|
-
constructor(client) {
|
|
15
|
-
this.client = client;
|
|
16
|
-
this.commands = [];
|
|
17
|
-
this.readyTimestamp = Number(Date.now());
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @description - The loader for the message commands.
|
|
21
|
-
* @param {MessageCommandOptions} options - The options for the message command loader.
|
|
22
|
-
*/
|
|
23
|
-
loadAllMessageCommands(options) {
|
|
24
|
-
this.client.handlerOptions.message = s
|
|
25
|
-
.object({
|
|
26
|
-
directory: s.string,
|
|
27
|
-
prefix: s.union(s.string, s.array(s.string)),
|
|
28
|
-
allowMention: s.boolean.default(false),
|
|
29
|
-
cooldown: s.number.default(0),
|
|
30
|
-
userPermissions: s.array(s.bigint).default([]),
|
|
31
|
-
clientPermissions: s.array(s.bigint).default([]),
|
|
32
|
-
handleEdits: s.boolean.default(false),
|
|
33
|
-
handleDeletes: s.boolean.default(false),
|
|
34
|
-
handleTyping: s.boolean.default(false),
|
|
35
|
-
logging: s.boolean.default(false),
|
|
36
|
-
})
|
|
37
|
-
.parse(options);
|
|
38
|
-
const files = this.readdir(options.directory), loaded = [];
|
|
39
|
-
for (const file of files) {
|
|
40
|
-
this.load(options.directory, file, CommandType.MessageCommand);
|
|
41
|
-
loaded.push(file.replace('.js', ''));
|
|
42
|
-
}
|
|
43
|
-
if (this.client.handlerOptions.message?.logging)
|
|
44
|
-
console.info(Style.log(`Xernerx | Loaded ${loaded.length} message commands: ${loaded.join(', ')}.`, {
|
|
45
|
-
color: Style.TextColor.Cyan,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @description - The loader for the slash commands.
|
|
50
|
-
* @param {SlashCommandOptions} options - The options for the slash command loader.
|
|
51
|
-
*/
|
|
52
|
-
loadAllSlashCommands(options) {
|
|
53
|
-
this.client.handlerOptions.slash = s
|
|
54
|
-
.object({
|
|
55
|
-
directory: s.string,
|
|
56
|
-
guildId: s.string,
|
|
57
|
-
global: s.boolean,
|
|
58
|
-
cooldown: s.number.default(0),
|
|
59
|
-
userPermissions: s.array(s.bigint).default([]),
|
|
60
|
-
clientPermissions: s.array(s.bigint).default([]),
|
|
61
|
-
logging: s.boolean.default(false),
|
|
62
|
-
defer: s.object({
|
|
63
|
-
reply: s.boolean.optional,
|
|
64
|
-
ephemeral: s.boolean.optional,
|
|
65
|
-
fetchReply: s.boolean.optional,
|
|
66
|
-
}).optional,
|
|
67
|
-
})
|
|
68
|
-
.parse(options);
|
|
69
|
-
const files = this.readdir(options.directory), loaded = [];
|
|
70
|
-
for (const file of files) {
|
|
71
|
-
this.load(options.directory, file, CommandType.SlashCommand);
|
|
72
|
-
loaded.push(file.replace('.js', ''));
|
|
73
|
-
}
|
|
74
|
-
if (this.client.handlerOptions.slash?.logging)
|
|
75
|
-
console.info(Style.log(`Xernerx | Loaded ${loaded.length} slash commands: ${loaded.join(', ')}.`, {
|
|
76
|
-
color: Style.TextColor.Cyan,
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @description - The loader for the context commands.
|
|
81
|
-
* @param {ContextCommandOptions} options - The options for the context command loader.
|
|
82
|
-
*/
|
|
83
|
-
loadAllContextCommands(options) {
|
|
84
|
-
this.client.handlerOptions.context = s
|
|
85
|
-
.object({
|
|
86
|
-
directory: s.string,
|
|
87
|
-
guildId: s.string,
|
|
88
|
-
global: s.boolean,
|
|
89
|
-
cooldown: s.number.default(0),
|
|
90
|
-
userPermissions: s.array(s.bigint).default([]),
|
|
91
|
-
clientPermissions: s.array(s.bigint).default([]),
|
|
92
|
-
logging: s.boolean.default(false),
|
|
93
|
-
defer: s.object({
|
|
94
|
-
reply: s.boolean.optional,
|
|
95
|
-
ephemeral: s.boolean.optional,
|
|
96
|
-
fetchReply: s.boolean.optional,
|
|
97
|
-
}).optional,
|
|
98
|
-
})
|
|
99
|
-
.parse(options);
|
|
100
|
-
const files = this.readdir(options.directory), loaded = [];
|
|
101
|
-
for (const file of files) {
|
|
102
|
-
this.load(options.directory, file, CommandType.ContextCommand);
|
|
103
|
-
loaded.push(file.replace('.js', ''));
|
|
104
|
-
}
|
|
105
|
-
if (this.client.handlerOptions.context?.logging)
|
|
106
|
-
console.info(Style.log(`Xernerx | Loaded ${loaded.length} context commands: ${loaded.join(', ')}.`, {
|
|
107
|
-
color: Style.TextColor.Cyan,
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* @description - The loader for the events.
|
|
112
|
-
* @param {EventLoadOptions} options - The options for the event loader.
|
|
113
|
-
*/
|
|
114
|
-
loadAllEvents(options) {
|
|
115
|
-
this.client.handlerOptions.events = s
|
|
116
|
-
.object({
|
|
117
|
-
directory: s.string,
|
|
118
|
-
logging: s.boolean.default(false),
|
|
119
|
-
})
|
|
120
|
-
.parse(options);
|
|
121
|
-
const files = this.readdir(options.directory), loaded = [];
|
|
122
|
-
(async () => {
|
|
123
|
-
for (const file of files) {
|
|
124
|
-
try {
|
|
125
|
-
options.directory.split(/\//).shift();
|
|
126
|
-
let event = (await import('file://' + `${path.resolve(options.directory)}/${file}`)).default;
|
|
127
|
-
event = new event();
|
|
128
|
-
event.client = this.client;
|
|
129
|
-
event.commandType = CommandType.Event;
|
|
130
|
-
this.client.events.set(event.name, event);
|
|
131
|
-
this.emitter(event);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
|
|
135
|
-
}
|
|
136
|
-
loaded.push(file.replace('.js', ''));
|
|
137
|
-
}
|
|
138
|
-
if (this.client.handlerOptions.events?.logging)
|
|
139
|
-
console.info(Style.log(`Xernerx | Loaded ${loaded.length} events: ${loaded.join(', ')}.`, { color: Style.TextColor.Cyan }));
|
|
140
|
-
})();
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* @description - The loader for the inhibitors.
|
|
144
|
-
* @param {InhibitorLoadOptions} options - The options for the inhibitor loader.
|
|
145
|
-
*/
|
|
146
|
-
loadAllInhibitors(options) {
|
|
147
|
-
this.client.handlerOptions.inhibitors = s
|
|
148
|
-
.object({
|
|
149
|
-
directory: s.string,
|
|
150
|
-
logging: s.boolean.default(false),
|
|
151
|
-
})
|
|
152
|
-
.parse(options);
|
|
153
|
-
const files = this.readdir(options.directory), loaded = [];
|
|
154
|
-
for (const file of files) {
|
|
155
|
-
this.load(options.directory, file, CommandType.Inhibitor);
|
|
156
|
-
loaded.push(file.replace('.js', ''));
|
|
157
|
-
}
|
|
158
|
-
if (this.client.handlerOptions.inhibitors?.logging)
|
|
159
|
-
console.info(Style.log(`Xernerx | Loaded ${loaded.length} inhibitors: ${loaded.join(', ')}.`, {
|
|
160
|
-
color: Style.TextColor.Cyan,
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* @description - a reader for directories
|
|
165
|
-
* @param {string} dir - the directory to look for.
|
|
166
|
-
* @returns array of files.
|
|
167
|
-
*/
|
|
168
|
-
readdir(dir) {
|
|
169
|
-
try {
|
|
170
|
-
return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
console.error(Style.log(`Xernerx | Couldn't read ${dir} because <${error}>.`, { color: Style.BackgroundColor.Red }));
|
|
174
|
-
}
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @description file loader.
|
|
179
|
-
* @param {string} dir - the directory.
|
|
180
|
-
* @param {string} file - the file in the directory.
|
|
181
|
-
* @param {string} type - the type of file.
|
|
182
|
-
* @returns undefined
|
|
183
|
-
*/
|
|
184
|
-
async load(dir, file, type) {
|
|
185
|
-
try {
|
|
186
|
-
dir.split(/\//).shift();
|
|
187
|
-
let command = (await import('file://' + `${path.resolve(dir)}/${file}`)).default;
|
|
188
|
-
command = new command();
|
|
189
|
-
command.client = this.client;
|
|
190
|
-
command.commandType = type;
|
|
191
|
-
command.filepath = `${path.resolve(dir)}\\${file}`;
|
|
192
|
-
command.file = file;
|
|
193
|
-
if (type === CommandType.MessageCommand)
|
|
194
|
-
this.client.commands.message.set(command?.name || command?.name, command);
|
|
195
|
-
if (type === CommandType.SlashCommand) {
|
|
196
|
-
this.client.commands.slash.set(command?.data?.name || command?.name, command);
|
|
197
|
-
}
|
|
198
|
-
if (type === CommandType.ContextCommand) {
|
|
199
|
-
this.client.commands.context.set(command?.data?.name || command?.name, command);
|
|
200
|
-
}
|
|
201
|
-
if (type === CommandType.Event) {
|
|
202
|
-
this.client.events.set(command.name, command);
|
|
203
|
-
}
|
|
204
|
-
if (type === CommandType.Inhibitor) {
|
|
205
|
-
this.client.inhibitors.set(command.name, command);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* @description the event emitter to emit all events.
|
|
214
|
-
* @param {object} event - the event to be emitted.
|
|
215
|
-
* @returns void
|
|
216
|
-
*/
|
|
217
|
-
emitter(event) {
|
|
218
|
-
const client = this.client;
|
|
219
|
-
if (event.emitter === 'client') {
|
|
220
|
-
if (event.once)
|
|
221
|
-
client.once(event.name, (...args) => {
|
|
222
|
-
event.run(...args);
|
|
223
|
-
});
|
|
224
|
-
else
|
|
225
|
-
client.on(event.name, (...args) => {
|
|
226
|
-
event.run(...args);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
else if (event.emitter === 'rest') {
|
|
230
|
-
if (event.once)
|
|
231
|
-
client.once(event.name, (...args) => {
|
|
232
|
-
event.run(...args);
|
|
233
|
-
});
|
|
234
|
-
else
|
|
235
|
-
client.on(event.name, (...args) => {
|
|
236
|
-
event.run(...args);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
else if (event.emitter === 'process') {
|
|
240
|
-
if (event.once)
|
|
241
|
-
process.once(event.name, (...args) => {
|
|
242
|
-
event.run(...args);
|
|
243
|
-
});
|
|
244
|
-
else
|
|
245
|
-
process.on(event.name, (...args) => {
|
|
246
|
-
event.run(...args);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { CommandType } from '../types/enums.js';
|
|
4
|
+
import { s } from '@sapphire/shapeshift';
|
|
5
|
+
import { Style } from 'dumfunctions';
|
|
6
|
+
/**
|
|
7
|
+
* @description - The Handler class.
|
|
8
|
+
* @param {XernerxClient} client - The XernerxClient.
|
|
9
|
+
*/
|
|
10
|
+
export class Handler {
|
|
11
|
+
client;
|
|
12
|
+
commands;
|
|
13
|
+
readyTimestamp;
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.commands = [];
|
|
17
|
+
this.readyTimestamp = Number(Date.now());
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @description - The loader for the message commands.
|
|
21
|
+
* @param {MessageCommandOptions} options - The options for the message command loader.
|
|
22
|
+
*/
|
|
23
|
+
loadAllMessageCommands(options) {
|
|
24
|
+
this.client.handlerOptions.message = s
|
|
25
|
+
.object({
|
|
26
|
+
directory: s.string,
|
|
27
|
+
prefix: s.union(s.string, s.array(s.string)),
|
|
28
|
+
allowMention: s.boolean.default(false),
|
|
29
|
+
cooldown: s.number.default(0),
|
|
30
|
+
userPermissions: s.array(s.bigint).default([]),
|
|
31
|
+
clientPermissions: s.array(s.bigint).default([]),
|
|
32
|
+
handleEdits: s.boolean.default(false),
|
|
33
|
+
handleDeletes: s.boolean.default(false),
|
|
34
|
+
handleTyping: s.boolean.default(false),
|
|
35
|
+
logging: s.boolean.default(false),
|
|
36
|
+
})
|
|
37
|
+
.parse(options);
|
|
38
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
this.load(options.directory, file, CommandType.MessageCommand);
|
|
41
|
+
loaded.push(file.replace('.js', ''));
|
|
42
|
+
}
|
|
43
|
+
if (this.client.handlerOptions.message?.logging)
|
|
44
|
+
console.info(Style.log(`Xernerx | Loaded ${loaded.length} message commands: ${loaded.join(', ')}.`, {
|
|
45
|
+
color: Style.TextColor.Cyan,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description - The loader for the slash commands.
|
|
50
|
+
* @param {SlashCommandOptions} options - The options for the slash command loader.
|
|
51
|
+
*/
|
|
52
|
+
loadAllSlashCommands(options) {
|
|
53
|
+
this.client.handlerOptions.slash = s
|
|
54
|
+
.object({
|
|
55
|
+
directory: s.string,
|
|
56
|
+
guildId: s.string,
|
|
57
|
+
global: s.boolean,
|
|
58
|
+
cooldown: s.number.default(0),
|
|
59
|
+
userPermissions: s.array(s.bigint).default([]),
|
|
60
|
+
clientPermissions: s.array(s.bigint).default([]),
|
|
61
|
+
logging: s.boolean.default(false),
|
|
62
|
+
defer: s.object({
|
|
63
|
+
reply: s.boolean.optional,
|
|
64
|
+
ephemeral: s.boolean.optional,
|
|
65
|
+
fetchReply: s.boolean.optional,
|
|
66
|
+
}).optional,
|
|
67
|
+
})
|
|
68
|
+
.parse(options);
|
|
69
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
this.load(options.directory, file, CommandType.SlashCommand);
|
|
72
|
+
loaded.push(file.replace('.js', ''));
|
|
73
|
+
}
|
|
74
|
+
if (this.client.handlerOptions.slash?.logging)
|
|
75
|
+
console.info(Style.log(`Xernerx | Loaded ${loaded.length} slash commands: ${loaded.join(', ')}.`, {
|
|
76
|
+
color: Style.TextColor.Cyan,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description - The loader for the context commands.
|
|
81
|
+
* @param {ContextCommandOptions} options - The options for the context command loader.
|
|
82
|
+
*/
|
|
83
|
+
loadAllContextCommands(options) {
|
|
84
|
+
this.client.handlerOptions.context = s
|
|
85
|
+
.object({
|
|
86
|
+
directory: s.string,
|
|
87
|
+
guildId: s.string,
|
|
88
|
+
global: s.boolean,
|
|
89
|
+
cooldown: s.number.default(0),
|
|
90
|
+
userPermissions: s.array(s.bigint).default([]),
|
|
91
|
+
clientPermissions: s.array(s.bigint).default([]),
|
|
92
|
+
logging: s.boolean.default(false),
|
|
93
|
+
defer: s.object({
|
|
94
|
+
reply: s.boolean.optional,
|
|
95
|
+
ephemeral: s.boolean.optional,
|
|
96
|
+
fetchReply: s.boolean.optional,
|
|
97
|
+
}).optional,
|
|
98
|
+
})
|
|
99
|
+
.parse(options);
|
|
100
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
101
|
+
for (const file of files) {
|
|
102
|
+
this.load(options.directory, file, CommandType.ContextCommand);
|
|
103
|
+
loaded.push(file.replace('.js', ''));
|
|
104
|
+
}
|
|
105
|
+
if (this.client.handlerOptions.context?.logging)
|
|
106
|
+
console.info(Style.log(`Xernerx | Loaded ${loaded.length} context commands: ${loaded.join(', ')}.`, {
|
|
107
|
+
color: Style.TextColor.Cyan,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @description - The loader for the events.
|
|
112
|
+
* @param {EventLoadOptions} options - The options for the event loader.
|
|
113
|
+
*/
|
|
114
|
+
loadAllEvents(options) {
|
|
115
|
+
this.client.handlerOptions.events = s
|
|
116
|
+
.object({
|
|
117
|
+
directory: s.string,
|
|
118
|
+
logging: s.boolean.default(false),
|
|
119
|
+
})
|
|
120
|
+
.parse(options);
|
|
121
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
122
|
+
(async () => {
|
|
123
|
+
for (const file of files) {
|
|
124
|
+
try {
|
|
125
|
+
options.directory.split(/\//).shift();
|
|
126
|
+
let event = (await import('file://' + `${path.resolve(options.directory)}/${file}`)).default;
|
|
127
|
+
event = new event();
|
|
128
|
+
event.client = this.client;
|
|
129
|
+
event.commandType = CommandType.Event;
|
|
130
|
+
this.client.events.set(event.name, event);
|
|
131
|
+
this.emitter(event);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
|
|
135
|
+
}
|
|
136
|
+
loaded.push(file.replace('.js', ''));
|
|
137
|
+
}
|
|
138
|
+
if (this.client.handlerOptions.events?.logging)
|
|
139
|
+
console.info(Style.log(`Xernerx | Loaded ${loaded.length} events: ${loaded.join(', ')}.`, { color: Style.TextColor.Cyan }));
|
|
140
|
+
})();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @description - The loader for the inhibitors.
|
|
144
|
+
* @param {InhibitorLoadOptions} options - The options for the inhibitor loader.
|
|
145
|
+
*/
|
|
146
|
+
loadAllInhibitors(options) {
|
|
147
|
+
this.client.handlerOptions.inhibitors = s
|
|
148
|
+
.object({
|
|
149
|
+
directory: s.string,
|
|
150
|
+
logging: s.boolean.default(false),
|
|
151
|
+
})
|
|
152
|
+
.parse(options);
|
|
153
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
154
|
+
for (const file of files) {
|
|
155
|
+
this.load(options.directory, file, CommandType.Inhibitor);
|
|
156
|
+
loaded.push(file.replace('.js', ''));
|
|
157
|
+
}
|
|
158
|
+
if (this.client.handlerOptions.inhibitors?.logging)
|
|
159
|
+
console.info(Style.log(`Xernerx | Loaded ${loaded.length} inhibitors: ${loaded.join(', ')}.`, {
|
|
160
|
+
color: Style.TextColor.Cyan,
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @description - a reader for directories
|
|
165
|
+
* @param {string} dir - the directory to look for.
|
|
166
|
+
* @returns array of files.
|
|
167
|
+
*/
|
|
168
|
+
readdir(dir) {
|
|
169
|
+
try {
|
|
170
|
+
return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error(Style.log(`Xernerx | Couldn't read ${dir} because <${error}>.`, { color: Style.BackgroundColor.Red }));
|
|
174
|
+
}
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @description file loader.
|
|
179
|
+
* @param {string} dir - the directory.
|
|
180
|
+
* @param {string} file - the file in the directory.
|
|
181
|
+
* @param {string} type - the type of file.
|
|
182
|
+
* @returns undefined
|
|
183
|
+
*/
|
|
184
|
+
async load(dir, file, type) {
|
|
185
|
+
try {
|
|
186
|
+
dir.split(/\//).shift();
|
|
187
|
+
let command = (await import('file://' + `${path.resolve(dir)}/${file}`)).default;
|
|
188
|
+
command = new command();
|
|
189
|
+
command.client = this.client;
|
|
190
|
+
command.commandType = type;
|
|
191
|
+
command.filepath = `${path.resolve(dir)}\\${file}`;
|
|
192
|
+
command.file = file;
|
|
193
|
+
if (type === CommandType.MessageCommand)
|
|
194
|
+
this.client.commands.message.set(command?.name || command?.name, command);
|
|
195
|
+
if (type === CommandType.SlashCommand) {
|
|
196
|
+
this.client.commands.slash.set(command?.data?.name || command?.name, command);
|
|
197
|
+
}
|
|
198
|
+
if (type === CommandType.ContextCommand) {
|
|
199
|
+
this.client.commands.context.set(command?.data?.name || command?.name, command);
|
|
200
|
+
}
|
|
201
|
+
if (type === CommandType.Event) {
|
|
202
|
+
this.client.events.set(command.name, command);
|
|
203
|
+
}
|
|
204
|
+
if (type === CommandType.Inhibitor) {
|
|
205
|
+
this.client.inhibitors.set(command.name, command);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error(Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: Style.BackgroundColor.Red }));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @description the event emitter to emit all events.
|
|
214
|
+
* @param {object} event - the event to be emitted.
|
|
215
|
+
* @returns void
|
|
216
|
+
*/
|
|
217
|
+
emitter(event) {
|
|
218
|
+
const client = this.client;
|
|
219
|
+
if (event.emitter === 'client') {
|
|
220
|
+
if (event.once)
|
|
221
|
+
client.once(event.name, (...args) => {
|
|
222
|
+
event.run(...args);
|
|
223
|
+
});
|
|
224
|
+
else
|
|
225
|
+
client.on(event.name, (...args) => {
|
|
226
|
+
event.run(...args);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else if (event.emitter === 'rest') {
|
|
230
|
+
if (event.once)
|
|
231
|
+
client.once(event.name, (...args) => {
|
|
232
|
+
event.run(...args);
|
|
233
|
+
});
|
|
234
|
+
else
|
|
235
|
+
client.on(event.name, (...args) => {
|
|
236
|
+
event.run(...args);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
else if (event.emitter === 'process') {
|
|
240
|
+
if (event.once)
|
|
241
|
+
process.once(event.name, (...args) => {
|
|
242
|
+
event.run(...args);
|
|
243
|
+
});
|
|
244
|
+
else
|
|
245
|
+
process.on(event.name, (...args) => {
|
|
246
|
+
event.run(...args);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Handler } from './Handler.js';
|
|
2
|
-
/**
|
|
3
|
-
* @description - Inhibitor loader.
|
|
4
|
-
* @param {XernerxClient} client - The XernerxClient.
|
|
5
|
-
*/
|
|
6
|
-
export default class InhibitorHandler {
|
|
7
|
-
client;
|
|
8
|
-
handler;
|
|
9
|
-
constructor(client) {
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.handler = new Handler(client);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @description - The loader for all inhibitors.
|
|
15
|
-
* @param {InhibitorLoadOptions} options - the inhibitor loader options.
|
|
16
|
-
* @returns undefined
|
|
17
|
-
*/
|
|
18
|
-
loadAllInhibitors(options) {
|
|
19
|
-
this.handler.loadAllInhibitors(options);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import { Handler } from './Handler.js';
|
|
2
|
+
/**
|
|
3
|
+
* @description - Inhibitor loader.
|
|
4
|
+
* @param {XernerxClient} client - The XernerxClient.
|
|
5
|
+
*/
|
|
6
|
+
export default class InhibitorHandler {
|
|
7
|
+
client;
|
|
8
|
+
handler;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.handler = new Handler(client);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @description - The loader for all inhibitors.
|
|
15
|
+
* @param {InhibitorLoadOptions} options - the inhibitor loader options.
|
|
16
|
+
* @returns undefined
|
|
17
|
+
*/
|
|
18
|
+
loadAllInhibitors(options) {
|
|
19
|
+
this.handler.loadAllInhibitors(options);
|
|
20
|
+
}
|
|
21
|
+
}
|