xernerx 4.0.5 → 4.1.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.
Files changed (62) hide show
  1. package/dist/build/SlashCommandBuilder.d.ts +1 -0
  2. package/dist/build/SlashCommandBuilder.js +1 -0
  3. package/dist/functions/deploy.js +5 -1
  4. package/dist/handlers/CommandHandler.js +13 -5
  5. package/dist/handlers/EventHandler.js +1 -1
  6. package/dist/handlers/ExtensionHandler.js +1 -1
  7. package/dist/handlers/InhibitorHandler.js +1 -1
  8. package/dist/main.d.ts +3 -2
  9. package/dist/main.js +3 -2
  10. package/package.json +1 -1
  11. package/dist/build copy/ContextCommandBuilder.d.ts +0 -37
  12. package/dist/build copy/ContextCommandBuilder.js +0 -88
  13. package/dist/build copy/EventBuilder.d.ts +0 -21
  14. package/dist/build copy/EventBuilder.js +0 -34
  15. package/dist/build copy/InhibitorBuilder.d.ts +0 -19
  16. package/dist/build copy/InhibitorBuilder.js +0 -27
  17. package/dist/build copy/MessageCommandBuilder.d.ts +0 -39
  18. package/dist/build copy/MessageCommandBuilder.js +0 -90
  19. package/dist/build copy/SlashCommandBuilder.d.ts +0 -41
  20. package/dist/build copy/SlashCommandBuilder.js +0 -122
  21. package/dist/client/DBLClient.d.ts +0 -8
  22. package/dist/client/DBLClient.js +0 -15
  23. package/dist/client/Top.ggClient.d.ts +0 -1
  24. package/dist/client/Top.ggClient.js +0 -1
  25. package/dist/events/messageCreate.d.ts +0 -1
  26. package/dist/events/messageCreate.js +0 -1
  27. package/dist/functions/AsyncFunctions.d.ts +0 -1
  28. package/dist/functions/AsyncFunctions.js +0 -1
  29. package/dist/functions/getPermissionBitField.d.ts +0 -2
  30. package/dist/functions/getPermissionBitField.js +0 -17
  31. package/dist/functions/hasVoted.d.ts +0 -1
  32. package/dist/functions/hasVoted.js +0 -1
  33. package/dist/functions/voted.d.ts +0 -1
  34. package/dist/functions/voted.js +0 -1
  35. package/dist/models/CommandArguments.d.ts +0 -17
  36. package/dist/models/CommandArguments.js +0 -101
  37. package/dist/models/Events.d.ts +0 -24
  38. package/dist/models/Events.js +0 -297
  39. package/dist/models/Extensions.d.ts +0 -7
  40. package/dist/models/Extensions.js +0 -23
  41. package/dist/models/XernerxUser.d.ts +0 -2
  42. package/dist/models/XernerxUser.js +0 -9
  43. package/dist/tools/classes.d.ts +0 -6
  44. package/dist/tools/classes.js +0 -10
  45. package/dist/tools/loggers.d.ts +0 -4
  46. package/dist/tools/loggers.js +0 -4
  47. package/dist/tools/package.d.ts +0 -42
  48. package/dist/tools/package.js +0 -41
  49. package/dist/types/enums.d.ts +0 -44
  50. package/dist/types/enums.js +0 -35
  51. package/dist/types/options.d.ts +0 -254
  52. package/dist/types/options.js +0 -1
  53. package/dist/utils/CommandUtil.d.ts +0 -58
  54. package/dist/utils/CommandUtil.js +0 -232
  55. package/dist/utils/InteractionArguments.d.ts +0 -1
  56. package/dist/utils/InteractionArguments.js +0 -1
  57. package/dist/validators/CommandValidations.d.ts +0 -12
  58. package/dist/validators/CommandValidations.js +0 -166
  59. package/dist/validators/commands.d.ts +0 -4
  60. package/dist/validators/commands.js +0 -25
  61. /package/dist/validators/{InhibitorValidations.d.ts → inhibitorValidations.d.ts} +0 -0
  62. /package/dist/validators/{InhibitorValidations.js → inhibitorValidations.js} +0 -0
