xernerx 4.17.7 → 5.0.2
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 +14 -67
- package/dist/main.cjs +63 -0
- package/dist/main.cjs.map +1 -0
- package/dist/main.d.cts +21 -0
- package/dist/main.d.ts +20 -46
- package/dist/main.js +23 -49
- package/dist/main.js.map +1 -0
- package/package.json +63 -47
- package/src/main.ts +26 -0
- package/dist/build/XernerxContextCommand.d.ts +0 -82
- package/dist/build/XernerxContextCommand.js +0 -125
- package/dist/build/XernerxEvent.d.ts +0 -21
- package/dist/build/XernerxEvent.js +0 -27
- package/dist/build/XernerxInhibitor.d.ts +0 -53
- package/dist/build/XernerxInhibitor.js +0 -27
- package/dist/build/XernerxMessageCommand.d.ts +0 -84
- package/dist/build/XernerxMessageCommand.js +0 -123
- package/dist/build/XernerxSlashCommand.d.ts +0 -104
- package/dist/build/XernerxSlashCommand.js +0 -182
- package/dist/client/XernerxClient.d.ts +0 -70
- package/dist/client/XernerxClient.js +0 -106
- package/dist/client/XernerxShardClient.d.ts +0 -21
- package/dist/client/XernerxShardClient.js +0 -67
- package/dist/functions/deploy.d.ts +0 -3
- package/dist/functions/deploy.js +0 -56
- package/dist/functions/load.d.ts +0 -4
- package/dist/functions/load.js +0 -34
- package/dist/functions/reload.d.ts +0 -3
- package/dist/functions/reload.js +0 -29
- package/dist/functions/setPresence.d.ts +0 -4
- package/dist/functions/setPresence.js +0 -22
- package/dist/functions/xernerxUser.d.ts +0 -4
- package/dist/functions/xernerxUser.js +0 -10
- package/dist/handlers/CommandHandler.d.ts +0 -16
- package/dist/handlers/CommandHandler.js +0 -326
- package/dist/handlers/EventHandler.d.ts +0 -9
- package/dist/handlers/EventHandler.js +0 -56
- package/dist/handlers/ExtensionHandler.d.ts +0 -9
- package/dist/handlers/ExtensionHandler.js +0 -29
- package/dist/handlers/Handler.d.ts +0 -31
- package/dist/handlers/Handler.js +0 -52
- package/dist/handlers/InhibitorHandler.d.ts +0 -9
- package/dist/handlers/InhibitorHandler.js +0 -33
- package/dist/handlers/IntegrationHandler.d.ts +0 -15
- package/dist/handlers/IntegrationHandler.js +0 -26
- package/dist/models/Arguments.d.ts +0 -12
- package/dist/models/Arguments.js +0 -139
- package/dist/models/Cooldowns.d.ts +0 -11
- package/dist/models/Cooldowns.js +0 -29
- package/dist/tools/XernerxError.d.ts +0 -7
- package/dist/tools/XernerxError.js +0 -11
- package/dist/tools/XernerxIntents.d.ts +0 -6
- package/dist/tools/XernerxIntents.js +0 -26
- package/dist/tools/XernerxLog.d.ts +0 -31
- package/dist/tools/XernerxLog.js +0 -148
- package/dist/tools/XernerxText.d.ts +0 -31
- package/dist/tools/XernerxText.js +0 -84
- package/dist/types/extenders.d.ts +0 -84
- package/dist/types/extenders.js +0 -2
- package/dist/types/interfaces.d.ts +0 -263
- package/dist/types/interfaces.js +0 -2
- package/dist/types/types.d.ts +0 -111
- package/dist/types/types.js +0 -2
- package/dist/utils/ClientUtil.d.ts +0 -22
- package/dist/utils/ClientUtil.js +0 -102
- package/dist/utils/InteractionUtil.d.ts +0 -25
- package/dist/utils/InteractionUtil.js +0 -154
- package/dist/utils/MessageUtil.d.ts +0 -26
- package/dist/utils/MessageUtil.js +0 -168
- package/dist/utils/Util.d.ts +0 -12
- package/dist/utils/Util.js +0 -11
- package/dist/validators/commandValidation.d.ts +0 -10
- package/dist/validators/commandValidation.js +0 -167
- package/dist/validators/inhibitorValidations.d.ts +0 -28
- package/dist/validators/inhibitorValidations.js +0 -44
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { GatewayIntentBits } from 'discord.js';
|
|
5
|
-
import Handler from './Handler.js';
|
|
6
|
-
import MessageUtil from '../utils/MessageUtil.js';
|
|
7
|
-
import { xernerxUser } from '../functions/xernerxUser.js';
|
|
8
|
-
import InteractionUtil from '../utils/InteractionUtil.js';
|
|
9
|
-
import commandValidation from '../validators/commandValidation.js';
|
|
10
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
11
|
-
import { interactionArguments, messageArguments } from '../models/Arguments.js';
|
|
12
|
-
import { inhibitorValidation } from '../validators/inhibitorValidations.js';
|
|
13
|
-
import { Style } from 'dumfunctions';
|
|
14
|
-
export default class CommandHandler extends Handler {
|
|
15
|
-
constructor(client) {
|
|
16
|
-
super(client);
|
|
17
|
-
this.readyTimestamp = Number(Date.now());
|
|
18
|
-
}
|
|
19
|
-
async loadMessageCommands(options) {
|
|
20
|
-
const commands = [];
|
|
21
|
-
if (!this.client.options.intents.has(GatewayIntentBits.MessageContent)) new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
|
|
22
|
-
if (!this.client.options.intents.has(GatewayIntentBits.GuildMessages)) new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent GuildMessages!`);
|
|
23
|
-
options = z
|
|
24
|
-
.object({
|
|
25
|
-
directory: z.string(),
|
|
26
|
-
prefix: z.string().or(z.array(z.string())),
|
|
27
|
-
allowMention: z.boolean().default(false),
|
|
28
|
-
cooldown: z.number().default(0),
|
|
29
|
-
permissions: z
|
|
30
|
-
.object({
|
|
31
|
-
user: z.array(z.string()).or(z.null()).default(null),
|
|
32
|
-
client: z.array(z.string()).or(z.null()).default(null),
|
|
33
|
-
dm: z.boolean().default(true),
|
|
34
|
-
})
|
|
35
|
-
.default({}),
|
|
36
|
-
handleEdits: z.boolean().default(false),
|
|
37
|
-
handleDeletes: z.boolean().default(false),
|
|
38
|
-
handleTyping: z.boolean().default(false),
|
|
39
|
-
logging: z.boolean().default(false),
|
|
40
|
-
})
|
|
41
|
-
.parse(options);
|
|
42
|
-
this.client.modules.options.message = options;
|
|
43
|
-
const files = await this.readdir(options.directory, 'MessageCommands');
|
|
44
|
-
for (const file of files) {
|
|
45
|
-
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
46
|
-
const command = await this.load(filepath, 'MessageCommand');
|
|
47
|
-
this._checks(command);
|
|
48
|
-
commands.push(command.id);
|
|
49
|
-
}
|
|
50
|
-
new XernerxLog(this.client).info(
|
|
51
|
-
`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Message Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`
|
|
52
|
-
);
|
|
53
|
-
this.emit({
|
|
54
|
-
name: 'messageCreate',
|
|
55
|
-
filetype: 'MessageCommand',
|
|
56
|
-
run: (message) => this.messageCommandRun(message),
|
|
57
|
-
});
|
|
58
|
-
this.emit({
|
|
59
|
-
name: 'messageUpdate',
|
|
60
|
-
filetype: 'MessageCommand',
|
|
61
|
-
run: (message, message2) => this.messageCommandRun(message, message2),
|
|
62
|
-
});
|
|
63
|
-
this.emit({
|
|
64
|
-
name: 'messageDelete',
|
|
65
|
-
filetype: 'MessageCommand',
|
|
66
|
-
run: (message) => this.messageCommandRun(message, 'delete'),
|
|
67
|
-
});
|
|
68
|
-
this.client.on('messageReactionAdd', (message) => {
|
|
69
|
-
message.util = new MessageUtil(this.client, message);
|
|
70
|
-
});
|
|
71
|
-
this.client.on('messageReactionRemove', (message) => {
|
|
72
|
-
message.util = new MessageUtil(this.client, message);
|
|
73
|
-
});
|
|
74
|
-
this.client.on('messageReactionRemoveAll', (message) => {
|
|
75
|
-
message.util = new MessageUtil(this.client, message);
|
|
76
|
-
});
|
|
77
|
-
this.client.on('messageReactionRemoveEmoji', (message) => {
|
|
78
|
-
message.util = new MessageUtil(this.client, message);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
// public reloadMessageCommands() {
|
|
82
|
-
// return reload(this.client, 'message');
|
|
83
|
-
// }
|
|
84
|
-
async loadSlashCommands(options) {
|
|
85
|
-
const commands = [];
|
|
86
|
-
if (!this.client.settings.local) new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
|
|
87
|
-
options = z
|
|
88
|
-
.object({
|
|
89
|
-
directory: z.string(),
|
|
90
|
-
cooldown: z.number().default(0),
|
|
91
|
-
permissions: z
|
|
92
|
-
.object({
|
|
93
|
-
user: z.array(z.string()).or(z.null()).default(null),
|
|
94
|
-
client: z.array(z.string()).or(z.null()).default(null),
|
|
95
|
-
dm: z.boolean().default(true),
|
|
96
|
-
})
|
|
97
|
-
.default({}),
|
|
98
|
-
logging: z.boolean().default(false),
|
|
99
|
-
defer: z
|
|
100
|
-
.object({
|
|
101
|
-
reply: z.boolean().default(false),
|
|
102
|
-
ephemeral: z.boolean().default(false),
|
|
103
|
-
fetchReply: z.boolean().default(false),
|
|
104
|
-
})
|
|
105
|
-
.default({}),
|
|
106
|
-
})
|
|
107
|
-
.parse(options);
|
|
108
|
-
this.client.modules.options.slash = options;
|
|
109
|
-
const files = await this.readdir(options.directory, 'SlashCommands');
|
|
110
|
-
for (const file of files) {
|
|
111
|
-
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
112
|
-
const command = await this.load(filepath, 'SlashCommand');
|
|
113
|
-
commands.push(command.id);
|
|
114
|
-
}
|
|
115
|
-
new XernerxLog(this.client).info(
|
|
116
|
-
`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Slash Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`
|
|
117
|
-
);
|
|
118
|
-
this.emit({
|
|
119
|
-
name: 'interactionCreate',
|
|
120
|
-
filetype: 'SlashCommand',
|
|
121
|
-
run: (interaction) => this.slashCommandRun(interaction),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
async loadContextCommands(options) {
|
|
125
|
-
const commands = [];
|
|
126
|
-
if (!this.client.settings.local) new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
|
|
127
|
-
options = z
|
|
128
|
-
.object({
|
|
129
|
-
directory: z.string(),
|
|
130
|
-
cooldown: z.number().default(0),
|
|
131
|
-
permissions: z
|
|
132
|
-
.object({
|
|
133
|
-
user: z.array(z.string()).or(z.null()).default(null),
|
|
134
|
-
client: z.array(z.string()).or(z.null()).default(null),
|
|
135
|
-
dm: z.boolean().default(true),
|
|
136
|
-
})
|
|
137
|
-
.default({}),
|
|
138
|
-
logging: z.boolean().default(false),
|
|
139
|
-
defer: z
|
|
140
|
-
.object({
|
|
141
|
-
reply: z.boolean().default(false),
|
|
142
|
-
ephemeral: z.boolean().default(false),
|
|
143
|
-
fetchReply: z.boolean().default(false),
|
|
144
|
-
})
|
|
145
|
-
.default({}),
|
|
146
|
-
})
|
|
147
|
-
.parse(options);
|
|
148
|
-
this.client.modules.options.context = options;
|
|
149
|
-
const files = await this.readdir(options.directory, 'ContextCommands');
|
|
150
|
-
for (const file of files) {
|
|
151
|
-
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
152
|
-
const command = await this.load(filepath, 'ContextCommand');
|
|
153
|
-
commands.push(command.id);
|
|
154
|
-
}
|
|
155
|
-
new XernerxLog(this.client).info(
|
|
156
|
-
`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Context Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`
|
|
157
|
-
);
|
|
158
|
-
this.emit({
|
|
159
|
-
name: 'interactionCreate',
|
|
160
|
-
filetype: 'ContextCommand',
|
|
161
|
-
run: (interaction) => this.contextCommandRun(interaction),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
async messageCommandRun(message, message2) {
|
|
165
|
-
const filetype = 'MessageCommand';
|
|
166
|
-
if (message.author.id === this.client.user?.id && this.client.settings.ignore?.self) return;
|
|
167
|
-
else if (message.author.bot && this.client.settings.ignore?.bots) return;
|
|
168
|
-
if (message.system && this.client.settings.ignore?.system) return;
|
|
169
|
-
message.util = new MessageUtil(this.client, message);
|
|
170
|
-
message.user = await xernerxUser(message, this.client);
|
|
171
|
-
if (await inhibitorValidation(message, undefined, undefined, 'pre')) return;
|
|
172
|
-
if (typeof message2 === 'object') message = message2;
|
|
173
|
-
if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
|
|
174
|
-
if (!this.client.cache.messages.has(message.id)) return;
|
|
175
|
-
const id = this.client.cache.messages.get(message.id);
|
|
176
|
-
if (!id) return;
|
|
177
|
-
(async () => {
|
|
178
|
-
const msg = await message.channel.messages.fetch(id);
|
|
179
|
-
await msg.delete();
|
|
180
|
-
this.client.cache.messages.delete(message.id);
|
|
181
|
-
})();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (message.content && this.client.modules.options.message) {
|
|
185
|
-
const commands = this.client.commands.message;
|
|
186
|
-
const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
|
|
187
|
-
let commandName = null,
|
|
188
|
-
cmd,
|
|
189
|
-
commandAlias = null,
|
|
190
|
-
commandPrefix = null;
|
|
191
|
-
commands.map((command) => {
|
|
192
|
-
let prefix = null;
|
|
193
|
-
if (command.regex && message.content.match(command.regex)) {
|
|
194
|
-
const [match] = message.content.match(command.regex) || [null];
|
|
195
|
-
if (match) commandName = command.name;
|
|
196
|
-
}
|
|
197
|
-
const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
|
|
198
|
-
prefixes.map((p) => {
|
|
199
|
-
if (message.content.startsWith(p)) prefix = p;
|
|
200
|
-
});
|
|
201
|
-
cp.map((p) => {
|
|
202
|
-
if (message.content.startsWith(p)) prefix = p;
|
|
203
|
-
});
|
|
204
|
-
if (!prefix) return;
|
|
205
|
-
if (!commandName)
|
|
206
|
-
commandName =
|
|
207
|
-
message.content
|
|
208
|
-
.replace(prefix, '')
|
|
209
|
-
.split(command.separator || / +/)
|
|
210
|
-
.shift()
|
|
211
|
-
?.trim()
|
|
212
|
-
?.toLowerCase() || '';
|
|
213
|
-
if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
|
|
214
|
-
commandAlias = commandName;
|
|
215
|
-
commandName = command.name;
|
|
216
|
-
}
|
|
217
|
-
commandAlias = commandAlias ? commandAlias : commandName;
|
|
218
|
-
commandPrefix = prefix;
|
|
219
|
-
});
|
|
220
|
-
if (!cmd && this.client.modules.options.message.allowMention) {
|
|
221
|
-
if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
222
|
-
commandName = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift()?.toLowerCase() || null;
|
|
223
|
-
commands.map((command) => {
|
|
224
|
-
if (command.aliases?.includes(commandName)) {
|
|
225
|
-
commandName = command.name;
|
|
226
|
-
return (commandAlias = commandName);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
commandPrefix = `<@${this.client.user?.id}>`;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (this.client.commands.message.has(commandName)) {
|
|
233
|
-
if (this.client.modules.options.message?.handleTyping) message.channel.sendTyping();
|
|
234
|
-
cmd = this.client.commands.message.get(commandName);
|
|
235
|
-
}
|
|
236
|
-
if (!commandPrefix || !commandName) return;
|
|
237
|
-
if (!cmd) return await this.client.emit('commandNotFound', message, commandName, filetype);
|
|
238
|
-
await this.client.emit('commandStart', message, cmd);
|
|
239
|
-
const args = await messageArguments(message, cmd, commandPrefix);
|
|
240
|
-
message.util.parsed = {
|
|
241
|
-
alias: commandAlias,
|
|
242
|
-
prefix: commandPrefix,
|
|
243
|
-
args: args.args,
|
|
244
|
-
};
|
|
245
|
-
cmd.util = message.util;
|
|
246
|
-
return await this.exec(cmd, message, args, filetype);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async slashCommandRun(interaction) {
|
|
250
|
-
const filetype = 'SlashCommand';
|
|
251
|
-
interaction.util = new InteractionUtil(this.client, interaction);
|
|
252
|
-
interaction.user = await xernerxUser(interaction, this.client);
|
|
253
|
-
if (await inhibitorValidation(interaction, undefined, undefined, 'pre')) return;
|
|
254
|
-
let cmd = null;
|
|
255
|
-
if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
|
|
256
|
-
if (!cmd) return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
|
|
257
|
-
new Promise(async (resolve) => {
|
|
258
|
-
if (interaction.isAutocomplete()) {
|
|
259
|
-
const focused = interaction.options.getFocused(true);
|
|
260
|
-
const options = interaction.options;
|
|
261
|
-
await cmd.autocomplete(interaction, focused, options);
|
|
262
|
-
} else resolve(true);
|
|
263
|
-
})
|
|
264
|
-
.then(async () => {
|
|
265
|
-
await this.client.emit('commandStart', interaction);
|
|
266
|
-
const args = await interactionArguments(interaction, cmd);
|
|
267
|
-
interaction.util.parsed = {
|
|
268
|
-
alias: [interaction.commandName, args.group || null, args.subcommand || null].filter((x) => x).join(' '),
|
|
269
|
-
args: args.args,
|
|
270
|
-
};
|
|
271
|
-
cmd.util = interaction.util;
|
|
272
|
-
return await this.exec(cmd, interaction, args, filetype);
|
|
273
|
-
})
|
|
274
|
-
.catch((error) => this.client.emit('commandError', interaction, error, cmd));
|
|
275
|
-
}
|
|
276
|
-
async contextCommandRun(interaction) {
|
|
277
|
-
const filetype = 'ContextCommand';
|
|
278
|
-
interaction.util = new InteractionUtil(this.client, interaction);
|
|
279
|
-
interaction.user = await xernerxUser(interaction, this.client);
|
|
280
|
-
if (await inhibitorValidation(interaction, undefined, undefined, 'pre')) return;
|
|
281
|
-
let cmd;
|
|
282
|
-
if (this.client.commands.context.has(interaction.commandName)) cmd = this.client.commands.context.get(interaction.commandName);
|
|
283
|
-
if (!cmd) return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
|
|
284
|
-
await this.client.emit('commandStart', interaction);
|
|
285
|
-
const args = await interactionArguments(interaction, cmd);
|
|
286
|
-
interaction.util.parsed = {
|
|
287
|
-
alias: interaction.commandName,
|
|
288
|
-
args: args,
|
|
289
|
-
};
|
|
290
|
-
cmd.util = interaction.util;
|
|
291
|
-
return await this.exec(cmd, interaction, args, filetype);
|
|
292
|
-
}
|
|
293
|
-
async exec(cmd, event, args, type) {
|
|
294
|
-
try {
|
|
295
|
-
if (cmd.filetype == 'SlashCommand' && (cmd?.defer?.reply ?? this.client.modules.options.slash?.defer?.reply)) {
|
|
296
|
-
await event.deferReply({
|
|
297
|
-
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.slash?.defer?.ephemeral || false,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
if (cmd.filetype == 'ContextCommand' && (cmd?.defer?.reply ?? this.client.modules.options.context?.defer?.reply)) {
|
|
301
|
-
await event.deferReply({
|
|
302
|
-
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.context?.defer?.ephemeral || false,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
if (await commandValidation(event, cmd)) return;
|
|
306
|
-
if (await inhibitorValidation(event, args, cmd, 'check')) return;
|
|
307
|
-
if (cmd.conditions && (await cmd.conditions(event, args))) return;
|
|
308
|
-
await cmd.exec(event, args);
|
|
309
|
-
await inhibitorValidation(event, args, cmd, 'post');
|
|
310
|
-
return await this.client.emit('commandFinish', event, cmd);
|
|
311
|
-
} catch (error) {
|
|
312
|
-
new XernerxLog(this.client).error(`An error occurred executing ${Style.log(cmd.name, { color: Style.TextColor.Blue })}`, error);
|
|
313
|
-
return await this.client.emit('commandError', event, error, cmd);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
_checks(command) {
|
|
317
|
-
if ((command.strict?.voice || command.ignore?.voice) && !this.client.options.intents.has('GuildVoiceStates'))
|
|
318
|
-
new XernerxLog(this.client).warn(
|
|
319
|
-
`${Style.log(command.id, { color: Style.TextColor.Blue })} options ${Style.log(`Xernerx${command.filetype}#strict#voice`, {
|
|
320
|
-
color: Style.BackgroundColor.Grey,
|
|
321
|
-
})} or ${Style.log(`Xernerx${command.filetype}#ignore#voice`, {
|
|
322
|
-
color: Style.BackgroundColor.Grey,
|
|
323
|
-
})} will misbehave due to missing the ${Style.log('GuildVoiceStates', { color: Style.TextColor.Yellow })} intent.`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
import { EventHandlerOptions } from '../types/interfaces.js';
|
|
4
|
-
import Handler from './Handler.js';
|
|
5
|
-
export default class EventHandler extends Handler {
|
|
6
|
-
readonly readyTimestamp: number;
|
|
7
|
-
constructor(client: XernerxClient);
|
|
8
|
-
loadEvents(options: EventHandlerOptions): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { Style } from 'dumfunctions';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
import Handler from './Handler.js';
|
|
6
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
7
|
-
export default class EventHandler extends Handler {
|
|
8
|
-
constructor(client) {
|
|
9
|
-
super(client);
|
|
10
|
-
this.readyTimestamp = Number(Date.now());
|
|
11
|
-
}
|
|
12
|
-
async loadEvents(options) {
|
|
13
|
-
const events = [];
|
|
14
|
-
options = z
|
|
15
|
-
.object({
|
|
16
|
-
directory: z.string(),
|
|
17
|
-
})
|
|
18
|
-
.parse(options);
|
|
19
|
-
this.client.modules.options.events = options;
|
|
20
|
-
const files = await this.readdir(options.directory, 'Events');
|
|
21
|
-
for (const file of files) {
|
|
22
|
-
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
23
|
-
const event = await this.load(filepath, 'Event');
|
|
24
|
-
this.emit(event);
|
|
25
|
-
events.push(event.id);
|
|
26
|
-
}
|
|
27
|
-
new XernerxLog(this.client).info(
|
|
28
|
-
`Loaded ${Style.log(String(this.client.events.size), { color: Style.TextColor.Cyan })} Events: ${events.map((event) => Style.log(event, { color: Style.TextColor.LightYellow })).join(', ')}`
|
|
29
|
-
);
|
|
30
|
-
process.on('unhandledRejection', async (error) => {
|
|
31
|
-
if (this.client.settings.ceaseless) new XernerxLog(this.client).error('An uncaught error happpened, this is triggered from the ceaseless setting.', error);
|
|
32
|
-
const data = {
|
|
33
|
-
channel: null,
|
|
34
|
-
message: null,
|
|
35
|
-
user: null,
|
|
36
|
-
url: error.url || null,
|
|
37
|
-
stack: error.stack || error,
|
|
38
|
-
};
|
|
39
|
-
if (error.url) {
|
|
40
|
-
await error.url.match(/(channels|messages|servers|users)\/\d{10,100}/gim)?.map(async (identifier) => {
|
|
41
|
-
const [type, id] = identifier.split('/');
|
|
42
|
-
console.log(type, id);
|
|
43
|
-
switch (type) {
|
|
44
|
-
case 'channels':
|
|
45
|
-
return (data.channel = (await this.client.channels.fetch(id)) || id);
|
|
46
|
-
case 'messages' && data.channel:
|
|
47
|
-
return (data.message = (await data.channel.messages.cache.get(id)) || id);
|
|
48
|
-
case 'users':
|
|
49
|
-
return (data.user = (await this.client.users.fetch(id)) || id);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
this.client.emit('processError', this.client, data);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxExtensionBuilder from 'xernerx-extension-builder';
|
|
3
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
4
|
-
import Handler from './Handler.js';
|
|
5
|
-
export default class ExtensionHandler extends Handler {
|
|
6
|
-
readonly readyTimestamp: number;
|
|
7
|
-
constructor(client: XernerxClient);
|
|
8
|
-
loadExtensions(...extensions: Array<XernerxExtensionBuilder>): void;
|
|
9
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import { Style } from 'dumfunctions';
|
|
3
|
-
import Handler from './Handler.js';
|
|
4
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
5
|
-
export default class ExtensionHandler extends Handler {
|
|
6
|
-
constructor(client) {
|
|
7
|
-
super(client);
|
|
8
|
-
this.readyTimestamp = Number(Date.now());
|
|
9
|
-
}
|
|
10
|
-
loadExtensions(...extensions) {
|
|
11
|
-
const active = extensions.map((extension) => {
|
|
12
|
-
try {
|
|
13
|
-
if (extension.main) extension.main(this.client);
|
|
14
|
-
if (extension.defer) {
|
|
15
|
-
this.client.on('ready', (client) => extension.defer(client));
|
|
16
|
-
}
|
|
17
|
-
return extension.name;
|
|
18
|
-
} catch (error) {
|
|
19
|
-
return new XernerxLog(this.client).error(`An error occurred while loading ${Style.log(extension.name, { color: Style.TextColor.Red })}`, error);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
new XernerxLog(this.client).info(
|
|
23
|
-
`Loaded ${Style.log(String(extensions.length), { color: Style.TextColor.Cyan })} Extensions: ${active
|
|
24
|
-
.filter((e) => e)
|
|
25
|
-
.map((event) => Style.log(event, { color: Style.TextColor.LightYellow }))
|
|
26
|
-
.join(', ')}`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
import MessageCommandBuilder from '../build/XernerxMessageCommand.js';
|
|
4
|
-
import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
|
|
5
|
-
import XernerxContextCommand from '../build/XernerxContextCommand.js';
|
|
6
|
-
import { filetype } from '../types/types.js';
|
|
7
|
-
import { XernerxClientEvents, XernerxEvent, XernerxInhibitor } from '../main.js';
|
|
8
|
-
export default class Handler {
|
|
9
|
-
readonly client: XernerxClient<{
|
|
10
|
-
[index: string]: any;
|
|
11
|
-
[index: number]: any;
|
|
12
|
-
}>;
|
|
13
|
-
readonly files: Array<MessageCommandBuilder | XernerxSlashCommand | XernerxContextCommand>;
|
|
14
|
-
constructor(client: XernerxClient);
|
|
15
|
-
readdir(dir: string, type: string): Promise<string[]>;
|
|
16
|
-
load(filepath: string, type: filetype): Promise<any>;
|
|
17
|
-
/**
|
|
18
|
-
* Emits a file that has been loaded into the handler.
|
|
19
|
-
* @param file - The file to emit.
|
|
20
|
-
*/
|
|
21
|
-
emit<
|
|
22
|
-
File extends
|
|
23
|
-
| {
|
|
24
|
-
name: string;
|
|
25
|
-
filetype: 'MessageCommand' | 'SlashCommand' | 'ContextCommand';
|
|
26
|
-
run: Function;
|
|
27
|
-
}
|
|
28
|
-
| XernerxInhibitor
|
|
29
|
-
| XernerxEvent<keyof XernerxClientEvents>,
|
|
30
|
-
>(file: File): Promise<void>;
|
|
31
|
-
}
|
package/dist/handlers/Handler.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import load from '../functions/load.js';
|
|
5
|
-
import { Style, XernerxLog } from '../main.js';
|
|
6
|
-
export default class Handler {
|
|
7
|
-
client;
|
|
8
|
-
files;
|
|
9
|
-
constructor(client) {
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.files = [];
|
|
12
|
-
}
|
|
13
|
-
async readdir(dir, type) {
|
|
14
|
-
try {
|
|
15
|
-
return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
|
|
16
|
-
} catch (error) {
|
|
17
|
-
new XernerxLog(this.client).error(`Cannot load ${type.toLowerCase()}, there is no such directory ${Style.log(dir, { color: Style.BackgroundColor.Grey })}.`);
|
|
18
|
-
}
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
async load(filepath, type) {
|
|
22
|
-
const file = await load(this.client, filepath, type);
|
|
23
|
-
if (this.client.settings.debug) new XernerxLog(this.client).debug(`Loaded ${Style.log(type, { color: Style.TextColor.Blue })} ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
|
|
24
|
-
this.files.push(file);
|
|
25
|
-
return file;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Emits a file that has been loaded into the handler.
|
|
29
|
-
* @param file - The file to emit.
|
|
30
|
-
*/
|
|
31
|
-
async emit(file) {
|
|
32
|
-
if (!file?.filetype) return;
|
|
33
|
-
if (file.filetype === 'Inhibitor') return;
|
|
34
|
-
if (file.filetype === 'Event' && file.emitter) {
|
|
35
|
-
if (file.emitter === 'client') {
|
|
36
|
-
if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to client event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
|
|
37
|
-
this.client[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
|
|
38
|
-
} else if (file.emitter === 'process') {
|
|
39
|
-
if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to process event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
|
|
40
|
-
process[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
|
|
41
|
-
} else if (file.emitter === 'rest') {
|
|
42
|
-
if (this.client.settings.debug) new XernerxLog(this.client).debug(`Listening to rest event ${Style.log(file.name, { color: Style.TextColor.Yellow })}`);
|
|
43
|
-
this.client.rest[file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
|
|
44
|
-
} else {
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
this.client[file.emitter][file.once ? 'once' : 'on'](file.name, (...args) => file.run(...args));
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
this.client.on(file.name, (...args) => file.run(...args));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
import Handler from './Handler.js';
|
|
4
|
-
import { InhibitorHandlerOptions } from '../types/interfaces.js';
|
|
5
|
-
export default class InhibitorHandler extends Handler {
|
|
6
|
-
readonly readyTimestamp: number;
|
|
7
|
-
constructor(client: XernerxClient);
|
|
8
|
-
loadInhibitors(options: InhibitorHandlerOptions): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { Style } from 'dumfunctions';
|
|
5
|
-
import Handler from './Handler.js';
|
|
6
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
7
|
-
export default class InhibitorHandler extends Handler {
|
|
8
|
-
constructor(client) {
|
|
9
|
-
super(client);
|
|
10
|
-
this.readyTimestamp = Number(Date.now());
|
|
11
|
-
}
|
|
12
|
-
async loadInhibitors(options) {
|
|
13
|
-
const inhibitors = [];
|
|
14
|
-
options = z
|
|
15
|
-
.object({
|
|
16
|
-
directory: z.string(),
|
|
17
|
-
})
|
|
18
|
-
.parse(options);
|
|
19
|
-
this.client.modules.options.inhibitors = options;
|
|
20
|
-
const files = await this.readdir(options.directory, 'Inhibitors');
|
|
21
|
-
for (const file of files) {
|
|
22
|
-
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
23
|
-
const inhibitor = await this.load(filepath, 'Inhibitor');
|
|
24
|
-
this.emit(inhibitor);
|
|
25
|
-
inhibitors.push(inhibitor.id);
|
|
26
|
-
}
|
|
27
|
-
new XernerxLog(this.client).info(
|
|
28
|
-
`Loaded ${Style.log(String(this.client.inhibitors.size), { color: Style.TextColor.Cyan })} Inhibitors: ${inhibitors
|
|
29
|
-
.map((inhibitor) => Style.log(inhibitor, { color: Style.TextColor.LightYellow }))
|
|
30
|
-
.join(', ')}`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import dbl from 'dbl-sdk';
|
|
3
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
4
|
-
import Handler from './Handler.js';
|
|
5
|
-
export default class IntegrationHandler extends Handler {
|
|
6
|
-
readonly readyTimestamp: number;
|
|
7
|
-
readonly dbl: dbl;
|
|
8
|
-
constructor(client: XernerxClient);
|
|
9
|
-
loadIntegrations(options?: DBLOptions): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
interface DBLOptions {
|
|
12
|
-
post?: boolean;
|
|
13
|
-
votes?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import dbl from 'dbl-sdk';
|
|
3
|
-
import XernerxLog from '../tools/XernerxLog.js';
|
|
4
|
-
import Handler from './Handler.js';
|
|
5
|
-
export default class IntegrationHandler extends Handler {
|
|
6
|
-
constructor(client) {
|
|
7
|
-
super(client);
|
|
8
|
-
this.dbl = new dbl(client, client.config);
|
|
9
|
-
this.readyTimestamp = Number(Date.now());
|
|
10
|
-
}
|
|
11
|
-
async loadIntegrations(options = { votes: true }) {
|
|
12
|
-
this.client.once('ready', async (client) => {
|
|
13
|
-
this.client.dbl.validate = (user) => this.dbl.validate(user);
|
|
14
|
-
if (options.post) {
|
|
15
|
-
this.dbl.post();
|
|
16
|
-
}
|
|
17
|
-
if (options.votes) {
|
|
18
|
-
this.dbl.votes();
|
|
19
|
-
this.client.on('dbl-sync', (client, responses) => {
|
|
20
|
-
this.client.stats.voteCount = responses.voteCount;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
new XernerxLog(this.client).info(`Successfully syncing with top.gg.`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
|
|
3
|
-
import XernerxContextCommand from '../build/XernerxContextCommand.js';
|
|
4
|
-
import MessageCommandBuilder from '../build/XernerxMessageCommand.js';
|
|
5
|
-
import { XernerxMessage, XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from '../types/extenders.js';
|
|
6
|
-
import { MessageCommandArguments } from '../types/interfaces.js';
|
|
7
|
-
import { XernerxInteraction } from '../types/types.js';
|
|
8
|
-
export declare function messageArguments(message: XernerxMessage, command: MessageCommandBuilder, prefix: string): Promise<MessageCommandArguments>;
|
|
9
|
-
export declare function interactionArguments(
|
|
10
|
-
interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction> | any,
|
|
11
|
-
command: XernerxContextCommand | XernerxSlashCommand
|
|
12
|
-
): Promise<any>;
|