xernerx 4.0.4 → 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 (64) 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/dist/types/interfaces.d.ts +1 -1
  11. package/dist/validators/commandValidation.js +2 -1
  12. package/package.json +1 -1
  13. package/dist/build copy/ContextCommandBuilder.d.ts +0 -37
  14. package/dist/build copy/ContextCommandBuilder.js +0 -88
  15. package/dist/build copy/EventBuilder.d.ts +0 -21
  16. package/dist/build copy/EventBuilder.js +0 -34
  17. package/dist/build copy/InhibitorBuilder.d.ts +0 -19
  18. package/dist/build copy/InhibitorBuilder.js +0 -27
  19. package/dist/build copy/MessageCommandBuilder.d.ts +0 -39
  20. package/dist/build copy/MessageCommandBuilder.js +0 -90
  21. package/dist/build copy/SlashCommandBuilder.d.ts +0 -41
  22. package/dist/build copy/SlashCommandBuilder.js +0 -122
  23. package/dist/client/DBLClient.d.ts +0 -8
  24. package/dist/client/DBLClient.js +0 -15
  25. package/dist/client/Top.ggClient.d.ts +0 -1
  26. package/dist/client/Top.ggClient.js +0 -1
  27. package/dist/events/messageCreate.d.ts +0 -1
  28. package/dist/events/messageCreate.js +0 -1
  29. package/dist/functions/AsyncFunctions.d.ts +0 -1
  30. package/dist/functions/AsyncFunctions.js +0 -1
  31. package/dist/functions/getPermissionBitField.d.ts +0 -2
  32. package/dist/functions/getPermissionBitField.js +0 -17
  33. package/dist/functions/hasVoted.d.ts +0 -1
  34. package/dist/functions/hasVoted.js +0 -1
  35. package/dist/functions/voted.d.ts +0 -1
  36. package/dist/functions/voted.js +0 -1
  37. package/dist/models/CommandArguments.d.ts +0 -17
  38. package/dist/models/CommandArguments.js +0 -101
  39. package/dist/models/Events.d.ts +0 -24
  40. package/dist/models/Events.js +0 -297
  41. package/dist/models/Extensions.d.ts +0 -7
  42. package/dist/models/Extensions.js +0 -23
  43. package/dist/models/XernerxUser.d.ts +0 -2
  44. package/dist/models/XernerxUser.js +0 -9
  45. package/dist/tools/classes.d.ts +0 -6
  46. package/dist/tools/classes.js +0 -10
  47. package/dist/tools/loggers.d.ts +0 -4
  48. package/dist/tools/loggers.js +0 -4
  49. package/dist/tools/package.d.ts +0 -42
  50. package/dist/tools/package.js +0 -41
  51. package/dist/types/enums.d.ts +0 -44
  52. package/dist/types/enums.js +0 -35
  53. package/dist/types/options.d.ts +0 -254
  54. package/dist/types/options.js +0 -1
  55. package/dist/utils/CommandUtil.d.ts +0 -58
  56. package/dist/utils/CommandUtil.js +0 -232
  57. package/dist/utils/InteractionArguments.d.ts +0 -1
  58. package/dist/utils/InteractionArguments.js +0 -1
  59. package/dist/validators/CommandValidations.d.ts +0 -12
  60. package/dist/validators/CommandValidations.js +0 -166
  61. package/dist/validators/commands.d.ts +0 -4
  62. package/dist/validators/commands.js +0 -25
  63. /package/dist/validators/{InhibitorValidations.d.ts → inhibitorValidations.d.ts} +0 -0
  64. /package/dist/validators/{InhibitorValidations.js → inhibitorValidations.js} +0 -0