@@ -42,6 +42,7 @@ export default class SlashCommandBuilder {
42
42
  | undefined;
43
43
  client: typeof XernerxClient;
44
44
  constructor(id: string, options: SlashCommandOptions);
45
+ autocomplete<T>(interaction: XernerxSlashInteraction, focused: T, options: Array<T>): Promise<void>;
45
46
  conditions(interaction: XernerxSlashInteraction, args: SlashCommandArguments): Promise<void>;
46
47
  exec(interaction: XernerxSlashInteraction, args: SlashCommandArguments): Promise<void>;
47
48
  private addArguments;
@@ -82,6 +82,7 @@ export default class SlashCommandBuilder {
82
82
  this.defer = options.defer;
83
83
  this.client = XernerxClient;
84
84
  }
85
+ async autocomplete(interaction, focused, options) {}
85
86
  async conditions(interaction, args) {}
86
87
  async exec(interaction, args) {}
87
88
  addArguments(command, args) {
@@ -16,7 +16,11 @@ export default function deploy(client, type) {
16
16
  } catch (error) {
17
17
  new XernerxLog(client).error(`An error occurred while deploying the interaction commands!`, error);
18
18
  } finally {
19
- new XernerxLog(client).info(`Deployed All Commands ${client.settings.global ? 'globally' : 'locally'}.`);
19
+ new XernerxLog(client).info(
20
+ `Deployed ${[client.commands.message.size, client.commands.slash.size, client.commands.context.size].reduce((a, b) => (a += b))} Commands ${
21
+ client.settings.global ? 'globally' : 'locally'
22
+ }.`
23
+ );
20
24
  }
21
25
  }
22
26
  commands.retries++;
@@ -42,7 +42,7 @@ export default class CommandHandler extends Handler {
42
42
  const filePath = `${path.resolve(options.directory)}\\${file}`;
43
43
  this.load(filePath, 'MessageCommand');
44
44
  }
45
- new XernerxLog(this.client).info(`Loaded Message Commands.`);
45
+ new XernerxLog(this.client).info(`Loaded ${files.length} Message Commands.`);
46
46
  this.emit({
47
47
  name: 'messageCreate',
48
48
  fileType: 'MessageCommand',
@@ -90,7 +90,7 @@ export default class CommandHandler extends Handler {
90
90
  const filePath = `${path.resolve(options.directory)}\\${file}`;
91
91
  this.load(filePath, 'SlashCommand');
92
92
  }
93
- new XernerxLog(this.client).info(`Loaded Slash Commands.`);
93
+ new XernerxLog(this.client).info(`Loaded ${files.length} Slash Commands.`);
94
94
  deploy(this.client, 'slash');
95
95
  this.emit({
96
96
  name: 'interactionCreate',
@@ -126,7 +126,7 @@ export default class CommandHandler extends Handler {
126
126
  const filePath = `${path.resolve(options.directory)}\\${file}`;
127
127
  this.load(filePath, 'ContextCommand');
128
128
  }
129
- new XernerxLog(this.client).info(`Loaded Context Commands.`);
129
+ new XernerxLog(this.client).info(`Loaded ${files.length} Context Commands.`);
130
130
  deploy(this.client, 'context');
131
131
  this.emit({
132
132
  name: 'interactionCreate',
@@ -199,11 +199,19 @@ export default class CommandHandler extends Handler {
199
199
  async slashCommandRun(interaction) {
200
200
  interaction.util = new InteractionUtil(this.client, interaction);
201
201
  interaction.user = await xernerxUser(interaction, this.client);
202
- let cmd;
202
+ let cmd = null;
203
203
  if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
204
204
  if (await inhibitorValidation(interaction, cmd)) return;
205
205
  if (!cmd) return this.client.emit('commandNotFound', interaction);
206
- this.exec(cmd, interaction, await interactionArguments(interaction, cmd), 'SlashCommand');
206
+ new Promise(async (resolve) => {
207
+ if (interaction.isAutocomplete()) {
208
+ const focused = interaction.options.getFocused(true);
209
+ const options = interaction.options;
210
+ await cmd.autocomplete(interaction, focused, options);
211
+ } else resolve(true);
212
+ })
213
+ .then(async () => await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), 'SlashCommand'))
214
+ .catch((error) => this.client.emit('commandError', interaction, error, cmd.filetype));
207
215
  }
208
216
  async contextCommandRun(interaction) {
209
217
  interaction.util = new InteractionUtil(this.client, interaction);
@@ -19,6 +19,6 @@ export default class EventHandler extends Handler {
19
19
  const data = await this.load(filePath, 'Event');
20
20
  this.emit(data);
21
21
  }
22
- new XernerxLog(this.client).info(`Loaded Events.`);
22
+ new XernerxLog(this.client).info(`Loaded ${this.client.events.size} Events.`);
23
23
  }
24
24
  }
@@ -14,6 +14,6 @@ export default class ExtensionHandler extends Handler {
14
14
  new XernerxLog(this.client).error(`An error occurred while loading ${extension.name}`, error);
15
15
  }
16
16
  });
17
- new XernerxLog(this.client).info(`Loaded Extensions: ${active.filter((e) => e).join(', ')}`);
17
+ new XernerxLog(this.client).info(`Loaded ${extensions.length} Extensions: ${active.filter((e) => e).join(', ')}`);
18
18
  }
19
19
  }
@@ -19,6 +19,6 @@ export default class InhibitorHandler extends Handler {
19
19
  const data = await this.load(filePath, 'Inhibitor');
20
20
  this.emit(data);
21
21
  }
22
- new XernerxLog(this.client).info(`Loaded Inhibitors.`);
22
+ new XernerxLog(this.client).info(`Loaded ${this.client.inhibitors.size} Inhibitors.`);
23
23
  }
