xernerx 4.4.4 → 4.4.6

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.
Files changed (42) hide show
  1. package/dist/build/ContextCommandBuilder.d.ts +26 -33
  2. package/dist/build/ContextCommandBuilder.js +38 -38
  3. package/dist/build/EventBuilder.d.ts +3 -1
  4. package/dist/build/EventBuilder.js +1 -1
  5. package/dist/build/InhibitorBuilder.d.ts +5 -3
  6. package/dist/build/InhibitorBuilder.js +1 -1
  7. package/dist/build/MessageCommandBuilder.d.ts +24 -28
  8. package/dist/build/MessageCommandBuilder.js +33 -33
  9. package/dist/build/SlashCommandBuilder.d.ts +29 -34
  10. package/dist/build/SlashCommandBuilder.js +47 -47
  11. package/dist/client/XernerxClient.d.ts +21 -29
  12. package/dist/client/XernerxClient.js +32 -32
  13. package/dist/client/XernerxShardClient.js +3 -5
  14. package/dist/functions/deploy.js +15 -12
  15. package/dist/functions/load.js +2 -1
  16. package/dist/functions/reload.js +11 -8
  17. package/dist/functions/sendWebhook.js +2 -1
  18. package/dist/functions/setPresence.d.ts +1 -1
  19. package/dist/functions/setPresence.js +10 -11
  20. package/dist/handlers/CommandHandler.js +104 -81
  21. package/dist/handlers/EventHandler.js +2 -2
  22. package/dist/handlers/ExtensionHandler.js +4 -2
  23. package/dist/handlers/Handler.js +15 -5
  24. package/dist/handlers/InhibitorHandler.js +2 -2
  25. package/dist/handlers/WebhookHandler.d.ts +3 -1
  26. package/dist/handlers/WebhookHandler.js +5 -8
  27. package/dist/main.d.ts +21 -28
  28. package/dist/main.js +21 -28
  29. package/dist/models/Arguments.d.ts +1 -8
  30. package/dist/models/Arguments.js +72 -51
  31. package/dist/tools/XernerxLog.js +1 -6
  32. package/dist/types/extenders.d.ts +8 -4
  33. package/dist/types/interfaces.d.ts +6 -12
  34. package/dist/types/types.d.ts +5 -173
  35. package/dist/utils/ClientUtil.d.ts +3 -3
  36. package/dist/utils/ClientUtil.js +13 -7
  37. package/dist/utils/InteractionUtil.d.ts +1 -1
  38. package/dist/utils/MessageUtil.d.ts +1 -1
  39. package/dist/utils/MessageUtil.js +8 -4
  40. package/dist/validators/commandValidation.js +28 -18
  41. package/dist/validators/inhibitorValidations.d.ts +1 -14
  42. package/package.json +1 -1
