xernerx 3.5.1 → 3.5.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.
Files changed (113) hide show
  1. package/dist/{build → cjs/build}/ContextCommandBuilder.d.ts +36 -28
  2. package/dist/cjs/build/ContextCommandBuilder.js +97 -0
  3. package/dist/cjs/build/EventBuilder.js +44 -0
  4. package/dist/{build → cjs/build}/InhibitorBuilder.d.ts +1 -1
  5. package/dist/cjs/build/InhibitorBuilder.js +37 -0
  6. package/dist/{build → cjs/build}/MessageCommandBuilder.d.ts +23 -17
  7. package/dist/cjs/build/MessageCommandBuilder.js +100 -0
  8. package/dist/{build → cjs/build}/SlashCommandBuilder.d.ts +25 -18
  9. package/dist/cjs/build/SlashCommandBuilder.js +169 -0
  10. package/dist/cjs/client/XernerxClient.js +116 -0
  11. package/dist/{handlers → cjs/handlers}/CommandHandler.js +11 -8
  12. package/dist/{handlers → cjs/handlers}/EventHandler.js +6 -3
  13. package/dist/cjs/handlers/Handler.js +308 -0
  14. package/dist/{handlers → cjs/handlers}/InhibitorHandler.js +6 -3
  15. package/dist/{main.d.ts → cjs/main.d.ts} +15 -1
  16. package/dist/cjs/main.js +112 -0
  17. package/dist/{models → cjs/models}/CommandArguments.d.ts +1 -1
  18. package/dist/{models → cjs/models}/CommandArguments.js +37 -52
  19. package/dist/cjs/models/Events.js +307 -0
  20. package/dist/cjs/models/Extensions.js +26 -0
  21. package/dist/{tools → cjs/tools}/XernerxError.js +4 -1
  22. package/dist/{tools → cjs/tools}/package.js +8 -6
  23. package/dist/cjs/types/enums.d.ts +44 -0
  24. package/dist/cjs/types/enums.js +38 -0
  25. package/dist/cjs/types/interfaces.js +2 -0
  26. package/dist/cjs/types/options.js +2 -0
  27. package/dist/{types → cjs/types}/types.d.ts +36 -9
  28. package/dist/cjs/types/types.js +2 -0
  29. package/dist/{utils → cjs/utils}/ClientUtil.js +73 -84
  30. package/dist/{utils → cjs/utils}/CommandUtil.d.ts +4 -2
  31. package/dist/{utils → cjs/utils}/CommandUtil.js +102 -103
  32. package/dist/{validators → cjs/validators}/CommandValidations.d.ts +6 -1
  33. package/dist/{validators → cjs/validators}/CommandValidations.js +36 -50
  34. package/dist/{validators → cjs/validators}/InhibitorValidations.js +12 -14
  35. package/dist/mjs/build/ContextCommandBuilder.d.ts +68 -0
  36. package/dist/mjs/build/ContextCommandBuilder.js +97 -0
  37. package/dist/mjs/build/EventBuilder.d.ts +21 -0
  38. package/dist/mjs/build/EventBuilder.js +44 -0
  39. package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
  40. package/dist/mjs/build/InhibitorBuilder.js +37 -0
  41. package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
  42. package/dist/mjs/build/MessageCommandBuilder.js +100 -0
  43. package/dist/mjs/build/SlashCommandBuilder.d.ts +65 -0
  44. package/dist/mjs/build/SlashCommandBuilder.js +169 -0
  45. package/dist/mjs/client/XernerxClient.d.ts +28 -0
  46. package/dist/mjs/client/XernerxClient.js +116 -0
  47. package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
  48. package/dist/mjs/handlers/CommandHandler.js +45 -0
  49. package/dist/mjs/handlers/EventHandler.d.ts +13 -0
  50. package/dist/mjs/handlers/EventHandler.js +19 -0
  51. package/dist/mjs/handlers/Handler.d.ts +57 -0
  52. package/dist/mjs/handlers/Handler.js +308 -0
  53. package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
  54. package/dist/mjs/handlers/InhibitorHandler.js +24 -0
  55. package/dist/{main.js → mjs/main.d.ts} +20 -18
  56. package/dist/mjs/main.js +112 -0
  57. package/dist/mjs/models/CommandArguments.d.ts +17 -0
  58. package/dist/mjs/models/CommandArguments.js +106 -0
  59. package/dist/mjs/models/Events.d.ts +24 -0
  60. package/dist/mjs/models/Events.js +307 -0
  61. package/dist/mjs/models/Extensions.d.ts +7 -0
  62. package/dist/mjs/models/Extensions.js +26 -0
  63. package/dist/mjs/tools/XernerxError.d.ts +5 -0
  64. package/dist/mjs/tools/XernerxError.js +11 -0
  65. package/dist/mjs/tools/package.d.ts +49 -0
  66. package/dist/mjs/tools/package.js +50 -0
  67. package/dist/mjs/types/enums.d.ts +44 -0
  68. package/dist/mjs/types/enums.js +38 -0
  69. package/dist/mjs/types/interfaces.d.ts +25 -0
  70. package/dist/mjs/types/interfaces.js +2 -0
  71. package/dist/mjs/types/options.d.ts +241 -0
  72. package/dist/mjs/types/options.js +2 -0
  73. package/dist/mjs/types/types.d.ts +61 -0
  74. package/dist/mjs/types/types.js +2 -0
  75. package/dist/mjs/utils/ClientUtil.d.ts +25 -0
  76. package/dist/mjs/utils/ClientUtil.js +211 -0
  77. package/dist/mjs/utils/CommandUtil.d.ts +58 -0
  78. package/dist/mjs/utils/CommandUtil.js +247 -0
  79. package/dist/mjs/validators/CommandValidations.d.ts +12 -0
  80. package/dist/mjs/validators/CommandValidations.js +169 -0
  81. package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
  82. package/dist/mjs/validators/InhibitorValidations.js +40 -0
  83. package/package.json +10 -15
  84. package/dist/build/ContextCommandBuilder.js +0 -93
  85. package/dist/build/EventBuilder.js +0 -34
  86. package/dist/build/InhibitorBuilder.js +0 -27
  87. package/dist/build/MessageCommandBuilder.js +0 -90
  88. package/dist/build/SlashCommandBuilder.js +0 -125
  89. package/dist/client/XernerxClient.js +0 -101
  90. package/dist/handlers/Handler.js +0 -250
  91. package/dist/main.cjs +0 -2023
  92. package/dist/models/Events.js +0 -294
  93. package/dist/models/Extensions.js +0 -23
  94. package/dist/types/enums.d.ts +0 -35
  95. package/dist/types/enums.js +0 -35
  96. package/dist/types/interfaces.js +0 -1
  97. package/dist/types/options.js +0 -1
  98. package/dist/types/types.js +0 -1
  99. package/dist/validators/Shapes.js +0 -1
  100. /package/dist/{build → cjs/build}/EventBuilder.d.ts +0 -0
  101. /package/dist/{client → cjs/client}/XernerxClient.d.ts +0 -0
  102. /package/dist/{handlers → cjs/handlers}/CommandHandler.d.ts +0 -0
  103. /package/dist/{handlers → cjs/handlers}/EventHandler.d.ts +0 -0
  104. /package/dist/{handlers → cjs/handlers}/Handler.d.ts +0 -0
  105. /package/dist/{handlers → cjs/handlers}/InhibitorHandler.d.ts +0 -0
  106. /package/dist/{models → cjs/models}/Events.d.ts +0 -0
  107. /package/dist/{models → cjs/models}/Extensions.d.ts +0 -0
  108. /package/dist/{tools → cjs/tools}/XernerxError.d.ts +0 -0
  109. /package/dist/{tools → cjs/tools}/package.d.ts +0 -0
  110. /package/dist/{types → cjs/types}/interfaces.d.ts +0 -0
  111. /package/dist/{types → cjs/types}/options.d.ts +0 -0
  112. /package/dist/{utils → cjs/utils}/ClientUtil.d.ts +0 -0
  113. /package/dist/{validators → cjs/validators}/InhibitorValidations.d.ts +0 -0
