xernerx 4.1.0 → 4.2.1

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 (112) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/build/ContextCommandBuilder.d.ts +68 -0
  3. package/dist/cjs/build/ContextCommandBuilder.js +97 -0
  4. package/dist/cjs/build/EventBuilder.d.ts +21 -0
  5. package/dist/cjs/build/EventBuilder.js +44 -0
  6. package/dist/cjs/build/InhibitorBuilder.d.ts +19 -0
  7. package/dist/cjs/build/InhibitorBuilder.js +37 -0
  8. package/dist/cjs/build/MessageCommandBuilder.d.ts +59 -0
  9. package/dist/cjs/build/MessageCommandBuilder.js +100 -0
  10. package/dist/cjs/build/SlashCommandBuilder.d.ts +64 -0
  11. package/dist/cjs/build/SlashCommandBuilder.js +168 -0
  12. package/dist/cjs/client/XernerxClient.d.ts +28 -0
  13. package/dist/cjs/client/XernerxClient.js +116 -0
  14. package/dist/cjs/handlers/CommandHandler.d.ts +27 -0
  15. package/dist/cjs/handlers/CommandHandler.js +45 -0
  16. package/dist/cjs/handlers/EventHandler.d.ts +13 -0
  17. package/dist/cjs/handlers/EventHandler.js +19 -0
  18. package/dist/cjs/handlers/Handler.d.ts +57 -0
  19. package/dist/cjs/handlers/Handler.js +308 -0
  20. package/dist/cjs/handlers/InhibitorHandler.d.ts +18 -0
  21. package/dist/cjs/handlers/InhibitorHandler.js +24 -0
  22. package/dist/cjs/main.d.ts +44 -0
  23. package/dist/cjs/main.js +112 -0
  24. package/dist/cjs/models/CommandArguments.d.ts +17 -0
  25. package/dist/cjs/models/CommandArguments.js +106 -0
  26. package/dist/cjs/models/Events.d.ts +24 -0
  27. package/dist/cjs/models/Events.js +307 -0
  28. package/dist/cjs/models/Extensions.d.ts +7 -0
  29. package/dist/cjs/models/Extensions.js +26 -0
  30. package/dist/cjs/tools/XernerxError.d.ts +5 -0
  31. package/dist/cjs/tools/XernerxError.js +11 -0
  32. package/dist/cjs/tools/package.d.ts +49 -0
  33. package/dist/cjs/tools/package.js +50 -0
  34. package/dist/cjs/types/enums.d.ts +44 -0
  35. package/dist/cjs/types/enums.js +38 -0
  36. package/dist/cjs/types/interfaces.d.ts +25 -0
  37. package/dist/cjs/types/interfaces.js +2 -0
  38. package/dist/cjs/types/options.d.ts +241 -0
  39. package/dist/cjs/types/options.js +2 -0
  40. package/dist/cjs/types/types.d.ts +61 -0
  41. package/dist/cjs/types/types.js +2 -0
  42. package/dist/cjs/utils/ClientUtil.d.ts +25 -0
  43. package/dist/cjs/utils/ClientUtil.js +211 -0
  44. package/dist/cjs/utils/CommandUtil.d.ts +58 -0
  45. package/dist/cjs/utils/CommandUtil.js +247 -0
  46. package/dist/cjs/validators/CommandValidations.d.ts +12 -0
  47. package/dist/cjs/validators/CommandValidations.js +169 -0
  48. package/dist/cjs/validators/InhibitorValidations.d.ts +11 -0
  49. package/dist/cjs/validators/InhibitorValidations.js +40 -0
  50. package/dist/client/XernerxClient.d.ts +5 -4
  51. package/dist/client/XernerxClient.js +2 -10
  52. package/dist/functions/deploy.js +20 -20
  53. package/dist/handlers/CommandHandler.js +28 -13
  54. package/dist/main.d.ts +1 -1
  55. package/dist/main.js +1 -1
  56. package/dist/mjs/build/ContextCommandBuilder.d.ts +68 -0
  57. package/dist/mjs/build/ContextCommandBuilder.js +88 -0
  58. package/dist/mjs/build/EventBuilder.d.ts +21 -0
  59. package/dist/mjs/build/EventBuilder.js +34 -0
  60. package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
  61. package/dist/mjs/build/InhibitorBuilder.js +27 -0
  62. package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
  63. package/dist/mjs/build/MessageCommandBuilder.js +90 -0
  64. package/dist/mjs/build/SlashCommandBuilder.d.ts +64 -0
  65. package/dist/mjs/build/SlashCommandBuilder.js +121 -0
  66. package/dist/mjs/client/XernerxClient.d.ts +28 -0
  67. package/dist/mjs/client/XernerxClient.js +108 -0
  68. package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
  69. package/dist/mjs/handlers/CommandHandler.js +42 -0
  70. package/dist/mjs/handlers/EventHandler.d.ts +13 -0
  71. package/dist/mjs/handlers/EventHandler.js +16 -0
  72. package/dist/mjs/handlers/Handler.d.ts +57 -0
  73. package/dist/mjs/handlers/Handler.js +260 -0
  74. package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
  75. package/dist/mjs/handlers/InhibitorHandler.js +21 -0
  76. package/dist/mjs/main.d.ts +44 -0
  77. package/dist/mjs/main.js +52 -0
  78. package/dist/mjs/models/CommandArguments.d.ts +17 -0
  79. package/dist/mjs/models/CommandArguments.js +101 -0
  80. package/dist/mjs/models/Events.d.ts +24 -0
  81. package/dist/mjs/models/Events.js +295 -0
  82. package/dist/mjs/models/Extensions.d.ts +7 -0
  83. package/dist/mjs/models/Extensions.js +23 -0
  84. package/dist/mjs/tools/XernerxError.d.ts +5 -0
  85. package/dist/mjs/tools/XernerxError.js +8 -0
  86. package/dist/mjs/tools/package.d.ts +49 -0
  87. package/dist/mjs/tools/package.js +48 -0
  88. package/dist/mjs/types/enums.d.ts +44 -0
  89. package/dist/mjs/types/enums.js +35 -0
  90. package/dist/mjs/types/interfaces.d.ts +25 -0
  91. package/dist/mjs/types/interfaces.js +1 -0
  92. package/dist/mjs/types/options.d.ts +241 -0
  93. package/dist/mjs/types/options.js +1 -0
  94. package/dist/mjs/types/types.d.ts +61 -0
  95. package/dist/mjs/types/types.js +1 -0
  96. package/dist/mjs/utils/ClientUtil.d.ts +25 -0
  97. package/dist/mjs/utils/ClientUtil.js +202 -0
  98. package/dist/mjs/utils/CommandUtil.d.ts +58 -0
  99. package/dist/mjs/utils/CommandUtil.js +232 -0
  100. package/dist/mjs/validators/CommandValidations.d.ts +12 -0
  101. package/dist/mjs/validators/CommandValidations.js +166 -0
  102. package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
  103. package/dist/mjs/validators/InhibitorValidations.js +36 -0
  104. package/dist/tools/XernerxLog.d.ts +1 -0
  105. package/dist/tools/XernerxLog.js +26 -8
  106. package/dist/types/extenders.d.ts +11 -6
  107. package/dist/types/interfaces.d.ts +23 -19
  108. package/dist/utils/ClientUtil.d.ts +2 -1
  109. package/dist/utils/ClientUtil.js +10 -1
  110. package/dist/utils/MessageUtil.d.ts +4 -1
  111. package/dist/utils/MessageUtil.js +4 -2
  112. package/package.json +1 -1
@@ -0,0 +1,247 @@
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.InteractionCommandUtil = exports.MessageCommandUtil = void 0;
9
+ const discord_js_1 = require('discord.js');
10
+ const XernerxError_js_1 = __importDefault(require('../tools/XernerxError.js'));
11
+ class MessageCommandUtil {
12
+ client;
13
+ message;
14
+ constructor(client, message) {
15
+ this.client = client;
16
+ this.message = message;
17
+ }
18
+ async reply(content) {
19
+ if (this.client.cache.messages.has(this.message.id)) var existingMessage = this.client.cache.messages.get(this.message.id);
20
+ if (!existingMessage) {
21
+ const msg = await this.message.reply(content);
22
+ this.message.response = msg.id;
23
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
24
+ this.client.cache.messages.set(this.message.id, this.message);
25
+ setInterval(() => {
26
+ this.client.cache.messages.delete(this.message.id);
27
+ }, this.client.settings.cooldown?.cache || 300000);
28
+ }
29
+ return msg;
30
+ }
31
+ if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
32
+ try {
33
+ const msg = await this.message.channel.messages.fetch(existingMessage.response);
34
+ msg.edit(content);
35
+ return msg;
36
+ } catch {
37
+ const msg = await this.message.reply(content);
38
+ this.message.response = msg.id;
39
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
40
+ this.client.cache.messages.set(this.message.id, this.message);
41
+ setInterval(() => {
42
+ this.client.cache.messages.delete(this.message.id);
43
+ }, this.client.settings.cooldown?.cache || 300000);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ async send(content) {
49
+ if (this.client.cache.messages.has(this.message.id)) var existingMessage = this.client.cache.messages.get(this.message.id);
50
+ if (!existingMessage) {
51
+ const msg = await this.message.channel.send(content);
52
+ this.message.response = msg.id;
53
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
54
+ this.client.cache.messages.set(this.message.id, this.message);
55
+ setInterval(() => {
56
+ this.client.cache.messages.delete(this.message.id);
57
+ }, this.client.settings.cooldown?.cache || 300000);
58
+ }
59
+ return msg;
60
+ }
61
+ if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
62
+ try {
63
+ const msg = await this.message.channel.messages.fetch(existingMessage.response);
64
+ msg.edit(content);
65
+ return msg;
66
+ } catch {
67
+ const msg = await this.message.channel.send(content);
68
+ this.message.response = msg.id;
69
+ if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
70
+ this.client.cache.messages.set(this.message.id, this.message);
71
+ setInterval(() => {
72
+ this.client.cache.messages.delete(this.message.id);
73
+ }, this.client.settings.cooldown?.cache || 300000);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ async defer(time) {
79
+ return new Promise((resolve) => setTimeout(resolve, time));
80
+ }
81
+ getCommands() {
82
+ return this.client.commands.message;
83
+ }
84
+ getCommandName() {}
85
+ selectMenuPaginator(embeds, options) {}
86
+ buttonPaginator(embeds, options) {}
87
+ buttonMenuPaginator(embeds, options) {}
88
+ isOwner() {
89
+ return this.client.util.isOwner(this.message.author.id);
90
+ }
91
+ createModal() {}
92
+ }
93
+ exports.MessageCommandUtil = MessageCommandUtil;
94
+ class InteractionCommandUtil {
95
+ client;
96
+ interaction;
97
+ constructor(client, interaction) {
98
+ this.client = client;
99
+ this.interaction = interaction;
100
+ }
101
+ reply(content) {
102
+ return this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content);
103
+ }
104
+ async defer(time) {
105
+ return new Promise((resolve) => setTimeout(resolve, time));
106
+ }
107
+ getCommands() {
108
+ if (this.interaction.commandType === 1) return this.client.commands.slash;
109
+ else return this.client.commands.context;
110
+ }
111
+ getCommandName() {}
112
+ selectMenuPaginator(embeds, options) {
113
+ if (!Array.isArray(embeds)) throw new XernerxError_js_1.default(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
114
+ if (embeds.length > 25) throw new XernerxError_js_1.default(`Max select menu length is 25.`);
115
+ if (typeof options !== 'object') options = {};
116
+ if (!Array.isArray(options.components)) options.components = [];
117
+ if (!options.index) {
118
+ options.index = new discord_js_1.EmbedBuilder().setTitle('Index').setColor('Random');
119
+ for (const embed of embeds) {
120
+ options.index.addFields([
121
+ {
122
+ name: embed.data.title || 'No Name',
123
+ value: embed.data.description || 'Page',
124
+ inline: embeds.length > 25 / 2 ? true : false,
125
+ },
126
+ ]);
127
+ }
128
+ }
129
+ if (!options.row) {
130
+ options.row = new discord_js_1.ActionRowBuilder();
131
+ if (!options.id) options.id = `${this.interaction.id}-menu`;
132
+ options.component = new discord_js_1.StringSelectMenuBuilder()
133
+ .setCustomId(options.id)
134
+ .setMaxValues(1)
135
+ .setMinValues(1)
136
+ .setPlaceholder('Select a page.')
137
+ .addOptions({ label: 'index', value: '0' });
138
+ embeds.map((embed, i = 0) => {
139
+ options?.component?.addOptions({
140
+ label: embed.data.title || 'No Name',
141
+ description: embed.data.description || `Page ${i}`,
142
+ value: String(i + 1),
143
+ });
144
+ });
145
+ options.row.addComponents(options.component);
146
+ }
147
+ embeds.unshift(options.index);
148
+ const content = {
149
+ embeds: [options.index],
150
+ components: [options.row, ...options.components],
151
+ ephemeral: !!options.ephemeral,
152
+ };
153
+ (options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then(() => {
154
+ const collector = this.interaction.channel
155
+ .createMessageComponentCollector({
156
+ filter: options?.filter,
157
+ time: options?.time || 60000,
158
+ })
159
+ .on('collect', (interaction) => {
160
+ if (!interaction.customId.startsWith(this.interaction.id)) return;
161
+ interaction.update({
162
+ embeds: [embeds[parseInt(interaction.values[0])]],
163
+ });
164
+ })
165
+ .on('end', () => {
166
+ this.interaction.editReply({ components: [] });
167
+ });
168
+ });
169
+ }
170
+ buttonPaginator(embeds, options) {
171
+ if (!Array.isArray(embeds)) throw new XernerxError_js_1.default(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
172
+ if (embeds.length <= 0) throw new XernerxError_js_1.default(`The minimum embeds is 1.`);
173
+ if (typeof options !== 'object') options = {};
174
+ if (!Array.isArray(options.components)) options.components = [];
175
+ if (!options.row) {
176
+ options.row = new discord_js_1.ActionRowBuilder();
177
+ if (!options.id) options.id = `${this.interaction.id}-menu`;
178
+ }
179
+ if (!options.buttons) options.buttons = ['⏮️', '◀️', '⏹️', '▶️', '⏭️'];
180
+ for (const button of options.buttons) {
181
+ options.row.addComponents(
182
+ new discord_js_1.ButtonBuilder()
183
+ .setCustomId(`${this.interaction.id}-${options.buttons.indexOf(button)}`)
184
+ .setEmoji(button)
185
+ .setStyle(discord_js_1.ButtonStyle.Primary)
186
+ );
187
+ }
188
+ let embed = embeds[options.index || 0];
189
+ const content = {
190
+ embeds: [embed],
191
+ components: [options.row, ...options.components],
192
+ ephemeral: !!options.ephemeral,
193
+ };
194
+ (options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then((message) => {
195
+ const collector = message.channel
196
+ .createMessageComponentCollector({
197
+ filter: options.filter,
198
+ time: options?.time || 60000,
199
+ })
200
+ .on('collect', (interaction) => {
201
+ let stop = false;
202
+ if (interaction.customId.startsWith(this.interaction.id)) {
203
+ switch (Number(interaction.customId.split(/-/).pop())) {
204
+ case 0: {
205
+ embed = embeds[0];
206
+ break;
207
+ }
208
+ case 1: {
209
+ embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
210
+ break;
211
+ }
212
+ case 2: {
213
+ collector.stop();
214
+ stop = true;
215
+ break;
216
+ }
217
+ case 3: {
218
+ embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
219
+ break;
220
+ }
221
+ case 4: {
222
+ embed = embeds[embeds.length - 1];
223
+ break;
224
+ }
225
+ }
226
+ stop
227
+ ? interaction.update({
228
+ embeds: [embed],
229
+ components: [],
230
+ })
231
+ : interaction.update({
232
+ embeds: [embed],
233
+ });
234
+ }
235
+ })
236
+ .on('end', () => {
237
+ this.interaction.editReply({ components: [] });
238
+ });
239
+ });
240
+ }
241
+ buttonMenuPaginator(embeds, options) {}
242
+ isOwner() {
243
+ return this.client.util.isOwner(this.interaction.user.id);
244
+ }
245
+ createModal() {}
246
+ }
247
+ exports.InteractionCommandUtil = InteractionCommandUtil;
@@ -0,0 +1,12 @@
1
+ import { Interaction } from 'discord.js';
2
+ import ContextCommandBuilder from '../build/ContextCommandBuilder.js';
3
+ import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
4
+ import SlashCommandBuilder from '../build/SlashCommandBuilder.js';
5
+ import XernerxClient from '../client/XernerxClient.js';
6
+ import { XernerxMessage } from '../types/types.js';
7
+ export default function commandValidation(
8
+ action: XernerxMessage | Interaction,
9
+ command: SlashCommandBuilder | MessageCommandBuilder | ContextCommandBuilder | any,
10
+ client: XernerxClient,
11
+ res?: boolean
12
+ ): boolean;
@@ -0,0 +1,169 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const discord_js_1 = require('discord.js');
4
+ const enums_js_1 = require('../types/enums.js');
5
+ function getUser(from) {
6
+ if (from instanceof discord_js_1.Message) return from.author;
7
+ else return from.user;
8
+ }
9
+ function commandValidation(action, command, client, res = false) {
10
+ let user = getUser(action);
11
+ if ((command.ignoreOwner || client.settings.ignore?.owner) && client.util.isOwner(user.id)) return res;
12
+ else if (inCooldown(user, client, command, action)) return true;
13
+ else if (command.owner && !client.util.isOwner(user.id)) {
14
+ res = true;
15
+ emit(client, action, command, 'Not an owner', client.settings.ownerId);
16
+ } else if (command.channelType?.length > 0 || command.channelType) {
17
+ if (!Array.isArray(command.channelType)) command.channelType = [command.channelType];
18
+ if (!command?.channelType?.includes(action.channel?.type)) {
19
+ res = true;
20
+ emit(client, action, command, 'Not the correct channel', command.channelType);
21
+ }
22
+ } else if (command.channels?.length > 0 && !command.channels.includes(action.channel?.id)) {
23
+ res = true;
24
+ emit(client, action, command, 'Not a whitelisted channel', command.channels);
25
+ } else if (command.guilds?.length > 0 && !command.guilds.includes(action.guild?.id)) {
26
+ res = true;
27
+ emit(client, action, command, 'Not a whitelisted guild', command.guilds);
28
+ } else if (command.channelType && command.channelType !== action.channel?.type) {
29
+ res = true;
30
+ emit(client, action, command, 'Not the correct type of channel', command.channelType);
31
+ } else if (action?.guild && (command.permissions?.user || client.settings.permissions?.user)) {
32
+ const permissions = command.permissions?.user || client?.settings?.permissions?.user?.push(...handlerPermissions(client, command.commandType, 'user')),
33
+ missing = [];
34
+ if (Array.isArray(permissions))
35
+ permissions.map((permission) => {
36
+ if (!(action.member?.permissions).has(permission)) {
37
+ missing.push(permission);
38
+ }
39
+ });
40
+ if (missing.length > 0) {
41
+ res = true;
42
+ emit(client, action, command, 'Missing User Permissions', missing);
43
+ }
44
+ } else if (action?.guild && (command.permissions?.client || client.settings.permissions?.client)) {
45
+ const permissions = command.permissions?.client || client?.settings?.permissions?.client?.push(...handlerPermissions(client, command.commandType, 'client')),
46
+ missing = [];
47
+ if (Array.isArray(permissions))
48
+ permissions.map((permission) => {
49
+ if (!(action.member?.permissions).has(permission)) {
50
+ missing.push(permission);
51
+ }
52
+ });
53
+ if (missing.length > 0) {
54
+ res = true;
55
+ emit(client, action, command, 'Missing Client Permissions', missing);
56
+ }
57
+ }
58
+ return res;
59
+ }
60
+ exports.default = commandValidation;
61
+ function emit(client, action, command, reason, extra) {
62
+ return client.emit('commandBlock', action, command, reason, extra);
63
+ }
64
+ function inCooldown(user, client, command, action) {
65
+ let res = false,
66
+ downs = {};
67
+ const { cooldowns, messageCommands, slashCommands, contextCommands, commands } = client.cache;
68
+ if (command.commandType === enums_js_1.CommandType.MessageCommand && client.handlerOptions.message.cooldown) {
69
+ if (messageCommands.has(user.id)) {
70
+ const usr = messageCommands.get(user.id);
71
+ usr.timeRemaining = usr.endsAt - Date.now();
72
+ downs.message = usr;
73
+ res = true;
74
+ }
75
+ if (!messageCommands.has(user.id)) {
76
+ messageCommands.set(user.id, toCooldown(action, command, client.handlerOptions.message.cooldown, user.id));
77
+ setInterval(() => {
78
+ messageCommands.delete(user.id);
79
+ }, client.handlerOptions.message.cooldown);
80
+ }
81
+ }
82
+ if (command.commandType === enums_js_1.CommandType.SlashCommand && client.handlerOptions.slash.cooldown) {
83
+ if (slashCommands.has(user.id)) {
84
+ const usr = slashCommands.get(user.id);
85
+ usr.timeRemaining = usr.endsAt - Date.now();
86
+ downs.slash = usr;
87
+ res = true;
88
+ }
89
+ if (!slashCommands.has(user.id)) {
90
+ slashCommands.set(user.id, toCooldown(action, command, client.handlerOptions.slash.cooldown, user.id));
91
+ setInterval(() => {
92
+ slashCommands.delete(user.id);
93
+ }, client.handlerOptions.slash.cooldown);
94
+ }
95
+ }
96
+ if (command.commandType === enums_js_1.CommandType.ContextCommand && client.handlerOptions.context.cooldown) {
97
+ if (contextCommands.has(user.id)) {
98
+ const usr = contextCommands.get(user.id);
99
+ usr.timeRemaining = usr.endsAt - Date.now();
100
+ downs.context = usr;
101
+ res = true;
102
+ }
103
+ if (!contextCommands.has(user.id)) {
104
+ contextCommands.set(user.id, toCooldown(action, command, client.handlerOptions.context.cooldown, user.id));
105
+ setInterval(() => {
106
+ contextCommands.delete(user.id);
107
+ }, client.handlerOptions.context.cooldown);
108
+ }
109
+ }
110
+ if (client.settings?.cooldown?.default) {
111
+ if (cooldowns.has(user.id)) {
112
+ const usr = cooldowns.get(user.id);
113
+ usr.timeRemaining = usr.endsAt - Date.now();
114
+ downs.default = usr;
115
+ res = true;
116
+ }
117
+ if (!cooldowns.has(user.id)) {
118
+ cooldowns.set(user.id, toCooldown(action, command, client.settings.cooldown.default, user.id));
119
+ setInterval(() => {
120
+ cooldowns.delete(user.id);
121
+ }, client.settings.cooldown.default);
122
+ }
123
+ }
124
+ if (command.cooldown) {
125
+ const name = user.id + '-' + (command.data?.name || command?.name) + '-' + command.commandType;
126
+ if (commands.has(name)) {
127
+ const usr = commands.get(name);
128
+ usr.timeRemaining = usr.endsAt - Date.now();
129
+ downs.command = usr;
130
+ res = true;
131
+ }
132
+ if (!commands.has(name)) {
133
+ commands.set(name, toCooldown(action, command, command.cooldown, name));
134
+ setInterval(() => {
135
+ commands.delete(name);
136
+ }, command.cooldown);
137
+ }
138
+ }
139
+ if (Object.keys(downs).length > 0) client.emit('commandCooldown', action, command, downs);
140
+ return res;
141
+ }
142
+ function toCooldown(action, command, cooldown, name) {
143
+ let user = getUser(action);
144
+ return {
145
+ name,
146
+ id: user.id,
147
+ tag: user.tag,
148
+ commandType: command.commandType,
149
+ commandName: command?.data?.name || command?.name,
150
+ guildId: action?.guild?.id,
151
+ channelId: action?.channel?.id,
152
+ startsAt: Number(Date.now()),
153
+ endsAt: Number(Date.now()) + cooldown,
154
+ };
155
+ }
156
+ function handlerPermissions(client, commandType, type) {
157
+ let permissions = [];
158
+ if (commandType === enums_js_1.CommandType.MessageCommand) {
159
+ if (type === 'user') permissions = client.handlerOptions.message?.userPermissions || [];
160
+ else if (type === 'client') permissions = client.handlerOptions.message?.clientPermissions || [];
161
+ } else if (commandType === enums_js_1.CommandType.SlashCommand) {
162
+ if (type === 'user') permissions = client.handlerOptions.slash?.userPermissions || [];
163
+ else if (type === 'client') permissions = client.handlerOptions.slash?.clientPermissions || [];
164
+ } else if (commandType === enums_js_1.CommandType.ContextCommand) {
165
+ if (type === 'user') permissions = client.handlerOptions.context?.userPermissions || [];
166
+ else if (type === 'client') permissions = client.handlerOptions.context?.clientPermissions || [];
167
+ }
168
+ return permissions;
169
+ }
@@ -0,0 +1,11 @@
1
+ import XernerxClient from '../client/XernerxClient.js';
2
+ import { XernerxInteraction, XernerxMessage } from '../types/types.js';
3
+ export declare class InhibitorValidation {
4
+ client: XernerxClient;
5
+ action: XernerxMessage | XernerxInteraction;
6
+ command: string;
7
+ inhibited: Record<string, string | void>;
8
+ constructor(client: XernerxClient, action: XernerxMessage | XernerxInteraction, command: string);
9
+ inhibit(): Promise<Record<string, string | void> | undefined>;
10
+ private args;
11
+ }
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.InhibitorValidation = void 0;
4
+ const enums_js_1 = require('../types/enums.js');
5
+ class InhibitorValidation {
6
+ client;
7
+ action;
8
+ command;
9
+ inhibited;
10
+ constructor(client, action, command) {
11
+ this.client = client;
12
+ this.action = action;
13
+ this.command = command;
14
+ this.inhibited = {};
15
+ }
16
+ async inhibit() {
17
+ for (const inhibitor of this.client.inhibitors) {
18
+ const inhibit = inhibitor[1];
19
+ if (inhibit) this.inhibited[inhibit.name] = await inhibit.check(this.action, this.args(this.action, inhibit.type));
20
+ }
21
+ for (const inhibit of Object.values(this.inhibited)) {
22
+ if (inhibit) return this.inhibited;
23
+ }
24
+ }
25
+ args(action, type) {
26
+ if (type === enums_js_1.InhibitorType.Channel) return action.channel;
27
+ if (type === enums_js_1.InhibitorType.User) return action.author || action.user;
28
+ if (type === enums_js_1.InhibitorType.Guild) return action.guild;
29
+ if (type === enums_js_1.InhibitorType.Member) return action.member;
30
+ // if (type === InhibitorType.Command)
31
+ // return this.client.util.getAllCommands().filter(this.command.name);
32
+ // if (type === InhibitorType.MessageCommand)
33
+ // return this.client.util.getAllMessageCommands().find(this.command.name);
34
+ // if (type === InhibitorType.SlashCommand)
35
+ // return this.client.util.getAllSlashCommands().find(this.command.name);
36
+ // if (type === InhibitorType.ContextCommand)
37
+ // return this.client.util.getAllContextCommands().find(this.command.name);
38
+ }
39
+ }
40
+ exports.InhibitorValidation = InhibitorValidation;
@@ -1,12 +1,12 @@
1
1
  import { Client, ClientOptions, Collection } from 'discord.js';
2
2
  import { XernerxOptions, ModuleOptions, XernerxCommands, XernerxCache } from '../types/interfaces.js';
3
3
  import ClientUtil from '../utils/ClientUtil.js';
4
- import { InhibitorBuilder } from '../main.js';
4
+ import { InhibitorBuilder, EventBuilder } from '../main.js';
5
5
  export default class XernerxClient extends Client {
6
6
  readonly settings: {
7
7
  ownerId: (string | string[]) & (string | string[] | undefined);
8
- local: string;
9
8
  global: boolean;
9
+ local?: string | undefined;
10
10
  permissions?:
11
11
  | {
12
12
  client: string[];
@@ -27,6 +27,7 @@ export default class XernerxClient extends Client {
27
27
  ready: boolean;
28
28
  error: boolean;
29
29
  info: boolean;
30
+ table: string[] | null;
30
31
  }
31
32
  | undefined;
32
33
  cooldown?:
@@ -38,7 +39,7 @@ export default class XernerxClient extends Client {
38
39
  };
39
40
  readonly config: unknown;
40
41
  readonly commands: XernerxCommands;
41
- readonly events: Collection<unknown, unknown>;
42
+ readonly events: Collection<string, EventBuilder>;
42
43
  readonly inhibitors: Collection<string, InhibitorBuilder>;
43
44
  readonly modules: ModuleOptions;
44
45
  readonly util: ClientUtil;
@@ -49,6 +50,6 @@ export default class XernerxClient extends Client {
49
50
  shardCount: number;
50
51
  };
51
52
  readonly cache: XernerxCache;
52
- constructor(discordOptions: ClientOptions, xernerxOptions: XernerxOptions, config: unknown);
53
+ constructor(discordOptions: ClientOptions, xernerxOptions: XernerxOptions, config?: unknown);
53
54
  connect(token: string): void;
54
55
  }
@@ -8,20 +8,11 @@ import XernerxLog from '../tools/XernerxLog.js';
8
8
  import ClientUtil from '../utils/ClientUtil.js';
9
9
  import ExtensionHandler from '../handlers/ExtensionHandler.js';
10
10
  export default class XernerxClient extends Client {
11
- settings;
12
- config;
13
- commands;
14
- events;
15
- inhibitors;
16
- modules;
17
- util;
18
- stats;
19
- cache;
20
11
  constructor(discordOptions, xernerxOptions, config) {
21
12
  super(discordOptions);
22
13
  this.settings = z
23
14
  .object({
24
- local: z.string(),
15
+ local: z.string().optional(),
25
16
  global: z.boolean().default(false),
26
17
  ownerId: z.string().or(z.array(z.string())).default([]),
27
18
  permissions: z
@@ -44,6 +35,7 @@ export default class XernerxClient extends Client {
44
35
  ready: z.boolean().default(false),
45
36
  info: z.boolean().default(false),
46
37
  error: z.boolean().default(false),
38
+ table: z.array(z.string()).or(z.null()).default(null),
47
39
  })
48
40
  .optional(),
49
41
  cooldown: z
@@ -1,33 +1,33 @@
1
1
  import { GatewayVersion, REST, Routes } from 'discord.js';
2
2
  import XernerxLog from '../tools/XernerxLog.js';
3
- const commands = { slash: [], context: [], retries: 0 };
3
+ import XernerxError from '../tools/XernerxError.js';
4
+ const commands = { slash: [], context: [] };
4
5
  export default function deploy(client, type) {
5
6
  client.prependOnceListener('ready', (client) => {
6
7
  commands[type] = client.commands[type].map((command) => command.data.toJSON());
7
- if (commands.retries % 2) {
8
- try {
9
- if (client.settings.global) {
10
- put(client, client.settings.global, [...commands.slash, ...commands.context]);
11
- put(client, !client.settings.global, []);
12
- } else {
13
- put(client, !client.settings.global, [...commands.slash, ...commands.context]);
14
- put(client, client.settings.global, []);
15
- }
16
- } catch (error) {
17
- new XernerxLog(client).error(`An error occurred while deploying the interaction commands!`, error);
18
- } finally {
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
- );
8
+ if (!(!!client.modules.options.slash && !!client.modules.options.context && commands.slash.length > 0 && commands.context.length > 0)) return;
9
+ try {
10
+ if (client.settings.global) {
11
+ put(client, client.settings.global, [...commands.slash, ...commands.context]);
12
+ put(client, !client.settings.global, []);
13
+ } else {
14
+ put(client, !client.settings.global, [...commands.slash, ...commands.context]);
15
+ put(client, client.settings.global, []);
24
16
  }
17
+ } catch (error) {
18
+ 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
+ );
25
25
  }
26
- commands.retries++;
27
26
  });
28
27
  }
29
28
  function put(client, global, body) {
30
29
  const rest = new REST({ version: GatewayVersion }).setToken(client.token);
31
- if (!global) rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
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
32
  else rest.put(Routes.applicationCommands(client.user?.id), { body });
33
33
  }