xernerx 3.5.0 → 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.
- package/dist/cjs/build/ContextCommandBuilder.js +97 -0
- package/dist/cjs/build/EventBuilder.js +44 -0
- package/dist/cjs/build/InhibitorBuilder.js +37 -0
- package/dist/cjs/build/MessageCommandBuilder.js +100 -0
- package/{types → dist/cjs}/build/SlashCommandBuilder.d.ts +2 -1
- package/dist/cjs/build/SlashCommandBuilder.js +169 -0
- package/dist/cjs/client/XernerxClient.js +116 -0
- package/dist/{handlers → cjs/handlers}/CommandHandler.js +11 -8
- package/dist/{handlers → cjs/handlers}/EventHandler.js +6 -3
- package/dist/cjs/handlers/Handler.js +308 -0
- package/dist/{handlers → cjs/handlers}/InhibitorHandler.js +6 -3
- package/dist/cjs/main.js +112 -0
- package/dist/{models → cjs/models}/CommandArguments.js +37 -52
- package/dist/cjs/models/Events.js +307 -0
- package/dist/cjs/models/Extensions.js +26 -0
- package/dist/{tools → cjs/tools}/XernerxError.js +4 -1
- package/{types → dist/cjs}/tools/package.d.ts +11 -0
- package/dist/cjs/tools/package.js +50 -0
- package/dist/cjs/types/enums.js +38 -0
- package/dist/cjs/types/interfaces.js +2 -0
- package/dist/cjs/types/options.js +2 -0
- package/dist/cjs/types/types.js +2 -0
- package/dist/{utils → cjs/utils}/ClientUtil.js +73 -84
- package/dist/{utils → cjs/utils}/CommandUtil.js +102 -103
- package/dist/{validators → cjs/validators}/CommandValidations.js +36 -50
- package/dist/{validators → cjs/validators}/InhibitorValidations.js +12 -14
- package/dist/mjs/build/ContextCommandBuilder.d.ts +68 -0
- package/dist/mjs/build/ContextCommandBuilder.js +97 -0
- package/dist/mjs/build/EventBuilder.d.ts +21 -0
- package/dist/mjs/build/EventBuilder.js +44 -0
- package/dist/mjs/build/InhibitorBuilder.d.ts +19 -0
- package/dist/mjs/build/InhibitorBuilder.js +37 -0
- package/dist/mjs/build/MessageCommandBuilder.d.ts +59 -0
- package/dist/mjs/build/MessageCommandBuilder.js +100 -0
- package/dist/mjs/build/SlashCommandBuilder.d.ts +65 -0
- package/dist/mjs/build/SlashCommandBuilder.js +169 -0
- package/dist/mjs/client/XernerxClient.d.ts +28 -0
- package/dist/mjs/client/XernerxClient.js +116 -0
- package/dist/mjs/handlers/CommandHandler.d.ts +27 -0
- package/dist/mjs/handlers/CommandHandler.js +45 -0
- package/dist/mjs/handlers/EventHandler.d.ts +13 -0
- package/dist/mjs/handlers/EventHandler.js +19 -0
- package/dist/mjs/handlers/Handler.d.ts +57 -0
- package/dist/mjs/handlers/Handler.js +308 -0
- package/dist/mjs/handlers/InhibitorHandler.d.ts +18 -0
- package/dist/mjs/handlers/InhibitorHandler.js +24 -0
- package/dist/{main.js → mjs/main.d.ts} +20 -18
- package/dist/mjs/main.js +112 -0
- package/dist/mjs/models/CommandArguments.d.ts +17 -0
- package/dist/mjs/models/CommandArguments.js +106 -0
- package/dist/mjs/models/Events.d.ts +24 -0
- package/dist/mjs/models/Events.js +307 -0
- package/dist/mjs/models/Extensions.d.ts +7 -0
- package/dist/mjs/models/Extensions.js +26 -0
- package/dist/mjs/tools/XernerxError.d.ts +5 -0
- package/dist/mjs/tools/XernerxError.js +11 -0
- package/dist/mjs/tools/package.d.ts +49 -0
- package/dist/mjs/tools/package.js +50 -0
- package/dist/mjs/types/enums.d.ts +44 -0
- package/dist/mjs/types/enums.js +38 -0
- package/dist/mjs/types/interfaces.d.ts +25 -0
- package/dist/mjs/types/interfaces.js +2 -0
- package/dist/mjs/types/options.d.ts +241 -0
- package/dist/mjs/types/options.js +2 -0
- package/dist/mjs/types/types.d.ts +61 -0
- package/dist/mjs/types/types.js +2 -0
- package/dist/mjs/utils/ClientUtil.d.ts +25 -0
- package/dist/mjs/utils/ClientUtil.js +211 -0
- package/dist/mjs/utils/CommandUtil.d.ts +58 -0
- package/dist/mjs/utils/CommandUtil.js +247 -0
- package/dist/mjs/validators/CommandValidations.d.ts +12 -0
- package/dist/mjs/validators/CommandValidations.js +169 -0
- package/dist/mjs/validators/InhibitorValidations.d.ts +11 -0
- package/dist/mjs/validators/InhibitorValidations.js +40 -0
- package/package.json +11 -16
- package/dist/build/ContextCommandBuilder.js +0 -93
- package/dist/build/EventBuilder.js +0 -34
- package/dist/build/InhibitorBuilder.js +0 -27
- package/dist/build/MessageCommandBuilder.js +0 -90
- package/dist/build/SlashCommandBuilder.js +0 -125
- package/dist/client/XernerxClient.js +0 -101
- package/dist/handlers/Handler.js +0 -250
- package/dist/main.cjs +0 -2012
- package/dist/models/Events.js +0 -294
- package/dist/models/Extensions.js +0 -23
- package/dist/tools/package.js +0 -37
- package/dist/types/enums.js +0 -35
- package/dist/types/interfaces.js +0 -1
- package/dist/types/options.js +0 -1
- package/dist/types/types.js +0 -1
- package/dist/validators/Shapes.js +0 -1
- package/types/validators/Shapes.d.ts +0 -1
- /package/{types → dist/cjs}/build/ContextCommandBuilder.d.ts +0 -0
- /package/{types → dist/cjs}/build/EventBuilder.d.ts +0 -0
- /package/{types → dist/cjs}/build/InhibitorBuilder.d.ts +0 -0
- /package/{types → dist/cjs}/build/MessageCommandBuilder.d.ts +0 -0
- /package/{types → dist/cjs}/client/XernerxClient.d.ts +0 -0
- /package/{types → dist/cjs}/handlers/CommandHandler.d.ts +0 -0
- /package/{types → dist/cjs}/handlers/EventHandler.d.ts +0 -0
- /package/{types → dist/cjs}/handlers/Handler.d.ts +0 -0
- /package/{types → dist/cjs}/handlers/InhibitorHandler.d.ts +0 -0
- /package/{types → dist/cjs}/main.d.ts +0 -0
- /package/{types → dist/cjs}/models/CommandArguments.d.ts +0 -0
- /package/{types → dist/cjs}/models/Events.d.ts +0 -0
- /package/{types → dist/cjs}/models/Extensions.d.ts +0 -0
- /package/{types → dist/cjs}/tools/XernerxError.d.ts +0 -0
- /package/{types → dist/cjs}/types/enums.d.ts +0 -0
- /package/{types → dist/cjs}/types/interfaces.d.ts +0 -0
- /package/{types → dist/cjs}/types/options.d.ts +0 -0
- /package/{types → dist/cjs}/types/types.d.ts +0 -0
- /package/{types → dist/cjs}/utils/ClientUtil.d.ts +0 -0
- /package/{types → dist/cjs}/utils/CommandUtil.d.ts +0 -0
- /package/{types → dist/cjs}/validators/CommandValidations.d.ts +0 -0
- /package/{types → dist/cjs}/validators/InhibitorValidations.d.ts +0 -0
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xernerx",
|
|
3
|
-
"version": "3.5.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "3.5.2",
|
|
5
4
|
"description": "A bot framework for discord.js.",
|
|
6
|
-
"main": "dist/main.js",
|
|
5
|
+
"main": "dist/cjs/main.js",
|
|
6
|
+
"module": "dist/mjs/main.js",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"discord.js",
|
|
9
9
|
"discord",
|
|
@@ -17,13 +17,6 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"homepage": "https://xernerx.github.io/xernerx/home.html",
|
|
19
19
|
"packageManager": "npm@8.5.5",
|
|
20
|
-
"exports": {
|
|
21
|
-
"import": "./dist/main.js",
|
|
22
|
-
"require": "./dist/main.cjs",
|
|
23
|
-
"types": "./types",
|
|
24
|
-
"node": null,
|
|
25
|
-
"default": null
|
|
26
|
-
},
|
|
27
20
|
"scripts": {
|
|
28
21
|
"start": "npm i && npm fund && npm audit fix --force && npm link && tsc -w",
|
|
29
22
|
"patch": "npm run write && git add . && npm run commit && npm version patch && npm publish && git push",
|
|
@@ -31,8 +24,11 @@
|
|
|
31
24
|
"major": "npm run write && git add . && npm run commit && npm version major && npm publish && git push",
|
|
32
25
|
"site": "git add docs && npm run commit && git push",
|
|
33
26
|
"commit": "node ../.scripts/commit.js",
|
|
34
|
-
"write": "npm run build && node ../.scripts/rewritePackage.js ",
|
|
35
|
-
"
|
|
27
|
+
"write": "npm run build && npm run format && node ../.scripts/rewritePackage.js ",
|
|
28
|
+
"format": "npx prettier --write src dist",
|
|
29
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
30
|
+
"build:esm": "tsc",
|
|
31
|
+
"build:cjs": "tsc --module CommonJS --outDir dist/cjs"
|
|
36
32
|
},
|
|
37
33
|
"repository": {
|
|
38
34
|
"type": "git",
|
|
@@ -43,14 +39,13 @@
|
|
|
43
39
|
},
|
|
44
40
|
"dependencies": {
|
|
45
41
|
"@sapphire/shapeshift": "^3.8.1",
|
|
46
|
-
"discord.js": "^14.7.
|
|
47
|
-
"dumfunctions": "^2.
|
|
48
|
-
"xernerx-extension-builder": "^0.0.
|
|
42
|
+
"discord.js": "^14.7.1",
|
|
43
|
+
"dumfunctions": "^2.1.2",
|
|
44
|
+
"xernerx-extension-builder": "^0.0.8",
|
|
49
45
|
"zod": "^3.20.6"
|
|
50
46
|
},
|
|
51
47
|
"devDependencies": {
|
|
52
48
|
"prettier": "^2.8.4",
|
|
53
|
-
"tsup": "^6.6.0",
|
|
54
49
|
"typescript": "^4.9.5"
|
|
55
50
|
}
|
|
56
51
|
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ContextMenuCommandBuilder } from 'discord.js';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
4
|
-
/**
|
|
5
|
-
* @description The command builder for context commands.
|
|
6
|
-
* @param {String} id - The unique ID of the command.
|
|
7
|
-
* @param {ContextCommandOptions} options - The command options.
|
|
8
|
-
*/
|
|
9
|
-
export default class ContextCommandBuilder {
|
|
10
|
-
id;
|
|
11
|
-
data;
|
|
12
|
-
name;
|
|
13
|
-
type;
|
|
14
|
-
description;
|
|
15
|
-
info;
|
|
16
|
-
category;
|
|
17
|
-
channelType;
|
|
18
|
-
cooldown;
|
|
19
|
-
ignore;
|
|
20
|
-
strict;
|
|
21
|
-
permissions;
|
|
22
|
-
defer;
|
|
23
|
-
client;
|
|
24
|
-
constructor(id, options) {
|
|
25
|
-
this.id = id;
|
|
26
|
-
this.data = new ContextMenuCommandBuilder();
|
|
27
|
-
if (options.name)
|
|
28
|
-
this.data.setName(options.name);
|
|
29
|
-
if (options.type)
|
|
30
|
-
this.data.setType(options.type);
|
|
31
|
-
if (options.permissions?.users)
|
|
32
|
-
this.data.setDefaultMemberPermissions(options.permissions?.users);
|
|
33
|
-
if (options.permissions?.dm === false)
|
|
34
|
-
this.data.setDMPermission(options.permissions?.dm);
|
|
35
|
-
if (options.nameLocalizations)
|
|
36
|
-
this.data.setNameLocalizations(options.nameLocalizations);
|
|
37
|
-
z.object({
|
|
38
|
-
description: z.string(),
|
|
39
|
-
info: z.string(),
|
|
40
|
-
category: z.string(),
|
|
41
|
-
channelType: z.array(z.number()).or(z.number()),
|
|
42
|
-
cooldown: z.number(),
|
|
43
|
-
ignore: z.object({
|
|
44
|
-
owner: z.boolean(),
|
|
45
|
-
users: z.array(z.string()),
|
|
46
|
-
channels: z.array(z.string()),
|
|
47
|
-
guilds: z.array(z.string()),
|
|
48
|
-
}),
|
|
49
|
-
strict: z.object({
|
|
50
|
-
owner: z.boolean(),
|
|
51
|
-
users: z.array(z.string()),
|
|
52
|
-
channels: z.array(z.string()),
|
|
53
|
-
guilds: z.array(z.string()),
|
|
54
|
-
}),
|
|
55
|
-
permissions: z.object({
|
|
56
|
-
client: z.array(z.string()),
|
|
57
|
-
users: z.array(z.string()),
|
|
58
|
-
dm: z.boolean(),
|
|
59
|
-
}),
|
|
60
|
-
defer: z.object({
|
|
61
|
-
reply: z.boolean(),
|
|
62
|
-
ephemeral: z.boolean(),
|
|
63
|
-
fetch: z.boolean(),
|
|
64
|
-
}),
|
|
65
|
-
})
|
|
66
|
-
.deepPartial()
|
|
67
|
-
.parse(options);
|
|
68
|
-
this.name = options.name;
|
|
69
|
-
this.type = options.type;
|
|
70
|
-
this.description = options.description;
|
|
71
|
-
this.info = options.info;
|
|
72
|
-
this.category = options.category;
|
|
73
|
-
this.channelType = options.channelType;
|
|
74
|
-
this.cooldown = options.cooldown;
|
|
75
|
-
this.ignore = options.ignore;
|
|
76
|
-
this.strict = options.strict;
|
|
77
|
-
this.permissions = options.permissions;
|
|
78
|
-
this.defer = options.defer;
|
|
79
|
-
this.client = XernerxClient;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @param {Interaction} interaction - The Discord interaction event data.
|
|
83
|
-
* @description make any preconditions here.
|
|
84
|
-
* TODO - update description
|
|
85
|
-
*/
|
|
86
|
-
async conditions(interaction, args) { }
|
|
87
|
-
/**
|
|
88
|
-
* @param {Interaction} interaction - The Discord interaction event data.
|
|
89
|
-
* @description Make your custom command here.
|
|
90
|
-
* TODO - update description
|
|
91
|
-
*/
|
|
92
|
-
async exec(interaction, args) { }
|
|
93
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
/**
|
|
4
|
-
* @description - The event builder for events.
|
|
5
|
-
* @param {String} id - The unique ID of the event.
|
|
6
|
-
* @param {EventOptions} options - The event options.
|
|
7
|
-
*/
|
|
8
|
-
export default class EventBuilder {
|
|
9
|
-
id;
|
|
10
|
-
name;
|
|
11
|
-
emitter;
|
|
12
|
-
type;
|
|
13
|
-
once;
|
|
14
|
-
client;
|
|
15
|
-
constructor(id, options) {
|
|
16
|
-
this.id = id;
|
|
17
|
-
z.object({
|
|
18
|
-
name: z.string(),
|
|
19
|
-
emitter: z.string().optional(),
|
|
20
|
-
type: z.string().optional(),
|
|
21
|
-
once: z.boolean().optional(),
|
|
22
|
-
}).parse(options);
|
|
23
|
-
this.name = options.name;
|
|
24
|
-
this.emitter = options.emitter || 'client';
|
|
25
|
-
this.type = options.type || 'discord';
|
|
26
|
-
this.once = options.once || false;
|
|
27
|
-
this.client = XernerxClient;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @description run your custom event here.
|
|
31
|
-
* TODO - update description
|
|
32
|
-
*/
|
|
33
|
-
async run() { }
|
|
34
|
-
}
|