@@ -12,39 +12,39 @@ export default class XernerxClient extends Client {
12
12
  super(discordOptions);
13
13
  this.settings = z
14
14
  .object({
15
- local: z.string().optional(),
16
- global: z.boolean().default(false),
17
- ownerId: z.string().or(z.array(z.string())).default([]),
18
- permissions: z
19
- .object({
20
- client: z.array(z.string()).default([]),
21
- user: z.array(z.string()).default([]),
22
- dm: z.boolean().default(false),
23
- })
24
- .optional(),
25
- ignore: z
26
- .object({
27
- owner: z.boolean().default(false),
28
- users: z.array(z.string()),
29
- channels: z.array(z.string()),
30
- guilds: z.array(z.string()),
31
- })
32
- .optional(),
33
- log: z
34
- .object({
35
- ready: z.boolean().default(false),
36
- info: z.boolean().default(false),
37
- error: z.boolean().default(false),
38
- table: z.array(z.string()).or(z.null()).default(null),
39
- })
40
- .optional(),
41
- cooldown: z
42
- .object({
43
- command: z.number().default(0),
44
- cache: z.number().default(0),
45
- })
46
- .optional(),
15
+ local: z.string().optional(),
16
+ global: z.boolean().default(false),
17
+ ownerId: z.string().or(z.array(z.string())).default([]),
18
+ permissions: z
19
+ .object({
20
+ client: z.array(z.string()).default([]),
21
+ user: z.array(z.string()).default([]),
22
+ dm: z.boolean().default(false),
47
23
  })
24
+ .optional(),
25
+ ignore: z
26
+ .object({
27
+ owner: z.boolean().default(false),
28
+ users: z.array(z.string()),
29
+ channels: z.array(z.string()),
30
+ guilds: z.array(z.string()),
31
+ })
32
+ .optional(),
33
+ log: z
34
+ .object({
35
+ ready: z.boolean().default(false),
36
+ info: z.boolean().default(false),
37
+ error: z.boolean().default(false),
38
+ table: z.array(z.string()).or(z.null()).default(null),
39
+ })
40
+ .optional(),
41
+ cooldown: z
42
+ .object({
43
+ command: z.number().default(0),
44
+ cache: z.number().default(0),
45
+ })
46
+ .optional(),
47
+ })
48
48
  .parse(xernerxOptions);
49
49
  this.config = config || null;
50
50
  this.commands = {
@@ -7,13 +7,13 @@ export default class XernerxShardClient extends ShardingManager {
7
7
  this.user = null;
8
8
  this.on('shardCreate', async (shard) => {
9
9
  shard.on('ready', async () => {
10
- const guilds = await shard.fetchClientValue('guilds.cache');
10
+ const guilds = (await shard.fetchClientValue('guilds.cache'));
11
11
  const guildCount = guilds.length;
12
12
  const userCount = guilds.map((guild) => guild.memberCount).length ? guilds.map((guild) => guild.memberCount).reduce((a, b) => (a += b)) : 0;
13
13
  this.stats.guildCount += Number(guildCount);
14
14
  this.stats.userCount += Number(userCount);
15
15
  this.stats.shardCount++;
16
- this.user = await shard.fetchClientValue('user');
16
+ this.user = (await shard.fetchClientValue('user'));
17
17
  });
18
18
  new XernerxLog({ settings: xernerxOptions }).info(`Launching shard ${shard.id} for ${this.user?.tag}!`);
19
19
  });
@@ -21,9 +21,7 @@ export default class XernerxShardClient extends ShardingManager {
21
21
  const collector = setInterval(() => {
22
22
  const index = shards.size - 1;
23
23
  if (shards.get(index)?.ready) {
24
- new XernerxLog({ settings: xernerxOptions }).info(
25
- `Launched all ${this.stats.shardCount} shards for ${this.user?.tag}, watching ${this.stats.guildCount} guilds, and ${this.stats.userCount} users!`
26
- );
24
+ new XernerxLog({ settings: xernerxOptions }).info(`Launched all ${this.stats.shardCount} shards for ${this.user?.tag}, watching ${this.stats.guildCount} guilds, and ${this.stats.userCount} users!`);
27
25
  clearInterval(collector);
28
26
  }
29
27
  }, 1000);
@@ -5,29 +5,32 @@ const commands = { slash: [], context: [] };
5
5
  export default function deploy(client, type) {
6
6
  client.prependOnceListener('ready', (client) => {
7
7
  commands[type] = client.commands[type].map((command) => command.data.toJSON());
8
- if (!(!!client.modules.options.slash && !!client.modules.options.context && commands.slash.length > 0 && commands.context.length > 0)) return;
8
+ if (!(!!client.modules.options.slash && !!client.modules.options.context && commands.slash.length > 0 && commands.context.length > 0))
9
+ return;
9
10
  try {
10
11
  if (client.settings.global) {
11
12
  put(client, client.settings.global, [...commands.slash, ...commands.context]);
12
13
  put(client, !client.settings.global, []);
13
- } else {
14
+ }
15
+ else {
14
16
  put(client, !client.settings.global, [...commands.slash, ...commands.context]);
15
17
  put(client, client.settings.global, []);
16
18
  }
17
- } catch (error) {
19
+ }
20
+ catch (error) {
18
21
  new XernerxLog(client).error(`An error occurred while deploying the interaction commands!`, error);
19
- } finally {
20
- new XernerxLog(client).info(
21
- `Deployed ${[client.commands.message.size, client.commands.slash.size, client.commands.context.size].reduce((a, b) => (a += b))} Commands ${
22
- client.settings.global ? 'globally' : 'locally'
23
- }.`
24
- );
22
+ }
23
+ finally {
24
+ new XernerxLog(client).info(`Deployed ${[client.commands.message.size, client.commands.slash.size, client.commands.context.size].reduce((a, b) => (a += b))} Commands ${client.settings.global ? 'globally' : 'locally'}.`);
25
25
  }
26
26
  });
27
27
  }
28
28
  function put(client, global, body) {
29
29
  const rest = new REST({ version: GatewayVersion }).setToken(client.token);
30
- if (!global && !client.settings?.local) throw new XernerxError(`No guild ID provided as local guild!`);
31
- if (!global && client.settings?.local) rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
32
- else rest.put(Routes.applicationCommands(client.user?.id), { body });
30
+ if (!global && !client.settings?.local)
31
+ throw new XernerxError(`No guild ID provided as local guild!`);
32
+ if (!global && client.settings?.local)
33
+ rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
34
+ else
35
+ rest.put(Routes.applicationCommands(client.user?.id), { body });
33
36
  }
@@ -7,7 +7,8 @@ export default async function load(client, path, type) {
7
7
  file.client = client;
8
8
  fileSave(client, file, type);
9
9
  return file;
10
- } catch (error) {
10
+ }
11
+ catch (error) {
11
12
  new XernerxLog(client).error(`Couldn't load ${type} ${path.match(/\w*\.js$/gim)?.at(0) || path}`, error);
12
13
  }
13
14
  }
@@ -1,10 +1,10 @@
1
1
  var FileTypes;
2
2
  (function (FileTypes) {
3
- FileTypes['message'] = 'MessageCommand';
4
- FileTypes['slash'] = 'SlashCommand';
5
- FileTypes['context'] = 'ContextCommand';
6
- FileTypes['event'] = 'Event';
7
- FileTypes['inhibitor'] = 'Inhibitor';
3
+ FileTypes["message"] = "MessageCommand";
4
+ FileTypes["slash"] = "SlashCommand";
5
+ FileTypes["context"] = "ContextCommand";
6
+ FileTypes["event"] = "Event";
7
+ FileTypes["inhibitor"] = "Inhibitor";
8
8
  })(FileTypes || (FileTypes = {}));
9
9
  export default function reload(client, type) {
10
10
  const files = [];
@@ -31,9 +31,12 @@ export default function reload(client, type) {
31
31
  filedata.fileType = FileTypes[type];
32
32
  filedata.filePath = file;
33
33
  filedata.client = client;
34
- if (type === 'message' || type === 'slash' || type === 'context') client.commands[type].set(filedata.name, filedata);
35
- if (type === 'event') client.events.set(filedata.name, filedata);
36
- if (type === 'inhibitor') client.inhibitors.set(filedata.name, filedata);
34
+ if (type === 'message' || type === 'slash' || type === 'context')
35
+ client.commands[type].set(filedata.name, filedata);
36
+ if (type === 'event')
37
+ client.events.set(filedata.name, filedata);
38
+ if (type === 'inhibitor')
39
+ client.inhibitors.set(filedata.name, filedata);
37
40
  return filedata;
38
41
  });
39
42
  }
@@ -6,7 +6,8 @@ export default async function sendWebhook(url, body) {
6
6
  },
7
7
  body: JSON.stringify(body),
8
8
  });