@@ -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
- }
@@ -1,8 +0,0 @@
1
- import { DBL } from 'dbl-sdk';
2
- import XernerxClient from './XernerxClient.js';
3
- import { DBLOptions } from '../types/interfaces.js';
4
- export default class DBLClient {
5
- dbl: DBL | null;
6
- readonly client: XernerxClient;
7
- constructor(client: any, options: DBLOptions);
8
- }
@@ -1,15 +0,0 @@
1
- import { DBL, hasVoted } from 'dbl-sdk';
2
- import XernerxLog from '../tools/XernerxLog.js';
3
- export default class DBLClient {
4
- dbl;
5
- client;
6
- constructor(client, options) {
7
- this.dbl = null;
8
- this.client = client;
9
- this.client.once('ready', (client) => {
10
- this.dbl = new DBL(client, options);
11
- new XernerxLog(this.client).info(`Loaded webhooks!`);
12
- this.client.util.hasVoted = (userId) => hasVoted(userId, client.user.id, this.dbl?.options.topgg?.token, 'top.gg');
13
- });
14
- }
15
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { PermissionNames } from '../types/types.js';
2
- export default function getPermissionBitField(...permissions: Array<PermissionNames | bigint>): bigint;
@@ -1,17 +0,0 @@
1
- import { PermissionFlagsBits } from 'discord.js';
2
- export default function getPermissionBitField(...permissions) {
3
- const bigIntPerms = [0n];
4
- permissions.map((permission) => {
5
- if (typeof permission === 'string') {
6
- permission =
7
- PermissionFlagsBits[
8
- permission
9
- .split(/ +/)
10
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
11
- .join('')
12
- ];
13
- }
14
- bigIntPerms.push(permission);
15
- });
16
- return bigIntPerms.reduce((a, b) => (a += b));
17
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
2
- import { XernerxInteraction, XernerxMessage } from '../types/types.js';
3
- export declare class InteractionArguments {
4
- interaction: XernerxInteraction;
5
- constructor(interaction: XernerxInteraction);
6
- group(): string | undefined;
7
- subcommand(): string | undefined;
8
- arguments(): Record<string, object>;
9
- }
10
- interface Flag {
11
- flags: Record<string, string | boolean>;
12
- }
13
- interface Argument {
14
- [index: string]: string | number | null;
15
- }
16
- export declare function messageArguments(message: XernerxMessage, command: MessageCommandBuilder): Promise<import('discord.js').Message<boolean> | Flag | Argument | undefined>;
17
- export {};
@@ -1,101 +0,0 @@
1
- export class InteractionArguments {
2
- interaction;
3
- constructor(interaction) {
4
- this.interaction = interaction;
5
- }
6
- group() {
7
- return this.interaction?.options?._group;
8
- }
9
- subcommand() {
10
- return this.interaction?.options?._subcommand;
11
- }
12
- arguments() {
13
- const options = {};
14
- if (this.interaction?.options?._hoistedOptions) {
15
- for (const option of this.interaction.options._hoistedOptions) {
16
- options[option.name] = option.channel || option.user || option.role || option.value;
17
- }
18
- }
19
- return options;
20
- }
21
- }
22
- export async function messageArguments(message, command) {
23
- let args = { flags: {} },
24
- separator = command.separator || ' ',
25
- i = 0;
26
- if (!command.args) return;
27
- command.args
28
- .filter((c) => c.type == 'flag')
29
- .map((flag) => {
30
- args = args;
31
- for (const flg of message.content.matchAll(flag.match)) {
32
- if (flag.match == flg) {
33
- message.content = message.content.replace(flag.match, '');
34
- args.flags[flag.name] = true;
35
- }
36
- }
37
- if (!args.flags[flag.name]) args.flags[flag.name] = false;
38
- });
39
- for (const argument of command.args) {
40
- args = args;
41
- let content = message.content
42
- .split(/ +/)
43
- .slice(1)
44
- .join(separator)
45
- .replace(new RegExp(`${separator}${separator}+`, 'g'), separator)
46
- .split(separator)
47
- .slice(i);
48
- if (content.join(separator) != '' && argument.type !== 'flag') {
49
- if (argument?.content?.includes(content[0])) {
50
- args[argument.name] = content[0];
51
- } else if (argument.type == 'string') {
52
- args[argument.name] = content[0];
53
- } else if (argument.type == 'number') {
54
- args[argument.name] = parseInt(content[0]);
55
- } else if (argument.type == 'boolean') {
56
- if (content[0]?.toLowerCase() != 'true' && content[0]?.toLowerCase() != 'false') content[0] = null;
57
- args[argument.name] = content[0];
58
- } else if (argument.type == 'user') {
59
- let user = message.client.users.cache.find((u) => u?.username?.toLowerCase()?.includes(content[0])) || null;
60
- try {
61
- user = (await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, ''))) || null;
62
- } catch (e) {
63
- user = null;
64
- }
65
- args[argument.name] = user;
66
- } else if (argument.type == 'role') {
67
- let role = message.guild?.roles.cache.find((r) => r?.name?.toLowerCase()?.includes(content[0])) || null;
68
- try {
69
- role = (await message.guild?.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, ''))) || null;
70
- } catch (e) {
71
- role = null;
72
- }
73
- args[argument.name] = role;
74
- } else if (argument.type == 'member') {
75
- let member = message.guild?.members.cache.find((m) => m?.nickname?.toLowerCase()?.includes(content[0]) || m?.user?.username?.toLowerCase()?.includes(content[0])) || null;
76
- try {
77
- member = (await message.guild?.members.fetch(member?.id || content[0].replace(/<@!?|>/g, ''))) || null;
78
- } catch (e) {
79
- member = null;
80
- }
81
- args[argument.name] = member;
82
- } else if (argument.type == 'channel') {
83
- let channel = message.guild?.channels.cache.find((c) => c?.name?.toLowerCase()?.includes(content[0]));
84
- try {
85
- channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, ''));
86
- } catch (e) {
87
- channel = null;
88
- }
89
- args[argument.name] = channel;
90
- } else if (argument.type == 'rest') {
91
- args[argument.name] = content.join(separator);
92
- break;
93
- } else if (argument.prompt) {
94
- if (argument.prompt.reply) return message.util?.reply(argument.prompt.reply);
95
- else if (argument.prompt.send) return message.channel.send(argument.prompt.send);
96
- } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
97
- i++;
98
- } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
99
- }
100
- return args;
101
- }
@@ -1,24 +0,0 @@
1
- import XernerxClient from '../client/XernerxClient.js';
2
- export declare class MessageCommandEvents {
3
- client: XernerxClient;
4
- constructor(client: XernerxClient);
5
- messageCreate(): void;
6
- messageUpdate(): void;
7
- messageDelete(): void;
8
- }
9
- export declare class SlashCommandEvents {
10
- client: XernerxClient;
11
- constructor(client: XernerxClient);
12
- slashCreate(): void;
13
- }
14
- export declare class ContextCommandEvents {
15
- client: XernerxClient;
16
- constructor(client: XernerxClient);
17
- contextCreate(): void;
18
- }
19
- export declare class CommandsDeploy {
20
- private client;
21
- constructor(client: XernerxClient);
22
- deploy(): void;
23
- private put;
24
- }
@@ -1,297 +0,0 @@
1
- import { GatewayVersion, InteractionType, REST, Routes } from 'discord.js';
2
- import { InteractionCommandUtil, MessageCommandUtil } from '../utils/CommandUtil.js';
3
- import { InteractionArguments, messageArguments } from './CommandArguments.js';
4
- import commandValidation from '../validators/CommandValidations.js';
5
- import { Style } from 'dumfunctions';
6
- import { InhibitorValidation } from '../validators/InhibitorValidations.js';
7
- import User from './XernerxUser.js';
8
- export class MessageCommandEvents {
9
- client;
10
- constructor(client) {
11
- this.client = client;
12
- }
13
- messageCreate() {
14
- this.client.on('messageCreate', async (message) => {
15
- if (!message.author.bot) {
16
- let command = undefined,
17
- px = undefined;
18
- message.author = await User(message);
19
- message.util = new MessageCommandUtil(this.client, message);
20
- const commands = this.client.commands.message;
21
- commands
22
- .filter((c) => !c.regex)
23
- .map(async (cmd) => {
24
- if (cmd.prefix) {
25
- cmd.prefix.map((prefix) => {
26
- if (message.content.startsWith(prefix)) {
27
- command = message.content.replace(prefix, '').split(/ +/).shift();
28
- px = prefix;
29
- }
30
- });
31
- }
32
- if (this.client.handlerOptions.message?.prefix) {
33
- const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
34
- prefix.map((prefix) => {
35
- if (message.content.startsWith(prefix)) {
36
- command = message.content.replace(prefix, '').split(/ +/).shift();
37
- px = prefix;
38
- }
39
- });
40
- }
41
- if (this.client.handlerOptions.message?.allowMention) {
42
- if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
43
- command = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
44
- px = 'MentionPrefix';
45
- }
46
- }
47
- const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
48
- if (
49
- (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
50
- (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
51
- ) {
52
- try {
53
- if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
54
- const inhibitor = new InhibitorValidation(this.client, message, command);
55
- if (commandValidation(message, cmd, this.client)) return;
56
- if (await inhibitor.inhibit()) return;
57
- if (cmd.conditions && (await cmd.conditions(message, await messageArguments(message, cmd)))) return;
58
- await cmd.exec(message, await messageArguments(message, cmd));
59
- this.client.emit('commandRun', message, cmd);
60
- } catch (error) {
61
- return this.client.emit('commandError', message, error, cmd);
62
- }
63
- }
64
- });
65
- }
66
- });
67
- }
68
- messageUpdate() {
69
- this.client.on('messageUpdate', async (old, message) => {
70
- message = message;
71
- if (!message.author?.bot) {
72
- let command = undefined,
73
- px = undefined;
74
- message.author = await User(message);
75
- message.util = new MessageCommandUtil(this.client, message);
76
- const commands = this.client.commands.message;
77
- commands
78
- .filter((c) => !c.regex)
79
- .map(async (cmd) => {
80
- if (cmd.prefix) {
81
- cmd.prefix.map((prefix) => {
82
- if (message?.content?.startsWith(prefix)) {
83
- command = message.content.replace(prefix, '').split(/ +/).shift();
84
- px = prefix;
85
- }
86
- });
87
- }
88
- if (this.client.handlerOptions.message?.prefix) {
89
- const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
90
- prefix.map((prefix) => {
91
- if (message?.content?.startsWith(prefix)) {
92
- command = message.content.replace(prefix, '').split(/ +/).shift();
93
- px = prefix;
94
- }
95
- });
96
- }
97
- if (this.client.handlerOptions.message?.allowMention) {
98
- if (message.mentions.users.has(this.client.user?.id || '') || message.mentions.repliedUser?.id === this.client.user?.id) {
99
- command = message?.content?.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
100
- px = 'MentionPrefix';
101
- }
102
- }
103
- const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
104
- if (
105
- (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
106
- (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
107
- ) {
108
- try {
109
- if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
110
- message = message;
111
- const inhibitor = new InhibitorValidation(this.client, message, command);
112
- if (commandValidation(message, cmd, this.client)) return;
113
- if (await inhibitor.inhibit()) return;
114
- if (cmd.conditions && (await cmd.conditions(message, await messageArguments(message, cmd)))) return;
115
- await cmd.exec(message, await messageArguments(message, cmd));
116
- this.client.emit('commandRun', message, cmd);
117
- } catch (error) {
118
- return this.client.emit('commandError', message, error, cmd);
119
- }
120
- }
121
- });
122
- }
123
- });
124
- }
125
- messageDelete() {
126
- this.client.on('messageDelete', async (message) => {
127
- if (this.client.cache.messages.has(message.id) && this.client.handlerOptions.message?.handleDeletes) {
128
- try {
129
- if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
130
- message.author = await User(message);
131
- const msg = this.client.cache.messages.get(message.id);
132
- const response = await message.channel.messages.fetch(msg?.response);
133
- await response.delete();
134
- } catch (error) {
135
- this.client.emit('commandError', message, error, null);
136
- }
137
- }
138
- });
139
- }
140
- }
141
- export class SlashCommandEvents {
142
- client;
143
- constructor(client) {
144
- this.client = client;
145
- }
146
- slashCreate() {
147
- this.client.on('interactionCreate', async (interaction) => {
148
- interaction.util = new InteractionCommandUtil(this.client, interaction);
149
- interaction.author = await User(interaction);
150
- if (interaction.type === InteractionType.ApplicationCommand) {
151
- if (this.client.commands.slash.has(interaction.commandName)) {
152
- let command = this.client.commands.slash.get(interaction.commandName);
153
- const argumentsInfo = new InteractionArguments(interaction);
154
- try {
155
- const inhibitor = new InhibitorValidation(this.client, interaction, command);
156
- if (await inhibitor.inhibit()) return;
157
- if (commandValidation(interaction, command, this.client)) return;
158
- if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
159
- await interaction.deferReply({
160
- ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
161
- fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply,
162
- });
163
- if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
164
- await interaction.deferReply({
165
- ephemeral: command.defer?.ephemeral,
166
- fetchReply: command.defer?.fetchReply,
167
- });
168
- if (
169
- command.conditions &&
170
- (await command.conditions(interaction, {
171
- group: argumentsInfo.group(),
172
- subcommand: argumentsInfo.subcommand(),
173
- args: await argumentsInfo.arguments(),
174
- }))
175
- )
176
- return;
177
- await command.exec(interaction, {
178
- group: argumentsInfo.group(),
179
- subcommand: argumentsInfo.subcommand(),
180
- args: await argumentsInfo.arguments(),
181
- });
182
- this.client.emit('commandRun', interaction, command);
183
- } catch (error) {
184
- this.client.emit('commandError', interaction, error, command);
185
- }
186
- }
187
- }
188
- });
189
- }
190
- }
191
- export class ContextCommandEvents {
192
- client;
193
- constructor(client) {
194
- this.client = client;
195
- }
196
- contextCreate() {
197
- this.client.on('interactionCreate', async (interaction) => {
198
- interaction.util = new InteractionCommandUtil(this.client, interaction);
199
- interaction.author = await User(interaction);
200
- if (interaction.type === InteractionType.ApplicationCommand) {
201
- if (this.client.commands.context.has(interaction.commandName)) {
202
- let command = this.client.commands.context.get(interaction.commandName);
203
- try {
204
- const inhibitor = new InhibitorValidation(this.client, interaction, command);
205
- if (commandValidation(interaction, command, this.client)) return;
206
- if (await inhibitor.inhibit()) return;
207
- if (command.conditions && (await command.conditions(interaction))) return;
208
- if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
209
- await interaction.deferReply({
210
- ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
211
- fetchReply: this.client.handlerOptions.context?.defer?.fetchReply,
212
- });
213
- if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
214
- await interaction.deferReply({
215
- ephemeral: command.defer?.ephemeral,
216
- fetchReply: command.defer?.fetchReply,
217
- });
218
- let args = {};
219
- if (command.type === 3) args = await interaction.channel.messages.fetch(interaction.targetId);
220
- if (command.type === 2) args = await this.client.users.fetch(interaction.targetId);
221
- await command.exec(interaction, args);
222
- this.client.emit('commandRun', interaction, command);
223
- } catch (error) {
224
- this.client.emit('commandError', interaction, error, command);
225
- }
226
- }
227
- }
228
- });
229
- }
230
- }
231
- export class CommandsDeploy {
232
- client;
233
- constructor(client) {
234
- this.client = client;
235
- }
236
- deploy() {
237
- this.client.once('ready', async (client) => {
238
- const slashCommands = [],
239
- contextCommands = [];
240
- this.client.commands.context.map((command) => (command.data ? contextCommands.push(command.data.toJSON()) : null));
241
- this.client.commands.slash.map((command) => (command.data ? slashCommands.push(command.data.toJSON()) : null));
242
- try {
243
- const global = {
244
- slash: this.client.handlerOptions.slash?.global,
245
- context: this.client.handlerOptions.context?.global,
246
- };
247
- const guild = {
248
- slash: this.client.handlerOptions.slash?.guildId,
249
- context: this.client.handlerOptions.context?.guildId,
250
- };
251
- if (!guild.slash && !guild.context) return;
252
- if (global.slash && global.context) {
253
- if (guild.slash !== guild.context)
254
- console.info(
255
- Style.log(
256
- `Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${
257
- (await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name
258
- }!`,
259
- { color: Style.TextColor.Red }
260
- )
261
- );
262
- this.put('global', guild.slash, [...contextCommands, ...slashCommands]);
263
- this.put('guild', guild.slash, []);
264
- }
265
- if (global.slash && global.context === false) {
266
- this.put('global', guild.slash, slashCommands);
267
- }
268
- if (global.slash === false && global.context) {
269
- this.put('global', guild.context, contextCommands);
270
- }
271
- if (global.slash === false && global.context === false) {
272
- this.put('guild', guild.slash, [...contextCommands, ...slashCommands]);
273
- }
274
- if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
275
- console.info(
276
- Style.log(
277
- `Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? 'globally' : 'locally'} and ${contextCommands.length} context commands ${
278
- global.context ? 'globally' : 'locally'
279
- }.`,
280
- { color: Style.TextColor.Purple }
281
- )
282
- );
283
- } catch (error) {
284
- console.error(
285
- Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
286
- color: Style.BackgroundColor.Red,
287
- })
288
- );
289
- }
290
- });
291
- }
292
- put(type, guild, body) {
293
- const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
294
- if (type === 'guild') rest.put(Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
295
- else rest.put(Routes.applicationCommands(this.client.user?.id), { body });
296
- }
297
- }
@@ -1,7 +0,0 @@
1
- import XernerxExtensionBuilder from 'xernerx-extension-builder';
2
- import XernerxClient from '../client/XernerxClient.js';
3
- export default class Extensions {
4
- client: XernerxClient;
5
- constructor(client: XernerxClient);
6
- load(extensions: Array<XernerxExtensionBuilder>, logging?: boolean): Promise<void>;
7
- }