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.
- package/dist/build/SlashCommandBuilder.d.ts +1 -0
- package/dist/build/SlashCommandBuilder.js +1 -0
- package/dist/functions/deploy.js +5 -1
- package/dist/handlers/CommandHandler.js +13 -5
- package/dist/handlers/EventHandler.js +1 -1
- package/dist/handlers/ExtensionHandler.js +1 -1
- package/dist/handlers/InhibitorHandler.js +1 -1
- package/dist/main.d.ts +3 -2
- package/dist/main.js +3 -2
- package/dist/types/interfaces.d.ts +1 -1
- package/dist/validators/commandValidation.js +2 -1
- package/package.json +1 -1
- package/dist/build copy/ContextCommandBuilder.d.ts +0 -37
- package/dist/build copy/ContextCommandBuilder.js +0 -88
- package/dist/build copy/EventBuilder.d.ts +0 -21
- package/dist/build copy/EventBuilder.js +0 -34
- package/dist/build copy/InhibitorBuilder.d.ts +0 -19
- package/dist/build copy/InhibitorBuilder.js +0 -27
- package/dist/build copy/MessageCommandBuilder.d.ts +0 -39
- package/dist/build copy/MessageCommandBuilder.js +0 -90
- package/dist/build copy/SlashCommandBuilder.d.ts +0 -41
- package/dist/build copy/SlashCommandBuilder.js +0 -122
- package/dist/client/DBLClient.d.ts +0 -8
- package/dist/client/DBLClient.js +0 -15
- package/dist/client/Top.ggClient.d.ts +0 -1
- package/dist/client/Top.ggClient.js +0 -1
- package/dist/events/messageCreate.d.ts +0 -1
- package/dist/events/messageCreate.js +0 -1
- package/dist/functions/AsyncFunctions.d.ts +0 -1
- package/dist/functions/AsyncFunctions.js +0 -1
- package/dist/functions/getPermissionBitField.d.ts +0 -2
- package/dist/functions/getPermissionBitField.js +0 -17
- package/dist/functions/hasVoted.d.ts +0 -1
- package/dist/functions/hasVoted.js +0 -1
- package/dist/functions/voted.d.ts +0 -1
- package/dist/functions/voted.js +0 -1
- package/dist/models/CommandArguments.d.ts +0 -17
- package/dist/models/CommandArguments.js +0 -101
- package/dist/models/Events.d.ts +0 -24
- package/dist/models/Events.js +0 -297
- package/dist/models/Extensions.d.ts +0 -7
- package/dist/models/Extensions.js +0 -23
- package/dist/models/XernerxUser.d.ts +0 -2
- package/dist/models/XernerxUser.js +0 -9
- package/dist/tools/classes.d.ts +0 -6
- package/dist/tools/classes.js +0 -10
- package/dist/tools/loggers.d.ts +0 -4
- package/dist/tools/loggers.js +0 -4
- package/dist/tools/package.d.ts +0 -42
- package/dist/tools/package.js +0 -41
- package/dist/types/enums.d.ts +0 -44
- package/dist/types/enums.js +0 -35
- package/dist/types/options.d.ts +0 -254
- package/dist/types/options.js +0 -1
- package/dist/utils/CommandUtil.d.ts +0 -58
- package/dist/utils/CommandUtil.js +0 -232
- package/dist/utils/InteractionArguments.d.ts +0 -1
- package/dist/utils/InteractionArguments.js +0 -1
- package/dist/validators/CommandValidations.d.ts +0 -12
- package/dist/validators/CommandValidations.js +0 -166
- package/dist/validators/commands.d.ts +0 -4
- package/dist/validators/commands.js +0 -25
- /package/dist/validators/{InhibitorValidations.d.ts → inhibitorValidations.d.ts} +0 -0
- /package/dist/validators/{InhibitorValidations.js → inhibitorValidations.js} +0 -0
|
@@ -1,232 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|
|
@@ -1,166 +0,0 @@
|
|
|
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 (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
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ContextCommandBuilder, MessageCommandBuilder, SlashCommandBuilder } from '../main.js';
|
|
2
|
-
import { XernerxMessage } from '../types/extenders.js';
|
|
3
|
-
import { XernerxInteraction } from '../types/types.js';
|
|
4
|
-
export default function commandValidation(event: XernerxInteraction | XernerxMessage, command: MessageCommandBuilder | SlashCommandBuilder | ContextCommandBuilder): Promise<boolean>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ChannelType, PermissionFlagsBits } from '../main.js';
|
|
2
|
-
export default async function commandValidation(event, command) {
|
|
3
|
-
if (command.permissions?.dm == false && event.channel?.type === ChannelType.DM) return await emit(event, "Can't use in a DM Channel");
|
|
4
|
-
if (command.permissions?.user) {
|
|
5
|
-
if (!(event.member?.permissions).has(toBigInt(command.permissions.user))) return await emit(event, 'Missing User Permissions');
|
|
6
|
-
}
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
async function emit(event, reason) {
|
|
10
|
-
return await event.client.emit('commandBlock', event, reason);
|
|
11
|
-
}
|
|
12
|
-
function toBigInt(permissions) {
|
|
13
|
-
let bigIntPermissions = 0n;
|
|
14
|
-
permissions.map((permission) => {
|
|
15
|
-
permission =
|
|
16
|
-
PermissionFlagsBits[
|
|
17
|
-
permission
|
|
18
|
-
.split(/ +/)
|
|
19
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
20
|
-
.join('')
|
|
21
|
-
];
|
|
22
|
-
if (typeof permission === 'bigint') bigIntPermissions += permission;
|
|
23
|
-
});
|
|
24
|
-
return bigIntPermissions;
|
|
25
|
-
}
|
|
File without changes
|
|
File without changes
|