9
- if (response.status === 204) return true;
9
+ if (response.status === 204)
10
+ return true;
10
11
  const data = await response.json();
11
12
  return data;
12
13
  }
@@ -1,3 +1,3 @@
1
1
  import XernerxClient from '../main.js';
2
2
  import { PresenceOptions } from '../types/interfaces.js';
3
- export default function setPresence(client: XernerxClient, options: PresenceOptions): import('discord.js').ClientPresence | undefined;
3
+ export default function setPresence(client: XernerxClient, options: PresenceOptions): import("discord.js").ClientPresence | undefined;
@@ -1,15 +1,14 @@
1
1
  export default function setPresence(client, options) {
2
- const presence = () =>
3
- client.user?.setPresence({
4
- activities: [
5
- {
6
- name: options.text,
7
- type: options.type,
8
- url: options.url,
9
- },
10
- ],
11
- status: options.status,
12
- });
2
+ const presence = () => client.user?.setPresence({
3
+ activities: [
4
+ {
5
+ name: options.text,
6
+ type: options.type,
7
+ url: options.url,
8
+ },
9
+ ],
10
+ status: options.status,
11
+ });
13
12
  let response = presence();
14
13
  if (options.interval)
15
14
  setInterval(() => {
@@ -15,26 +15,28 @@ export default class CommandHandler extends Handler {
15
15
  super(client);
16
16
  }
17
17
  loadMessageCommands(options) {
18
- 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!`);
19
- 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!`);
18
+ if (!this.client.options.intents.has(GatewayIntentBits.MessageContent))
19
+ new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
20
+ if (!this.client.options.intents.has(GatewayIntentBits.GuildMessages))
21
+ new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent GuildMessages!`);
20
22
  options = z
21
23
  .object({
22
- directory: z.string(),
23
- prefix: z.string().or(z.array(z.string())),
24
- allowMention: z.boolean().default(false),
25
- cooldown: z.number().default(0),
26
- permissions: z
27
- .object({
28
- user: z.array(z.string()).default([]),
29
- client: z.array(z.string()).default([]),
30
- dm: z.boolean().default(true),
31
- })
32
- .default({}),
33
- handleEdits: z.boolean().default(false),
34
- handleDeletes: z.boolean().default(false),
35
- handleTyping: z.boolean().default(false),
36
- logging: z.boolean().default(false),
24
+ directory: z.string(),
25
+ prefix: z.string().or(z.array(z.string())),
26
+ allowMention: z.boolean().default(false),
27
+ cooldown: z.number().default(0),
28
+ permissions: z
29
+ .object({
30
+ user: z.array(z.string()).default([]),
31
+ client: z.array(z.string()).default([]),
32
+ dm: z.boolean().default(true),
37
33
  })
34
+ .default({}),
35
+ handleEdits: z.boolean().default(false),
36
+ handleDeletes: z.boolean().default(false),
37
+ handleTyping: z.boolean().default(false),
38
+ logging: z.boolean().default(false),
39
+ })
38
40
  .parse(options);
39
41
  this.client.modules.options.message = options;
40
42
  const files = this.readdir(options.directory);
@@ -63,27 +65,28 @@ export default class CommandHandler extends Handler {
63
65
  // return reload(this.client, 'message');
64
66
  // }
65
67
  loadSlashCommands(options) {
66
- if (!this.client.settings.local) new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
68
+ if (!this.client.settings.local)
69
+ new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
67
70
  options = z
68
71
  .object({
69
- directory: z.string(),
70
- cooldown: z.number().default(0),
71
- permissions: z
72
- .object({
73
- user: z.array(z.string()).default([]),
74
- client: z.array(z.string()).default([]),
75
- dm: z.boolean().default(true),
76
- })
77
- .default({}),
78
- logging: z.boolean().default(false),
79
- defer: z
80
- .object({
81
- reply: z.boolean().default(false),
82
- ephemeral: z.boolean().default(false),
83
- fetchReply: z.boolean().default(false),
84
- })
85
- .default({}),
72
+ directory: z.string(),
73
+ cooldown: z.number().default(0),
74
+ permissions: z
75
+ .object({
76
+ user: z.array(z.string()).default([]),
77
+ client: z.array(z.string()).default([]),
78
+ dm: z.boolean().default(true),
79
+ })
80
+ .default({}),
81
+ logging: z.boolean().default(false),
82
+ defer: z
83
+ .object({
84
+ reply: z.boolean().default(false),
85
+ ephemeral: z.boolean().default(false),
86
+ fetchReply: z.boolean().default(false),
86
87
  })
88
+ .default({}),
89
+ })
87
90
  .parse(options);
88
91
  this.client.modules.options.slash = options;
89
92
  const files = this.readdir(options.directory);
@@ -100,27 +103,28 @@ export default class CommandHandler extends Handler {
100
103
  });
101
104
  }
102
105
  loadContextCommands(options) {
103
- if (!this.client.settings.local) new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
106
+ if (!this.client.settings.local)
107
+ new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
104
108
  options = z
105
109
  .object({
106
- directory: z.string(),
107
- cooldown: z.number().default(0),
108
- permissions: z
109
- .object({
110
- user: z.array(z.string()).default([]),
111
- client: z.array(z.string()).default([]),
112
- dm: z.boolean().default(true),
113
- })
114
- .default({}),
115
- logging: z.boolean().default(false),
116
- defer: z
117
- .object({
118
- reply: z.boolean().default(false),
119
- ephemeral: z.boolean().default(false),
120
- fetchReply: z.boolean().default(false),
121
- })
122
- .default({}),
110
+ directory: z.string(),
111
+ cooldown: z.number().default(0),
112
+ permissions: z
113
+ .object({
114
+ user: z.array(z.string()).default([]),
115
+ client: z.array(z.string()).default([]),
116
+ dm: z.boolean().default(true),
123
117
  })
118
+ .default({}),
119
+ logging: z.boolean().default(false),
120
+ defer: z
121
+ .object({
122
+ reply: z.boolean().default(false),
123
+ ephemeral: z.boolean().default(false),
124
+ fetchReply: z.boolean().default(false),
125
+ })
126
+ .default({}),
127
+ })
124
128
  .parse(options);
125
129
  this.client.modules.options.context = options;
126
130
  const files = this.readdir(options.directory);
@@ -138,14 +142,18 @@ export default class CommandHandler extends Handler {
138
142
  }
139
143
  async messageCommandRun(message, message2) {
140
144
  const filetype = 'MessageCommand';
141
- if (message.author.bot) return;
145
+ if (message.author.bot)
146
+ return;
142
147
  message.util = new MessageUtil(this.client, message);
143
148
  message.user = await xernerxUser(message, this.client);
144
- if (typeof message2 === 'object') message = message2;
149
+ if (typeof message2 === 'object')
150
+ message = message2;
145
151
  if (message2 === 'delete') {
146
- if (!this.client.cache.messages.has(message.id)) return;
152
+ if (!this.client.cache.messages.has(message.id))
153
+ return;
147
154
  const id = this.client.cache.messages.get(message.id);
148
- if (!id) return;
155
+ if (!id)
156
+ return;
149
157
  (async () => {
150
158
  const msg = await message.channel.messages.fetch(id);
151
159
  await msg.delete();
@@ -156,24 +164,25 @@ export default class CommandHandler extends Handler {
156
164
  if (message.content && this.client.modules.options.message) {
157
165
  const commands = this.client.commands.message;
158
166
  const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
159
- let commandName = null,
160
- cmd,
161
- commandAlias = null,
162
- commandPrefix = null;
167
+ let commandName = null, cmd, commandAlias = null, commandPrefix = null;
163
168
  commands.map((command) => {
164
169
  let prefix = null;
165
170
  if (command.regex && message.content.match(command.regex)) {
166
171
  const [match] = message.content.match(command.regex) || [null];
167
- if (match) commandName = command.name;
172
+ if (match)
173
+ commandName = command.name;
168
174
  }
169
175
  const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
170
176
  prefixes.map((p) => {
171
- if (message.content.startsWith(p)) prefix = p;
177
+ if (message.content.startsWith(p))
178
+ prefix = p;
172
179
  });
173
180
  cp.map((p) => {
174
- if (message.content.startsWith(p)) prefix = p;
181
+ if (message.content.startsWith(p))
182
+ prefix = p;
175
183
  });
176
- if (!prefix) return;
184
+ if (!prefix)
185
+ return;
177
186
  if (!commandName)
178
187
  commandName =
179
188
  message.content
@@ -194,9 +203,12 @@ export default class CommandHandler extends Handler {
194
203
  commandName = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift()?.toLowerCase() || null;
195
204
  }
196
205
  }
197
- if (this.client.commands.message.has(commandName)) cmd = this.client.commands.message.get(commandName);
198
- if (await inhibitorValidation(message, cmd)) return;
199
- if (!cmd) return this.client.emit('commandNotFound', message, filetype);
206
+ if (this.client.commands.message.has(commandName))
207
+ cmd = this.client.commands.message.get(commandName);
208
+ if (await inhibitorValidation(message, cmd))
209
+ return;
210
+ if (!cmd)
211
+ return this.client.emit('commandNotFound', message, filetype);
200
212
  message.util.parsed = {
201
213
  alias: commandAlias,
202
214
  prefix: commandPrefix,
@@ -210,20 +222,25 @@ export default class CommandHandler extends Handler {
210
222
  interaction.util = new InteractionUtil(this.client, interaction);
211
223
  interaction.user = await xernerxUser(interaction, this.client);
212
224
  let cmd = null;
213
- if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
214
- if (await inhibitorValidation(interaction, cmd)) return;
215
- if (!cmd) return this.client.emit('commandNotFound', interaction);
225
+ if (this.client.commands.slash.has(interaction.commandName))
226
+ cmd = this.client.commands.slash.get(interaction.commandName);
227
+ if (await inhibitorValidation(interaction, cmd))
228
+ return;
229
+ if (!cmd)
230
+ return this.client.emit('commandNotFound', interaction);
216
231
  new Promise(async (resolve) => {
217
232
  if (interaction.isAutocomplete()) {
218
233
  const focused = interaction.options.getFocused(true);
219
234
  const options = interaction.options;
220
235
  await cmd.autocomplete(interaction, focused, options);
221
- } else resolve(true);
236
+ }
237
+ else
238
+ resolve(true);
222
239
  })
223
240
  .then(async () => {
224
- this.client.emit('commandStart', interaction, filetype);
225
- await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
226
- })
241
+ this.client.emit('commandStart', interaction, filetype);
242
+ await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
243
+ })
227
244
  .catch((error) => this.client.emit('commandError', interaction, error, filetype));
228
245
  }
229
246
  async contextCommandRun(interaction) {
@@ -231,19 +248,25 @@ export default class CommandHandler extends Handler {
231
248
  interaction.util = new InteractionUtil(this.client, interaction);
232
249
  interaction.user = await xernerxUser(interaction, this.client);
233
250
  let cmd;
234
- if (this.client.commands.context.has(interaction.commandName)) cmd = this.client.commands.context.get(interaction.commandName);
235
- if (await inhibitorValidation(interaction, cmd)) return;
236
- if (!cmd) return this.client.emit('commandNotFound', interaction, filetype);
251
+ if (this.client.commands.context.has(interaction.commandName))
252
+ cmd = this.client.commands.context.get(interaction.commandName);
253
+ if (await inhibitorValidation(interaction, cmd))
254
+ return;
255
+ if (!cmd)
256
+ return this.client.emit('commandNotFound', interaction, filetype);
237
257
  this.client.emit('commandStart', interaction, filetype);
238
258
  this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
239
259
  }
240
260
  async exec(cmd, event, args, type) {
241
261
  try {
242
- if (await commandValidation(event, cmd)) return;
243
- if (cmd.conditions && (await cmd.conditions(event, args))) return;
262
+ if (await commandValidation(event, cmd))
263
+ return;
264
+ if (cmd.conditions && (await cmd.conditions(event, args)))
265
+ return;
244
266
  cmd.exec(event, args);
245
267
  this.client.emit('commandFinish', event, type);
246
- } catch (error) {
268
+ }
269
+ catch (error) {
247
270
  new XernerxLog(this.client).error(`An error occurred executing ${cmd.name}`, error);
248
271
  this.client.emit('commandError', event, error, type);
249
272
  }
@@ -9,8 +9,8 @@ export default class EventHandler extends Handler {
9
9
  async loadEvents(options) {
10
10
  options = z
11
11
  .object({
12
- directory: z.string(),
13
- })
12
+ directory: z.string(),
13
+ })
14
14
  .parse(options);
15
15
  this.client.modules.options.events = options;
16
16
  const files = this.readdir(options.directory);
@@ -7,12 +7,14 @@ export default class ExtensionHandler extends Handler {
7
7
  loadExtensions(...extensions) {
8
8
  const active = extensions.map((extension) => {
9
9
  try {
10
- if (extension.main) extension.main(this.client);
10
+ if (extension.main)
11
+ extension.main(this.client);
11
12
  if (extension.defer) {
12
13
  this.client.on('ready', (client) => extension.defer(client));
13
14
  }
14
15
  return extension.name;
15
- } catch (error) {
16
+ }
17
+ catch (error) {
16
18
  new XernerxLog(this.client).error(`An error occurred while loading ${extension.name}`, error);
17
19
  }
18
20
  });
@@ -13,7 +13,8 @@ export default class Handler {
13
13
  readdir(dir) {
14
14
  try {
15
15
  return fs.readdirSync(path.resolve(dir)).filter((file) => file.endsWith('.js'));
16
- } catch (error) {
16
+ }
17
+ catch (error) {
17
18
  console.error(error);
18
19
  }
19
20
  return [];
@@ -24,13 +25,22 @@ export default class Handler {
24
25
  return file;
25
26
  }
26
27
  async emit(event) {
27
- if (!event?.fileType) return;
28
+ if (!event?.fileType)
29
+ return;
28
30
  if (event.fileType === 'Event') {
29
- if (event.emitter === 'client') event.once ? this.client.once(event.name, (...args) => event.run(...args)) : this.client.on(event.name, (...args) => event.run(...args));
30
- else if (event.emitter === 'process') event.once ? process.once(event.name, (...args) => event.run(...args)) : process.on(event.name, (...args) => event.run(...args));
31
+ if (event.emitter === 'client')
32
+ event.once
33
+ ? this.client.once(event.name, (...args) => event.run(...args))
34
+ : this.client.on(event.name, (...args) => event.run(...args));
35
+ else if (event.emitter === 'process')
36
+ event.once
37
+ ? process.once(event.name, (...args) => event.run(...args))
38
+ : process.on(event.name, (...args) => event.run(...args));
31
39
  }
32
40
  if (['MessageCommand', 'SlashCommand', 'ContextCommand'].includes(event.fileType)) {
33
- event.once ? this.client.once(event.name, (...args) => event.run(...args)) : this.client.on(event.name, (...args) => event.run(...args));
41
+ event.once
42
+ ? this.client.once(event.name, (...args) => event.run(...args))
43
+ : this.client.on(event.name, (...args) => event.run(...args));
34
44
  }
35
45
  }
36
46
  }
@@ -9,8 +9,8 @@ export default class InhibitorHandler extends Handler {
9
9
  async loadInhibitors(options) {
10
10
  options = z
11
11
  .object({
12
- directory: z.string(),
13
- })
12
+ directory: z.string(),
13
+ })
14
14
  .parse(options);
15
15
  this.client.modules.options.inhibitors = options;
16
16
  const files = this.readdir(options.directory);
@@ -2,6 +2,8 @@ import XernerxClient from '../client/XernerxClient.js';
2
2
  import Handler from './Handler.js';
3
3
  export default class WebhookHandler extends Handler {
4
4
  constructor(client: XernerxClient);
5
- loadWebhooks(options: { token: string }): Promise<void>;
5
+ loadWebhooks(options: {
6
+ token: string;
7
+ }): Promise<void>;
6
8
  private post;
7
9
  }
@@ -11,13 +11,9 @@ export default class WebhookHandler extends Handler {
11
11
  this.post(client.token);
12
12
  }, 60000 * 30);
13
13
  this.client.util.hasVoted = async (userId) => {
14
- return !!(
15
- await (
16
- await fetch(`https://top.gg/api/bots/${this.client.user?.id}/check?userId=${userId}`, {
17
- headers: { Authorization: options.token, 'Content-Type': 'application/json' },
18
- })
19
- ).json()
20
- ).voted;
14
+ return !!(await (await fetch(`https://top.gg/api/bots/${this.client.user?.id}/check?userId=${userId}`, {
15
+ headers: { Authorization: options.token, 'Content-Type': 'application/json' },
16
+ })).json()).voted;
21
17
  };
22
18
  });
23
19
  }
@@ -42,7 +38,8 @@ export default class WebhookHandler extends Handler {
42
38
  shard_count: this.client.stats.shardCount,
43
39
  }),
44
40
  });
45
- } catch (error) {
41
+ }
42
+ catch (error) {
46
43
  new XernerxLog(this.client).error(`An error occurred while posting stats to Top.gg`, error);
47
44
  return this.client.emit('webhookError', this.client, this.client.stats);
48
45
  }