@@ -1,4 +1,7 @@
1
- export class InteractionArguments {
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.messageArguments = exports.InteractionArguments = void 0;
4
+ class InteractionArguments {
2
5
  interaction;
3
6
  constructor(interaction) {
4
7
  this.interaction = interaction;
@@ -19,23 +22,24 @@ export class InteractionArguments {
19
22
  return options;
20
23
  }
21
24
  }
22
- export async function messageArguments(message, command) {
23
- let args = { flags: {} }, separator = command.separator || ' ', i = 0;
24
- if (!command.args)
25
- return;
25
+ exports.InteractionArguments = InteractionArguments;
26
+ async function messageArguments(message, command) {
27
+ let args = { flags: {} },
28
+ separator = command.separator || ' ',
29
+ i = 0;
30
+ if (!command.args) return;
26
31
  command.args
27
32
  .filter((c) => c.type == 'flag')
28
33
  .map((flag) => {
29
- args = args;
30
- for (const flg of message.content.matchAll(flag.match)) {
31
- if (flag.match == flg) {
32
- message.content = message.content.replace(flag.match, '');
33
- args.flags[flag.name] = true;
34
+ args = args;
35
+ for (const flg of message.content.matchAll(flag.match)) {
36
+ if (flag.match == flg) {
37
+ message.content = message.content.replace(flag.match, '');
38
+ args.flags[flag.name] = true;
39
+ }
34
40
  }
35
- }
36
- if (!args.flags[flag.name])
37
- args.flags[flag.name] = false;
38
- });
41
+ if (!args.flags[flag.name]) args.flags[flag.name] = false;
42
+ });
39
43
  for (const argument of command.args) {
40
44
  args = args;
41
45
  let content = message.content
@@ -48,74 +52,55 @@ export async function messageArguments(message, command) {
48
52
  if (content.join(separator) != '' && argument.type !== 'flag') {
49
53
  if (argument?.content?.includes(content[0])) {
50
54
  args[argument.name] = content[0];
51
- }
52
- else if (argument.type == 'string') {
55
+ } else if (argument.type == 'string') {
53
56
  args[argument.name] = content[0];
54
- }
55
- else if (argument.type == 'number') {
57
+ } else if (argument.type == 'number') {
56
58
  args[argument.name] = parseInt(content[0]);
57
- }
58
- else if (argument.type == 'boolean') {
59
- if (content[0]?.toLowerCase() != 'true' && content[0]?.toLowerCase() != 'false')
60
- content[0] = null;
59
+ } else if (argument.type == 'boolean') {
60
+ if (content[0]?.toLowerCase() != 'true' && content[0]?.toLowerCase() != 'false') content[0] = null;
61
61
  args[argument.name] = content[0];
62
- }
63
- else if (argument.type == 'user') {
62
+ } else if (argument.type == 'user') {
64
63
  let user = message.client.users.cache.find((u) => u?.username?.toLowerCase()?.includes(content[0])) || null;
65
64
  try {
66
65
  user = (await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, ''))) || null;
67
- }
68
- catch (e) {
66
+ } catch (e) {
69
67
  user = null;
70
68
  }
71
69
  args[argument.name] = user;
72
- }
73
- else if (argument.type == 'role') {
70
+ } else if (argument.type == 'role') {
74
71
  let role = message.guild?.roles.cache.find((r) => r?.name?.toLowerCase()?.includes(content[0])) || null;
75
72
  try {
76
73
  role = (await message.guild?.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, ''))) || null;
77
- }
78
- catch (e) {
74
+ } catch (e) {
79
75
  role = null;
80
76
  }
81
77
  args[argument.name] = role;
82
- }
83
- else if (argument.type == 'member') {
78
+ } else if (argument.type == 'member') {
84
79
  let member = message.guild?.members.cache.find((m) => m?.nickname?.toLowerCase()?.includes(content[0]) || m?.user?.username?.toLowerCase()?.includes(content[0])) || null;
85
80
  try {
86
81
  member = (await message.guild?.members.fetch(member?.id || content[0].replace(/<@!?|>/g, ''))) || null;
87
- }
88
- catch (e) {
82
+ } catch (e) {
89
83
  member = null;
90
84
  }
91
85
  args[argument.name] = member;
92
- }
93
- else if (argument.type == 'channel') {
86
+ } else if (argument.type == 'channel') {
94
87
  let channel = message.guild?.channels.cache.find((c) => c?.name?.toLowerCase()?.includes(content[0]));
95
88
  try {
96
89
  channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, ''));
97
- }
98
- catch (e) {
90
+ } catch (e) {
99
91
  channel = null;
100
92
  }
101
93
  args[argument.name] = channel;
102
- }
103
- else if (argument.type == 'rest') {
94
+ } else if (argument.type == 'rest') {
104
95
  args[argument.name] = content.join(separator);
105
96
  break;
106
- }
107
- else if (argument.prompt) {
108
- if (argument.prompt.reply)
109
- return message.util?.reply(argument.prompt.reply);
110
- else if (argument.prompt.send)
111
- return message.channel.send(argument.prompt.send);
112
- }
113
- else
114
- args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
97
+ } else if (argument.prompt) {
98
+ if (argument.prompt.reply) return message.util?.reply(argument.prompt.reply);
99
+ else if (argument.prompt.send) return message.channel.send(argument.prompt.send);
100
+ } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
115
101
  i++;