24
24
  }
package/dist/main.d.ts CHANGED
@@ -4,10 +4,11 @@ import SlashCommandBuilder from './build/SlashCommandBuilder.js';
4
4
  import ContextCommandBuilder from './build/ContextCommandBuilder.js';
5
5
  import EventBuilder from './build/EventBuilder.js';
6
6
  import InhibitorBuilder from './build/InhibitorBuilder.js';
7
+ import XernerxLog from './tools/XernerxLog.js';
7
8
  export default XernerxClient;
8
9
  export * from 'discord.js';
9
10
  export * from 'dumfunctions';
10
11
  import ExtensionBuilder from 'xernerx-extension-builder';
11
12
  import Discord from 'discord.js';
12
- declare const version = '4.0.5';
13
- export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder, Discord, version };
13
+ declare const version = '4.1.0';
14
+ export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder, Discord, version, XernerxLog };
package/dist/main.js CHANGED
@@ -4,10 +4,11 @@ import SlashCommandBuilder from './build/SlashCommandBuilder.js';
4
4
  import ContextCommandBuilder from './build/ContextCommandBuilder.js';
5
5
  import EventBuilder from './build/EventBuilder.js';
6
6
  import InhibitorBuilder from './build/InhibitorBuilder.js';
7
+ import XernerxLog from './tools/XernerxLog.js';
7
8
  export default XernerxClient;
8
9
  export * from 'discord.js';
9
10
  export * from 'dumfunctions';
10
11
  import ExtensionBuilder from 'xernerx-extension-builder';
11
12
  import Discord from 'discord.js';
12
- const version = '4.0.5';
13
- export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder, Discord, version };
13
+ const version = '4.1.0';
14
+ export { XernerxClient, MessageCommandBuilder, SlashCommandBuilder, ContextCommandBuilder, EventBuilder, InhibitorBuilder, ExtensionBuilder, Discord, version, XernerxLog };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xernerx",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "A bot framework for discord.js.",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",
@@ -1,37 +0,0 @@
1
- import { ContextMenuCommandBuilder, Interaction } from 'discord.js';
2
- import { ContextCommandOptions } from '../types/options.js';
3
- import XernerxClient from '../client/XernerxClient.js';
4
- /**
5
- * @description The command builder for context commands.
6
- * @param {String} id - The unique ID of the command.
7
- * @param {ContextCommandOptions} options - The command options.
8
- */
9
- export default class ContextCommandBuilder {
10
- id: string;
11
- data: ContextMenuCommandBuilder;
12
- name: any;
13
- type: any;
14
- description: any;
15
- info: any;
16
- category: any;
17
- channelType: any;
18
- cooldown: any;
19
- ignore: any;
20
- strict: any;
21
- permissions: any;
22
- defer: any;
23
- client: typeof XernerxClient;
24
- constructor(id: string, options: ContextCommandOptions);
25
- /**
26
- * @param {Interaction} interaction - The Discord interaction event data.
27
- * @description make any preconditions here.
28
- * TODO - update description
29
- */
30
- conditions(interaction: Interaction, args: any): Promise<void>;
31
- /**
32
- * @param {Interaction} interaction - The Discord interaction event data.
33
- * @description Make your custom command here.
34
- * TODO - update description
35
- */
36
- exec(interaction: Interaction, args: any): Promise<void>;
37
- }
@@ -1,88 +0,0 @@
1
- import { ContextMenuCommandBuilder } from 'discord.js';
2
- import { z } from 'zod';
3
- import XernerxClient from '../client/XernerxClient.js';
4
- /**
5
- * @description The command builder for context commands.
6
- * @param {String} id - The unique ID of the command.
7
- * @param {ContextCommandOptions} options - The command options.
8
- */
9
- export default class ContextCommandBuilder {
10
- id;
11
- data;
12
- name;
13
- type;
14
- description;
15
- info;
16
- category;
17
- channelType;
18
- cooldown;
19
- ignore;
20
- strict;
21
- permissions;
22
- defer;
23
- client;
24
- constructor(id, options) {
25
- this.id = id;
26
- this.data = new ContextMenuCommandBuilder();
27
- if (options.name) this.data.setName(options.name);
28
- if (options.type) this.data.setType(options.type);
29
- if (options.permissions?.users) this.data.setDefaultMemberPermissions(options.permissions?.users);
30
- if (options.permissions?.dm === false) this.data.setDMPermission(options.permissions?.dm);
31
- if (options.nameLocalizations) this.data.setNameLocalizations(options.nameLocalizations);
32
- z.object({
33
- description: z.string(),
34
- info: z.string(),
35
- category: z.string(),
36
- channelType: z.array(z.number()).or(z.number()),
37
- cooldown: z.number(),
38
- ignore: z.object({
39
- owner: z.boolean(),
40
- users: z.array(z.string()),
41
- channels: z.array(z.string()),
42
- guilds: z.array(z.string()),
43
- }),
44
- strict: z.object({
45
- owner: z.boolean(),
46
- users: z.array(z.string()),
47
- channels: z.array(z.string()),
48
- guilds: z.array(z.string()),
49
- }),
50
- permissions: z.object({
51
- client: z.array(z.string()),
52
- users: z.array(z.string()),
53
- dm: z.boolean(),
54
- }),
55
- defer: z.object({
56
- reply: z.boolean(),
57
- ephemeral: z.boolean(),
58
- fetch: z.boolean(),
59
- }),
60
- })
61
- .deepPartial()
62
- .parse(options);
63
- this.name = options.name;
64
- this.type = options.type;
65
- this.description = options.description;
66
- this.info = options.info;
67
- this.category = options.category;
68
- this.channelType = options.channelType;
69
- this.cooldown = options.cooldown;
70
- this.ignore = options.ignore;
71
- this.strict = options.strict;
72
- this.permissions = options.permissions;
73
- this.defer = options.defer;
74
- this.client = XernerxClient;
75
- }
76
- /**
77
- * @param {Interaction} interaction - The Discord interaction event data.
78
- * @description make any preconditions here.
79
- * TODO - update description
80
- */
81
- async conditions(interaction, args) {}
82
- /**
83
- * @param {Interaction} interaction - The Discord interaction event data.
84
- * @description Make your custom command here.
85
- * TODO - update description
86
- */
87
- async exec(interaction, args) {}
88
- }
@@ -1,21 +0,0 @@
1
- import XernerxClient from '../client/XernerxClient.js';
2
- import { EventOptions } from '../types/options.js';
3
- /**
4
- * @description - The event builder for events.
5
- * @param {String} id - The unique ID of the event.
6
- * @param {EventOptions} options - The event options.
7
- */
8
- export default class EventBuilder {
9
- id: string;
10
- name: any;
11
- emitter: any;
12
- type: any;
13
- once: any;
14
- client: typeof XernerxClient;
15
- constructor(id: string, options: EventOptions);
16
- /**
17
- * @description run your custom event here.
18
- * TODO - update description
19
- */
20
- run(): Promise<void>;
21
- }
@@ -1,34 +0,0 @@
1
- import { z } from 'zod';
2
- import XernerxClient from '../client/XernerxClient.js';
3
- /**
4
- * @description - The event builder for events.
5
- * @param {String} id - The unique ID of the event.
6
- * @param {EventOptions} options - The event options.
7
- */
8
- export default class EventBuilder {
9
- id;
10
- name;
11
- emitter;
12
- type;
13
- once;
14
- client;
15
- constructor(id, options) {
16
- this.id = id;
17
- z.object({
18
- name: z.string(),
19
- emitter: z.string().optional(),
20
- type: z.string().optional(),
21
- once: z.boolean().optional(),
22
- }).parse(options);
23
- this.name = options.name;
24
- this.emitter = options.emitter || 'client';
25
- this.type = options.type || 'discord';
26
- this.once = options.once || false;
27
- this.client = XernerxClient;
28
- }
29
- /**
30
- * @description run your custom event here.
31
- * TODO - update description
32
- */
33
- async run() {}
34
- }
@@ -1,19 +0,0 @@
1
- import XernerxClient from '../client/XernerxClient.js';
2
- import { InhibitorOptions, MessageArgumentOptions, SlashArgumentOptions } from '../types/options.js';
3
- import { XernerxInteraction, XernerxMessage } from '../types/types.js';
4
- /**
5
- * @description - The inhibitor builder for inhibitors.
6
- * @param {String} id - The unique ID of the inhibitor.
7
- * @param {InhibitorOptions} options - The inhibitor options.
8
- */
9
- export default class InhibitorBuilder {
10
- id: string;
11
- name: any;
12
- type: any;
13
- client: typeof XernerxClient;
14
- constructor(id: string, options: InhibitorOptions);
15
- /**
16
- * TODO - update description
17
- */
18
- check(interaction: XernerxInteraction | XernerxMessage, args: SlashArgumentOptions | MessageArgumentOptions): Promise<void>;
19
- }
@@ -1,27 +0,0 @@
1
- import { z } from 'zod';
2
- import XernerxClient from '../client/XernerxClient.js';
3
- /**
4
- * @description - The inhibitor builder for inhibitors.
5
- * @param {String} id - The unique ID of the inhibitor.
6
- * @param {InhibitorOptions} options - The inhibitor options.
7
- */
8
- export default class InhibitorBuilder {
9
- id;
10
- name;
11
- type;
12
- client;
13
- constructor(id, options) {
14
- this.id = id;
15
- z.object({
16
- name: z.string(),
17
- type: z.string(),
18
- }).parse(options);
19
- this.name = options.name;
20
- this.type = options.type;
21
- this.client = XernerxClient;
22
- }
23
- /**
24
- * TODO - update description
25
- */
26
- async check(interaction, args) {}
27
- }
@@ -1,39 +0,0 @@
1
- import { MessageArgumentOptions, MessageCommandOptions } from '../types/options.js';
2
- import XernerxClient from '../client/XernerxClient.js';
3
- import { XernerxMessage } from '../types/types.js';
4
- /**
5
- * @description - The command builder for message commands.
6
- * @param {String} id - The unique ID of the command.
7
- * @param {MessageCommandOptions} options - The command options.
8
- */
9
- export default class MessageCommandBuilder {
10
- id: string;
11
- name: any;
12
- aliases: any;
13
- separator: any;
14
- description: any;
15
- info: any;
16
- category: any;
17
- prefix: any;
18
- regex: any;
19
- channelType: any;
20
- ignore: any;
21
- strict: any;
22
- permissions: any;
23
- cooldown: any;
24
- args: any;
25
- client: typeof XernerxClient;
26
- constructor(id: string, options: MessageCommandOptions);
27
- /**
28
- * @param {Message} message - The Discord message event data.
29
- * @param {object} args - The arguments you created.
30
- * @description make any preconditions here.
31
- */
32
- conditions(message: XernerxMessage, args: MessageArgumentOptions): Promise<void>;
33
- /**
34
- * @param {Message} message - The Discord message event data.
35
- * @param {object} args - The arguments you created.
36
- * @description Make your custom command here.
37
- */
38
- exec(message: XernerxMessage, args: MessageArgumentOptions): Promise<void>;
39
- }
@@ -1,90 +0,0 @@
1
- import { z } from 'zod';
2
- import XernerxClient from '../client/XernerxClient.js';
3
- /**
4
- * @description - The command builder for message commands.
5
- * @param {String} id - The unique ID of the command.
6
- * @param {MessageCommandOptions} options - The command options.
7
- */
8
- export default class MessageCommandBuilder {
9
- id;
10
- name;
11
- aliases;
12
- separator;
13
- description;
14
- info;
15
- category;
16
- prefix;
17
- regex;
18
- channelType;
19
- ignore;
20
- strict;
21
- permissions;
22
- cooldown;
23
- args;
24
- client;
25
- constructor(id, options) {
26
- this.id = id;
27
- z.object({
28
- name: z.string(),
29
- aliases: z.array(z.string()).optional(),
30
- separator: z.string().min(1).max(1).optional(),
31
- description: z.string().optional(),
32
- info: z.string().optional(),
33
- category: z.string().optional(),
34
- prefix: z.array(z.string()).or(z.string()).optional(),
35
- regex: z.unknown(),
36
- channelType: z.array(z.number()).or(z.number()).optional(),
37
- cooldown: z.number().optional(),
38
- ignore: z
39
- .object({
40
- owners: z.boolean().optional(),
41
- users: z.array(z.string()).or(z.string()).optional(),
42
- channels: z.array(z.string()).or(z.string()).optional(),
43
- guilds: z.array(z.string()).or(z.string()).optional(),
44
- })
45
- .optional(),
46
- strict: z
47
- .object({
48
- owners: z.boolean().optional(),
49
- users: z.array(z.string()).or(z.string()).optional(),
50
- channels: z.array(z.string()).or(z.string()).optional(),
51
- guilds: z.array(z.string()).or(z.string()).optional(),
52
- })
53
- .optional(),
54
- permissions: z
55
- .object({
56
- client: z.array(z.string()).optional(),
57
- users: z.array(z.string()).optional(),
58
- dm: z.boolean().optional(),
59
- })
60
- .optional(),
61
- }).parse(options);
62
- this.name = options.name;
63
- this.aliases = options.aliases;
64
- this.separator = options.separator || ' ';
65
- this.description = options.description;
66
- this.info = options.info;
67
- this.category = options.category;
68
- this.prefix = options.prefix ? (Array.isArray(options.prefix) ? options.prefix : [options.prefix]) : [];
69
- this.regex = options.regex;
70
- this.channelType = options.channelType;
71
- this.ignore = options.ignore;
72
- this.strict = options.strict;
73
- this.permissions = options.permissions;
74
- this.cooldown = options.cooldown || 0;
75
- this.args = options.args || [];
76
- this.client = XernerxClient;
77
- }
78
- /**
79
- * @param {Message} message - The Discord message event data.
80
- * @param {object} args - The arguments you created.
81
- * @description make any preconditions here.
82
- */
83
- async conditions(message, args) {}
84
- /**
85
- * @param {Message} message - The Discord message event data.
86
- * @param {object} args - The arguments you created.
87
- * @description Make your custom command here.
88
- */
89
- async exec(message, args) {}
90
- }
@@ -1,41 +0,0 @@
1
- import * as Discord from 'discord.js';
2
- import { Interaction } from 'discord.js';
3
- import { SlashCommandOptions } from '../types/options.js';
4
- import XernerxClient from '../client/XernerxClient.js';
5
- /**
6
- * @description - The command builder for slash commands.
7
- * @param {String} id - The unique ID of the command.
8
- * @param {SlashCommandOptions} options - The command options.
9
- */
10
- export default class SlashCommandBuilder {
11
- id: string;
12
- data: Discord.SlashCommandBuilder;
13
- name: any;
14
- description: any;
15
- info: any;
16
- category: any;
17
- channelType: any;
18
- cooldown: any;
19
- ignore: any;
20
- strict: any;
21
- permissions: any;
22
- args?: object[];
23
- subcommands?: object[];
24
- groups?: object[];
25
- defer: any;
26
- client: typeof XernerxClient;
27
- constructor(id: string, options: SlashCommandOptions);
28
- /**
29
- * TODO - update description
30
- * @param interaction
31
- */
32
- conditions(interaction: Interaction): Promise<void>;
33
- /**
34
- * TODO - update description
35
- * @param interaction
36
- */
37
- exec(interaction: Interaction): Promise<void>;
38
- private addArgs;
39
- private addSubcommands;
40
- private addSubcommandGroups;
41
- }
@@ -1,122 +0,0 @@
1
- import * as Discord from 'discord.js';
2
- import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from 'discord.js';
3
- import { z } from 'zod';
4
- import XernerxError from '../tools/XernerxError.js';
5
- import XernerxClient from '../client/XernerxClient.js';
6
- /**
7
- * @description - The command builder for slash commands.
8
- * @param {String} id - The unique ID of the command.
9
- * @param {SlashCommandOptions} options - The command options.
10
- */
11
- export default class SlashCommandBuilder {
12
- id;
13
- data;
14
- name;
15
- description;
16
- info;
17
- category;
18
- channelType;
19
- cooldown;
20
- ignore;
21
- strict;
22
- permissions;
23
- args;
24
- subcommands;
25
- groups;
26
- defer;
27
- client;
28
- constructor(id, options) {
29
- this.id = id;
30
- this.data = new Discord.SlashCommandBuilder().setName(options.name).setDescription(options.description);
31
- if (options.args && options?.args?.length > 0) {
32
- this.addArgs(this.data, options.args);
33
- }
34
- if (options.subcommands && options?.subcommands?.length > 0) {
35
- this.addSubcommands(this.data, options.subcommands);
36
- }
37
- if (options.groups && options?.groups?.length > 0) {
38
- this.addSubcommandGroups(options.groups);
39
- }
40
- z.object({
41
- description: z.string(),
42
- info: z.string(),
43
- category: z.string(),
44
- channelType: z.array(z.number()).or(z.number()),
45
- cooldown: z.number(),
46
- ignore: z.object({
47
- owner: z.boolean(),
48
- users: z.array(z.string()),
49
- channels: z.array(z.string()),
50
- guilds: z.array(z.string()),
51
- }),
52
- strict: z.object({
53
- owner: z.boolean(),
54
- users: z.array(z.string()),
55
- channels: z.array(z.string()),
56
- guilds: z.array(z.string()),
57
- }),
58
- permissions: z.object({
59
- client: z.array(z.string()),
60
- users: z.array(z.string()),
61
- dm: z.boolean(),
62
- }),
63
- defer: z.object({
64
- reply: z.boolean(),
65
- ephemeral: z.boolean(),
66
- fetch: z.boolean(),
67
- }),
68
- })
69
- .deepPartial()
70
- .parse(options);
71
- this.name = options.name;
72
- this.description = options.description;
73
- this.info = options.info;
74
- this.category = options.category;
75
- this.channelType = options.channelType;
76
- this.cooldown = options.cooldown;
77
- this.ignore = options.ignore;
78
- this.strict = options.strict;
79
- this.permissions = options.permissions;
80
- this.defer = options.defer;
81
- this.client = XernerxClient;
82
- }
83
- /**
84
- * TODO - update description
85
- * @param interaction
86
- */
87
- async conditions(interaction) {}
88
- /**
89
- * TODO - update description
90
- * @param interaction
91
- */
92
- async exec(interaction) {}
93
- addArgs(command, args) {
94
- const types = ['boolean', 'integer', 'number', 'string', 'user', 'role', 'channel', 'mentionable'];
95
- for (const argument of args) {
96
- if (!types.includes(argument.type.toLowerCase())) throw new XernerxError(`Expected one of ${types.join(', ')}, received ${argument.type} instead.`);
97
- let slashArgumentType = `${argument.type.slice(0, 1).toUpperCase()}${argument.type.slice(1).toLowerCase()}`;
98
- command[`add${slashArgumentType}Option`]((option) => {
99
- option
100
- .setName(argument.name)
101
- .setDescription(argument.description)
102
- .setRequired(argument.required || false);
103
- if (argument.choices) option.setChoices(...argument?.choices);
104
- return option;
105
- });
106
- }
107
- }
108
- addSubcommands(method, subcommands) {
109
- for (const subcommand of subcommands) {
110
- let sub = new SlashCommandSubcommandBuilder().setName(subcommand.name).setDescription(subcommand.description);
111
- if (subcommand.args?.length > 0) this.addArgs(sub, subcommand.args);
112
- method.addSubcommand(sub);
113
- }
114
- }
115
- addSubcommandGroups(groups) {
116
- for (const group of groups) {
117
- let subcommandGroup = new SlashCommandSubcommandGroupBuilder().setName(group.name).setDescription(group.description);
118
- if (group.subcommands?.length > 0) this.addSubcommands(subcommandGroup, group.subcommands);
119
- this.data.addSubcommandGroup(subcommandGroup);
120
- }
121
- }
122
- }