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