116
- }
117
- else
118
- args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
102
+ } else args[argument.name] = typeof argument.default == 'function' ? argument.default(message) : argument.default;
119
103
  }
120
104
  return args;
121
105
  }
106
+ exports.messageArguments = messageArguments;
@@ -0,0 +1,307 @@
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ exports.CommandsDeploy = exports.ContextCommandEvents = exports.SlashCommandEvents = exports.MessageCommandEvents = void 0;
9
+ const discord_js_1 = require('discord.js');
10
+ const CommandUtil_js_1 = require('../utils/CommandUtil.js');
11
+ const CommandArguments_js_1 = require('./CommandArguments.js');
12
+ const CommandValidations_js_1 = __importDefault(require('../validators/CommandValidations.js'));
13
+ const dumfunctions_1 = require('dumfunctions');
14
+ const InhibitorValidations_js_1 = require('../validators/InhibitorValidations.js');
15
+ class MessageCommandEvents {
16
+ client;
17
+ constructor(client) {
18
+ this.client = client;
19
+ }
20
+ messageCreate() {
21
+ this.client.on('messageCreate', async (message) => {
22
+ if (!message.author.bot) {
23
+ let command = undefined,
24
+ px = undefined;
25
+ message.author.isOwner = this.client.util.isOwner(message.author.id);
26
+ message.util = new CommandUtil_js_1.MessageCommandUtil(this.client, message);
27
+ const commands = this.client.commands.message;
28
+ commands
29
+ .filter((c) => !c.regex)
30
+ .map(async (cmd) => {
31
+ if (cmd.prefix) {
32
+ cmd.prefix.map((prefix) => {
33
+ if (message.content.startsWith(prefix)) {
34
+ command = message.content.replace(prefix, '').split(/ +/).shift();
35
+ px = prefix;
36
+ }
37
+ });
38
+ }
39
+ if (this.client.handlerOptions.message?.prefix) {
40
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
41
+ prefix.map((prefix) => {
42
+ if (message.content.startsWith(prefix)) {
43
+ command = message.content.replace(prefix, '').split(/ +/).shift();
44
+ px = prefix;
45
+ }
46
+ });
47
+ }
48
+ if (this.client.handlerOptions.message?.allowMention) {
49
+ if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
50
+ command = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
51
+ px = 'MentionPrefix';
52
+ }
53
+ }
54
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
55
+ if (
56
+ (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
57
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
58
+ ) {
59
+ try {
60
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
61
+ const inhibitor = new InhibitorValidations_js_1.InhibitorValidation(this.client, message, command);
62
+ if ((0, CommandValidations_js_1.default)(message, cmd, this.client)) return;
63
+ if (await inhibitor.inhibit()) return;
64
+ if (cmd.conditions && (await cmd.conditions(message, await (0, CommandArguments_js_1.messageArguments)(message, cmd)))) return;
65
+ await cmd.exec(message, await (0, CommandArguments_js_1.messageArguments)(message, cmd));
66
+ this.client.emit('commandRun', message, cmd);
67
+ } catch (error) {
68
+ return this.client.emit('commandError', message, error, cmd);
69
+ }
70
+ }
71
+ });
72
+ }
73
+ });
74
+ }
75
+ messageUpdate() {
76
+ this.client.on('messageUpdate', async (old, message) => {
77
+ message = message;
78
+ if (!message.author?.bot) {
79
+ let command = undefined,
80
+ px = undefined;
81
+ if (message.author) message.author.isOwner = this.client.util.isOwner(message.author.id);
82
+ message.util = new CommandUtil_js_1.MessageCommandUtil(this.client, message);
83
+ const commands = this.client.commands.message;
84
+ commands
85
+ .filter((c) => !c.regex)
86
+ .map(async (cmd) => {
87
+ if (cmd.prefix) {
88
+ cmd.prefix.map((prefix) => {
89
+ if (message?.content?.startsWith(prefix)) {
90
+ command = message.content.replace(prefix, '').split(/ +/).shift();
91
+ px = prefix;
92
+ }
93
+ });
94
+ }
95
+ if (this.client.handlerOptions.message?.prefix) {
96
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
97
+ prefix.map((prefix) => {
98
+ if (message?.content?.startsWith(prefix)) {
99
+ command = message.content.replace(prefix, '').split(/ +/).shift();
100
+ px = prefix;
101
+ }
102
+ });
103
+ }
104
+ if (this.client.handlerOptions.message?.allowMention) {
105
+ if (message.mentions.users.has(this.client.user?.id || '') || message.mentions.repliedUser?.id === this.client.user?.id) {
106
+ command = message?.content?.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
107
+ px = 'MentionPrefix';
108
+ }
109
+ }
110
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
111
+ if (
112
+ (cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
113
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')
114
+ ) {
115
+ try {
116
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
117
+ message = message;
118
+ const inhibitor = new InhibitorValidations_js_1.InhibitorValidation(this.client, message, command);
119
+ if ((0, CommandValidations_js_1.default)(message, cmd, this.client)) return;
120
+ if (await inhibitor.inhibit()) return;
121
+ if (cmd.conditions && (await cmd.conditions(message, await (0, CommandArguments_js_1.messageArguments)(message, cmd)))) return;
122
+ await cmd.exec(message, await (0, CommandArguments_js_1.messageArguments)(message, cmd));
123
+ this.client.emit('commandRun', message, cmd);
124
+ } catch (error) {
125
+ return this.client.emit('commandError', message, error, cmd);
126
+ }
127
+ }
128
+ });
129
+ }
130
+ });
131
+ }
132
+ messageDelete() {
133
+ this.client.on('messageDelete', async (message) => {
134
+ if (this.client.cache.messages.has(message.id) && this.client.handlerOptions.message?.handleDeletes) {
135
+ try {
136
+ if (this.client.handlerOptions.message?.handleTyping) message.channel.sendTyping();
137
+ const msg = this.client.cache.messages.get(message.id);
138
+ const response = await message.channel.messages.fetch(msg?.response);
139
+ await response.delete();
140
+ } catch (error) {
141
+ this.client.emit('commandError', message, error, null);
142
+ }
143
+ }
144
+ });
145
+ }
146
+ }
147
+ exports.MessageCommandEvents = MessageCommandEvents;
148
+ class SlashCommandEvents {
149
+ client;
150
+ constructor(client) {
151
+ this.client = client;
152
+ }
153
+ slashCreate() {
154
+ this.client.on('interactionCreate', async (interaction) => {
155
+ interaction.util = new CommandUtil_js_1.InteractionCommandUtil(this.client, interaction);
156
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
157
+ if (interaction.type === discord_js_1.InteractionType.ApplicationCommand) {
158
+ if (this.client.commands.slash.has(interaction.commandName)) {
159
+ let command = this.client.commands.slash.get(interaction.commandName);
160
+ const argumentsInfo = new CommandArguments_js_1.InteractionArguments(interaction);
161
+ try {
162
+ const inhibitor = new InhibitorValidations_js_1.InhibitorValidation(this.client, interaction, command);
163
+ if (await inhibitor.inhibit()) return;
164
+ if ((0, CommandValidations_js_1.default)(interaction, command, this.client)) return;
165
+ if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
166
+ await interaction.deferReply({
167
+ ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
168
+ fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply,
169
+ });
170
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
171
+ await interaction.deferReply({
172
+ ephemeral: command.defer?.ephemeral,
173
+ fetchReply: command.defer?.fetchReply,
174
+ });
175
+ if (
176
+ command.conditions &&
177
+ (await command.conditions(interaction, {
178
+ group: argumentsInfo.group(),
179
+ subcommand: argumentsInfo.subcommand(),
180
+ args: await argumentsInfo.arguments(),
181
+ }))
182
+ )
183
+ return;
184
+ await command.exec(interaction, {
185
+ group: argumentsInfo.group(),
186
+ subcommand: argumentsInfo.subcommand(),
187
+ args: await argumentsInfo.arguments(),
188
+ });
189
+ this.client.emit('commandRun', interaction, command);
190
+ } catch (error) {
191
+ this.client.emit('commandError', interaction, error, command);
192
+ }
193
+ }
194
+ }
195
+ });
196
+ }
197
+ }
198
+ exports.SlashCommandEvents = SlashCommandEvents;
199
+ class ContextCommandEvents {
200
+ client;
201
+ constructor(client) {
202
+ this.client = client;
203
+ }
204
+ contextCreate() {
205
+ this.client.on('interactionCreate', async (interaction) => {
206
+ interaction.util = new CommandUtil_js_1.InteractionCommandUtil(this.client, interaction);
207
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
208
+ if (interaction.type === discord_js_1.InteractionType.ApplicationCommand) {
209
+ if (this.client.commands.context.has(interaction.commandName)) {
210
+ let command = this.client.commands.context.get(interaction.commandName);
211
+ try {
212
+ const inhibitor = new InhibitorValidations_js_1.InhibitorValidation(this.client, interaction, command);
213
+ if ((0, CommandValidations_js_1.default)(interaction, command, this.client)) return;
214
+ if (await inhibitor.inhibit()) return;
215
+ if (command.conditions && (await command.conditions(interaction))) return;
216
+ if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
217
+ await interaction.deferReply({
218
+ ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
219
+ fetchReply: this.client.handlerOptions.context?.defer?.fetchReply,
220
+ });
221
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
222
+ await interaction.deferReply({
223
+ ephemeral: command.defer?.ephemeral,
224
+ fetchReply: command.defer?.fetchReply,
225
+ });
226
+ let args = {};
227
+ if (command.type === 3) args = await interaction.channel.messages.fetch(interaction.targetId);
228
+ if (command.type === 2) args = await this.client.users.fetch(interaction.targetId);
229
+ await command.exec(interaction, args);
230
+ this.client.emit('commandRun', interaction, command);
231
+ } catch (error) {
232
+ this.client.emit('commandError', interaction, error, command);
233
+ }
234
+ }
235
+ }
236
+ });
237
+ }
238
+ }
239
+ exports.ContextCommandEvents = ContextCommandEvents;
240
+ class CommandsDeploy {
241
+ client;
242
+ constructor(client) {
243
+ this.client = client;
244
+ }
245
+ deploy() {
246
+ this.client.once('ready', async (client) => {
247
+ const slashCommands = [],
248
+ contextCommands = [];
249
+ this.client.commands.context.map((command) => (command.data ? contextCommands.push(command.data.toJSON()) : null));
250
+ this.client.commands.slash.map((command) => (command.data ? slashCommands.push(command.data.toJSON()) : null));
251
+ try {
252
+ const global = {
253
+ slash: this.client.handlerOptions.slash?.global,
254
+ context: this.client.handlerOptions.context?.global,
255
+ };
256
+ const guild = {
257
+ slash: this.client.handlerOptions.slash?.guildId,
258
+ context: this.client.handlerOptions.context?.guildId,
259
+ };
260
+ if (!guild.slash && !guild.context) return;
261
+ if (global.slash && global.context) {
262
+ if (guild.slash !== guild.context)
263
+ console.info(
264
+ dumfunctions_1.Style.log(
265
+ `Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${
266
+ (await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name
267
+ }!`,
268
+ { color: dumfunctions_1.Style.TextColor.Red }
269
+ )
270
+ );
271
+ this.put('global', guild.slash, [...contextCommands, ...slashCommands]);
272
+ this.put('guild', guild.slash, []);
273
+ }
274
+ if (global.slash && global.context === false) {
275
+ this.put('global', guild.slash, slashCommands);
276
+ }
277
+ if (global.slash === false && global.context) {
278
+ this.put('global', guild.context, contextCommands);
279
+ }
280
+ if (global.slash === false && global.context === false) {
281
+ this.put('guild', guild.slash, [...contextCommands, ...slashCommands]);
282
+ }
283
+ if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
284
+ console.info(
285
+ dumfunctions_1.Style.log(
286
+ `Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? 'globally' : 'locally'} and ${contextCommands.length} context commands ${
287
+ global.context ? 'globally' : 'locally'
288
+ }.`,
289
+ { color: dumfunctions_1.Style.TextColor.Purple }
290
+ )
291
+ );
292
+ } catch (error) {
293
+ console.error(
294
+ dumfunctions_1.Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
295
+ color: dumfunctions_1.Style.BackgroundColor.Red,
296
+ })
297
+ );
298
+ }
299
+ });
300
+ }
301
+ put(type, guild, body) {
302
+ const rest = new discord_js_1.REST({ version: discord_js_1.GatewayVersion }).setToken(this.client.token);
303
+ if (type === 'guild') rest.put(discord_js_1.Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
304
+ else rest.put(discord_js_1.Routes.applicationCommands(this.client.user?.id), { body });
305
+ }
306
+ }
307
+ exports.CommandsDeploy = CommandsDeploy;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const dumfunctions_1 = require('dumfunctions');
4
+ class Extensions {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ async load(extensions, logging = false) {
10
+ const exts = [];
11
+ extensions.map((extension) => {
12
+ try {
13
+ this.client.extensions[extension.name] = extension;
14
+ exts.push(extension.name);
15
+ } catch (error) {
16
+ console.error(
17
+ dumfunctions_1.Style.log(`Xernerx | An error occurred trying to load ${extension.name}, error: <${error}>`, {
18
+ color: dumfunctions_1.Style.BackgroundColor.Red,
19
+ })
20
+ );
21
+ }
22
+ });
23
+ if (logging) console.info(dumfunctions_1.Style.log(`Xernerx | Loaded ${exts.length} extensions: ${exts.join(', ')}`, { color: dumfunctions_1.Style.TextColor.Cyan }));
24
+ }
25
+ }
26
+ exports.default = Extensions;
@@ -1,4 +1,6 @@
1
- export default class XernerxError {
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ class XernerxError {
2
4
  name;
3
5
  message;
4
6
  constructor(message) {
@@ -6,3 +8,4 @@ export default class XernerxError {
6
8
  this.message = message || '';
7
9
  }
8
10
  }
11
+ exports.default = XernerxError;
@@ -1,6 +1,8 @@
1
- export default {
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.default = {
2
4
  name: 'xernerx',
3
- version: '3.5.0',
5
+ version: '3.5.1',
4
6
  type: 'module',
5
7
  description: 'A bot framework for discord.js.',
6
8
  main: 'dist/main.js',
@@ -24,7 +26,7 @@ export default {
24
26
  site: 'git add docs && npm run commit && git push',
25
27
  commit: 'node ../.scripts/commit.js',
26
28
  write: 'npm run build && node ../.scripts/rewritePackage.js ',
27
- build: 'tsc && npx tsup src/main.ts && npx prettier --write src types',
29
+ build: 'tsc && npx tsup src/main.ts && npx prettier --write src',
28
30
  },
29
31
  repository: {
30
32
  type: 'git',
@@ -35,9 +37,9 @@ export default {
35
37
  },
36
38
  dependencies: {
37
39
  '@sapphire/shapeshift': '^3.8.1',
38
- 'discord.js': '^14.7.0',
39
- dumfunctions: '^2.0.0',
40
- 'xernerx-extension-builder': '^0.0.2',
40
+ 'discord.js': '^14.7.1',
41
+ dumfunctions: '^2.1.1',
42
+ 'xernerx-extension-builder': '^0.0.5',
41
43
  zod: '^3.20.6',
42
44
  },
43
45
  devDependencies: {
@@ -0,0 +1,44 @@
1
+ import {
2
+ SlashCommandStringOption,
3
+ SlashCommandNumberOption,
4
+ SlashCommandIntegerOption,
5
+ SlashCommandBooleanOption,
6
+ SlashCommandUserOption,
7
+ SlashCommandChannelOption,
8
+ SlashCommandRoleOption,
9
+ SlashCommandMentionableOption,
10
+ } from 'discord.js';
11
+ export declare enum InhibitorType {
12
+ Member = 'Member',
13
+ User = 'User',
14
+ Guild = 'Guild',
15
+ SlashCommand = 'SlashCommand',
16
+ MessageCommand = 'MessageCommand',
17
+ ContextCommand = 'ContextCommand',
18
+ Command = 'Command',
19
+ Message = 'Message',
20
+ Interaction = 'Interaction',
21
+ Channel = 'Channel',
22
+ }
23
+ export declare enum CommandType {
24
+ Message = 'MessageCommand',
25
+ Slash = 'SlashCommand',
26
+ Context = 'ContextCommand',
27
+ Event = 'Event',
28
+ Inhibitor = 'Inhibitor',
29
+ MessageCommand = 'MessageCommand',
30
+ SlashCommand = 'SlashCommand',
31
+ ContextCommand = 'ContextCommand',
32
+ }
33
+ export declare enum ContextCommandType {
34
+ Message = 3,
35
+ User = 2,
36
+ }
37
+ export declare enum EventEmitterType {
38
+ Client = 'client',
39
+ Rest = 'rest',
40
+ Process = 'process',
41
+ }
42
+ export type SlashCommandOptionChoices = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption;
43
+ export type SlashCommandOption = SlashCommandOptionChoices | SlashCommandBooleanOption | SlashCommandUserOption | SlashCommandChannelOption | SlashCommandRoleOption | SlashCommandMentionableOption;
44
+ export type SlashArgumentTypes = 'String' | 'Number' | 'Boolean' | 'User' | 'Channel' | 'Role' | 'Mentionable' | 'Integer';
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.EventEmitterType = exports.ContextCommandType = exports.CommandType = exports.InhibitorType = void 0;
4
+ var InhibitorType;
5
+ (function (InhibitorType) {
6
+ InhibitorType['Member'] = 'Member';
7
+ InhibitorType['User'] = 'User';
8
+ InhibitorType['Guild'] = 'Guild';
9
+ InhibitorType['SlashCommand'] = 'SlashCommand';
10
+ InhibitorType['MessageCommand'] = 'MessageCommand';
11
+ InhibitorType['ContextCommand'] = 'ContextCommand';
12
+ InhibitorType['Command'] = 'Command';
13
+ InhibitorType['Message'] = 'Message';
14
+ InhibitorType['Interaction'] = 'Interaction';
15
+ InhibitorType['Channel'] = 'Channel';
16
+ })((InhibitorType = exports.InhibitorType || (exports.InhibitorType = {})));
17
+ var CommandType;
18
+ (function (CommandType) {
19
+ CommandType['Message'] = 'MessageCommand';
20
+ CommandType['Slash'] = 'SlashCommand';
21
+ CommandType['Context'] = 'ContextCommand';
22
+ CommandType['Event'] = 'Event';
23
+ CommandType['Inhibitor'] = 'Inhibitor';
24
+ CommandType['MessageCommand'] = 'MessageCommand';
25
+ CommandType['SlashCommand'] = 'SlashCommand';
26
+ CommandType['ContextCommand'] = 'ContextCommand';
27
+ })((CommandType = exports.CommandType || (exports.CommandType = {})));
28
+ var ContextCommandType;
29
+ (function (ContextCommandType) {
30
+ ContextCommandType[(ContextCommandType['Message'] = 3)] = 'Message';
31
+ ContextCommandType[(ContextCommandType['User'] = 2)] = 'User';
32
+ })((ContextCommandType = exports.ContextCommandType || (exports.ContextCommandType = {})));
33
+ var EventEmitterType;
34
+ (function (EventEmitterType) {
35
+ EventEmitterType['Client'] = 'client';
36
+ EventEmitterType['Rest'] = 'rest';
37
+ EventEmitterType['Process'] = 'process';
38
+ })((EventEmitterType = exports.EventEmitterType || (exports.EventEmitterType = {})));
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });