xernerx 3.4.2 → 3.5.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/README.md +10 -10
- package/dist/build/ContextCommandBuilder.js +93 -88
- package/dist/build/EventBuilder.js +34 -35
- package/dist/build/InhibitorBuilder.js +27 -28
- package/dist/build/MessageCommandBuilder.js +90 -80
- package/dist/build/SlashCommandBuilder.js +125 -118
- package/dist/client/XernerxClient.js +101 -81
- package/dist/handlers/CommandHandler.js +42 -42
- package/dist/handlers/EventHandler.js +16 -16
- package/dist/handlers/Handler.js +250 -250
- package/dist/handlers/InhibitorHandler.js +21 -21
- package/dist/main.cjs +2012 -0
- package/dist/main.js +42 -42
- package/dist/models/CommandArguments.js +121 -123
- package/dist/models/Events.js +294 -304
- package/dist/models/Extensions.js +23 -23
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/package.js +37 -41
- package/dist/types/enums.js +35 -35
- package/dist/types/interfaces.js +1 -1
- package/dist/types/options.js +1 -1
- package/dist/types/types.js +1 -1
- package/dist/utils/ClientUtil.js +222 -218
- package/dist/utils/CommandUtil.js +248 -260
- package/dist/validators/CommandValidations.js +183 -185
- package/dist/validators/InhibitorValidations.js +42 -42
- package/dist/validators/Shapes.js +1 -0
- package/package.json +54 -39
- package/types/build/ContextCommandBuilder.d.ts +68 -0
- package/{dist → types}/build/EventBuilder.d.ts +21 -17
- package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
- package/types/build/MessageCommandBuilder.d.ts +59 -0
- package/types/build/SlashCommandBuilder.d.ts +64 -0
- package/{dist → types}/client/XernerxClient.d.ts +28 -28
- package/{dist → types}/handlers/CommandHandler.d.ts +27 -26
- package/{dist → types}/handlers/EventHandler.d.ts +13 -12
- package/{dist → types}/handlers/Handler.d.ts +57 -57
- package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -17
- package/{dist → types}/main.d.ts +44 -30
- package/{dist → types}/models/CommandArguments.d.ts +17 -17
- package/{dist → types}/models/Events.d.ts +24 -24
- package/{dist → types}/models/Extensions.d.ts +7 -7
- package/{dist → types}/tools/XernerxError.d.ts +5 -5
- package/{dist → types}/tools/package.d.ts +38 -38
- package/types/types/enums.d.ts +44 -0
- package/{dist → types}/types/interfaces.d.ts +25 -25
- package/{dist → types}/types/options.d.ts +241 -206
- package/{dist → types}/types/types.d.ts +61 -32
- package/{dist → types}/utils/ClientUtil.d.ts +25 -25
- package/{dist → types}/utils/CommandUtil.d.ts +58 -56
- package/{dist → types}/validators/CommandValidations.d.ts +12 -7
- package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
- package/types/validators/Shapes.d.ts +1 -0
- package/dist/build/ContextCommandBuilder.d.ts +0 -42
- package/dist/build/MessageCommandBuilder.d.ts +0 -42
- package/dist/build/SlashCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.js +0 -84
- package/dist/build/XEventBuilder.d.ts +0 -17
- package/dist/build/XEventBuilder.js +0 -35
- package/dist/build/XInhibitorBuilder.d.ts +0 -20
- package/dist/build/XInhibitorBuilder.js +0 -28
- package/dist/build/XMessageCommandBuilder.d.ts +0 -42
- package/dist/build/XMessageCommandBuilder.js +0 -80
- package/dist/build/XSlashCommandBuilder.d.ts +0 -36
- package/dist/build/XSlashCommandBuilder.js +0 -114
- package/dist/models/CommandValidations.d.ts +0 -4
- package/dist/models/CommandValidations.js +0 -183
- package/dist/models/InhibitorValidations.d.ts +0 -12
- package/dist/models/InhibitorValidations.js +0 -42
- package/dist/types/enums.d.ts +0 -35
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,2012 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/main.ts
|
|
32
|
+
var main_exports = {};
|
|
33
|
+
__export(main_exports, {
|
|
34
|
+
CommandType: () => CommandType,
|
|
35
|
+
ContextCommandBuilder: () => ContextCommandBuilder,
|
|
36
|
+
ContextCommandType: () => ContextCommandType,
|
|
37
|
+
EventBuilder: () => EventBuilder,
|
|
38
|
+
EventEmitterType: () => EventEmitterType,
|
|
39
|
+
ExtensionBuilder: () => import_xernerx_extension_builder.default,
|
|
40
|
+
InhibitorBuilder: () => InhibitorBuilder,
|
|
41
|
+
InhibitorType: () => InhibitorType,
|
|
42
|
+
MessageCommandBuilder: () => MessageCommandBuilder,
|
|
43
|
+
SlashCommandBuilder: () => SlashCommandBuilder,
|
|
44
|
+
XernerxClient: () => XernerxClient,
|
|
45
|
+
XernerxError: () => XernerxError,
|
|
46
|
+
default: () => main_default,
|
|
47
|
+
xernerxVersion: () => xernerxVersion
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(main_exports);
|
|
50
|
+
__reExport(main_exports, require("discord.js"), module.exports);
|
|
51
|
+
__reExport(main_exports, require("dumfunctions"), module.exports);
|
|
52
|
+
var import_xernerx_extension_builder = __toESM(require("xernerx-extension-builder"), 1);
|
|
53
|
+
|
|
54
|
+
// src/client/XernerxClient.ts
|
|
55
|
+
var import_discord4 = require("discord.js");
|
|
56
|
+
var import_zod = require("zod");
|
|
57
|
+
var import_dumfunctions4 = require("dumfunctions");
|
|
58
|
+
|
|
59
|
+
// src/tools/XernerxError.ts
|
|
60
|
+
var XernerxError = class {
|
|
61
|
+
name;
|
|
62
|
+
message;
|
|
63
|
+
constructor(message) {
|
|
64
|
+
this.name = "XernerxError";
|
|
65
|
+
this.message = message || "";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/utils/ClientUtil.ts
|
|
70
|
+
var ClientUtil = class {
|
|
71
|
+
client;
|
|
72
|
+
constructor(client) {
|
|
73
|
+
this.client = client;
|
|
74
|
+
}
|
|
75
|
+
uptime(timestamp) {
|
|
76
|
+
if (!timestamp)
|
|
77
|
+
timestamp = this.client.uptime || 0;
|
|
78
|
+
let totalSeconds = timestamp / 1e3;
|
|
79
|
+
let years = Math.floor(totalSeconds / 31536e3);
|
|
80
|
+
totalSeconds %= 31536e3;
|
|
81
|
+
let days = Math.floor(totalSeconds / 86400);
|
|
82
|
+
totalSeconds %= 86400;
|
|
83
|
+
let hours = Math.floor(totalSeconds / 3600);
|
|
84
|
+
totalSeconds %= 3600;
|
|
85
|
+
let minutes = Math.floor(totalSeconds / 60);
|
|
86
|
+
let seconds = Math.floor(totalSeconds % 60);
|
|
87
|
+
if (years >= 1)
|
|
88
|
+
return `${years}y ${days}d ${hours}h ${minutes}m`;
|
|
89
|
+
else if (days >= 1)
|
|
90
|
+
return `${days}d ${hours}h ${minutes}m`;
|
|
91
|
+
else if (hours >= 1)
|
|
92
|
+
return `${hours}h ${minutes}m`;
|
|
93
|
+
else if (minutes >= 1)
|
|
94
|
+
return `${minutes}m ${seconds}s`;
|
|
95
|
+
else
|
|
96
|
+
return `${seconds}s`;
|
|
97
|
+
}
|
|
98
|
+
getSubcommands(name) {
|
|
99
|
+
if (!name || typeof name !== "string")
|
|
100
|
+
throw new XernerxError(`Expected name to be of type string, received ${typeof name} instead!`);
|
|
101
|
+
const commands = [];
|
|
102
|
+
this.getAllCommands().filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) == name?.toLowerCase()).map((c) => {
|
|
103
|
+
if (c?.data?.options?.length > 0) {
|
|
104
|
+
c?.data?.options?.map((option) => {
|
|
105
|
+
if (!option?.type) {
|
|
106
|
+
if (option?.options?.length > 0) {
|
|
107
|
+
option?.options?.map((opt) => {
|
|
108
|
+
if (!opt.type) {
|
|
109
|
+
commands.push({
|
|
110
|
+
name: c.data.name,
|
|
111
|
+
formattedName: `${c.data.name} ${option.name} ${opt.name}`,
|
|
112
|
+
description: opt.description,
|
|
113
|
+
category: c.category || null,
|
|
114
|
+
commandType: c.commandType
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
commands.push({
|
|
118
|
+
name: c.data.name,
|
|
119
|
+
formattedName: `${c.data.name} ${option.name}`,
|
|
120
|
+
description: option.description,
|
|
121
|
+
category: c.category || null,
|
|
122
|
+
commandType: c.commandType
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
commands.push({
|
|
128
|
+
name: c.data.name,
|
|
129
|
+
formattedName: `${c.data.name} ${option.name}`,
|
|
130
|
+
description: option.description,
|
|
131
|
+
category: c.category || null,
|
|
132
|
+
commandType: c.commandType
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
commands.push({
|
|
137
|
+
name: c.data.name,
|
|
138
|
+
formattedName: `${c.data.name}`,
|
|
139
|
+
description: c.data.description,
|
|
140
|
+
category: c.category || null,
|
|
141
|
+
commandType: c.commandType
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
commands.push({
|
|
147
|
+
name: c.data?.name || c.name,
|
|
148
|
+
formattedName: `${c.data?.name || c.name}`,
|
|
149
|
+
description: c.data?.description || c.description,
|
|
150
|
+
category: c.category || null,
|
|
151
|
+
commandType: c.commandType
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return commands;
|
|
156
|
+
}
|
|
157
|
+
isOwner(userId) {
|
|
158
|
+
if (!userId)
|
|
159
|
+
throw new XernerxError("No ID specified");
|
|
160
|
+
let owners = this.client.settings.ownerId;
|
|
161
|
+
if (!owners)
|
|
162
|
+
return false;
|
|
163
|
+
if (typeof owners === "string")
|
|
164
|
+
owners = [owners];
|
|
165
|
+
return owners.includes(userId);
|
|
166
|
+
}
|
|
167
|
+
getAllCommands() {
|
|
168
|
+
const cmds = [];
|
|
169
|
+
for (const commands of Object.values(this.client.commands)) {
|
|
170
|
+
commands.map((cmd) => cmds.push(cmd));
|
|
171
|
+
}
|
|
172
|
+
return cmds;
|
|
173
|
+
}
|
|
174
|
+
getAllMessageCommands() {
|
|
175
|
+
const cmds = [];
|
|
176
|
+
this.client.commands.message.map((cmd) => cmds.push(cmd));
|
|
177
|
+
return cmds;
|
|
178
|
+
}
|
|
179
|
+
getAllSlashCommands() {
|
|
180
|
+
const cmds = [];
|
|
181
|
+
this.client.commands.slash.map((cmd) => cmds.push(cmd));
|
|
182
|
+
return cmds;
|
|
183
|
+
}
|
|
184
|
+
getAllContextCommands() {
|
|
185
|
+
const cmds = [];
|
|
186
|
+
this.client.commands.context.map((cmd) => cmds.push(cmd));
|
|
187
|
+
return cmds;
|
|
188
|
+
}
|
|
189
|
+
setPresence(options) {
|
|
190
|
+
const client = this.client;
|
|
191
|
+
function pres() {
|
|
192
|
+
client.user?.setPresence({
|
|
193
|
+
activities: [
|
|
194
|
+
{
|
|
195
|
+
name: options.text || void 0,
|
|
196
|
+
type: options.type || void 0,
|
|
197
|
+
url: options.link || void 0
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
status: options.status || void 0
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
pres();
|
|
204
|
+
if (options.interval) {
|
|
205
|
+
setInterval(() => {
|
|
206
|
+
pres();
|
|
207
|
+
}, options.interval);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
getCooldowns(id, command) {
|
|
211
|
+
let cooldowns = [];
|
|
212
|
+
for (const [key, value] of Object.entries(this.client.cache)) {
|
|
213
|
+
if (!["cooldowns", "messageCommands", "slashCommands", "contextCommands", "commands"].includes(key))
|
|
214
|
+
continue;
|
|
215
|
+
if (key === "commands") {
|
|
216
|
+
if (command) {
|
|
217
|
+
value.map((x) => {
|
|
218
|
+
const name = x.name.split(/-/);
|
|
219
|
+
name.pop();
|
|
220
|
+
if (name.join("-") === id + "-" + command) {
|
|
221
|
+
cooldowns.push(x);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
value.map((x) => {
|
|
226
|
+
if (x.name.split(/-/).shift() === id) {
|
|
227
|
+
cooldowns.push(x);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
if (value.has(id)) {
|
|
233
|
+
const x = value.get(id);
|
|
234
|
+
cooldowns.push(x);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return cooldowns;
|
|
239
|
+
}
|
|
240
|
+
getCooldownTimers(id, command) {
|
|
241
|
+
let cooldowns = [];
|
|
242
|
+
for (const [key, value] of Object.entries(this.client.cache)) {
|
|
243
|
+
if (!["cooldowns", "messageCommands", "slashCommands", "contextCommands", "commands"].includes(key))
|
|
244
|
+
continue;
|
|
245
|
+
if (key === "commands") {
|
|
246
|
+
if (command) {
|
|
247
|
+
value.map((x) => {
|
|
248
|
+
const name = x.name.split(/-/);
|
|
249
|
+
name.pop();
|
|
250
|
+
if (name.join("-") === id + "-" + command) {
|
|
251
|
+
cooldowns.push({
|
|
252
|
+
[x.commandName]: x.endsAt - Date.now()
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
value.map((x) => {
|
|
258
|
+
if (x.name.split(/-/).shift() === id) {
|
|
259
|
+
cooldowns.push({
|
|
260
|
+
[x.commandName]: x.endsAt - Date.now()
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
if (value.has(id)) {
|
|
267
|
+
const x = value.get(id);
|
|
268
|
+
cooldowns.push({ [key]: x.endsAt - Date.now() });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const sort = cooldowns.map((x) => Object.entries(x).shift()).sort((a, b) => b[1] - a[1]);
|
|
273
|
+
cooldowns = [];
|
|
274
|
+
sort.map(([key, value]) => cooldowns.push({ [key]: value }));
|
|
275
|
+
return cooldowns;
|
|
276
|
+
}
|
|
277
|
+
async defer(time) {
|
|
278
|
+
return new Promise((resolve2) => setTimeout(resolve2, time || 0));
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/handlers/Handler.ts
|
|
283
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
284
|
+
var path = __toESM(require("path"), 1);
|
|
285
|
+
|
|
286
|
+
// src/types/enums.ts
|
|
287
|
+
var InhibitorType = /* @__PURE__ */ ((InhibitorType2) => {
|
|
288
|
+
InhibitorType2["Member"] = "Member";
|
|
289
|
+
InhibitorType2["User"] = "User";
|
|
290
|
+
InhibitorType2["Guild"] = "Guild";
|
|
291
|
+
InhibitorType2["SlashCommand"] = "SlashCommand";
|
|
292
|
+
InhibitorType2["MessageCommand"] = "MessageCommand";
|
|
293
|
+
InhibitorType2["ContextCommand"] = "ContextCommand";
|
|
294
|
+
InhibitorType2["Command"] = "Command";
|
|
295
|
+
InhibitorType2["Message"] = "Message";
|
|
296
|
+
InhibitorType2["Interaction"] = "Interaction";
|
|
297
|
+
InhibitorType2["Channel"] = "Channel";
|
|
298
|
+
return InhibitorType2;
|
|
299
|
+
})(InhibitorType || {});
|
|
300
|
+
var CommandType = /* @__PURE__ */ ((CommandType2) => {
|
|
301
|
+
CommandType2["Message"] = "MessageCommand";
|
|
302
|
+
CommandType2["Slash"] = "SlashCommand";
|
|
303
|
+
CommandType2["Context"] = "ContextCommand";
|
|
304
|
+
CommandType2["Event"] = "Event";
|
|
305
|
+
CommandType2["Inhibitor"] = "Inhibitor";
|
|
306
|
+
CommandType2["MessageCommand"] = "MessageCommand";
|
|
307
|
+
CommandType2["SlashCommand"] = "SlashCommand";
|
|
308
|
+
CommandType2["ContextCommand"] = "ContextCommand";
|
|
309
|
+
return CommandType2;
|
|
310
|
+
})(CommandType || {});
|
|
311
|
+
var ContextCommandType = /* @__PURE__ */ ((ContextCommandType2) => {
|
|
312
|
+
ContextCommandType2[ContextCommandType2["Message"] = 3] = "Message";
|
|
313
|
+
ContextCommandType2[ContextCommandType2["User"] = 2] = "User";
|
|
314
|
+
return ContextCommandType2;
|
|
315
|
+
})(ContextCommandType || {});
|
|
316
|
+
var EventEmitterType = /* @__PURE__ */ ((EventEmitterType2) => {
|
|
317
|
+
EventEmitterType2["Client"] = "client";
|
|
318
|
+
EventEmitterType2["Rest"] = "rest";
|
|
319
|
+
EventEmitterType2["Process"] = "process";
|
|
320
|
+
return EventEmitterType2;
|
|
321
|
+
})(EventEmitterType || {});
|
|
322
|
+
|
|
323
|
+
// src/handlers/Handler.ts
|
|
324
|
+
var import_shapeshift = require("@sapphire/shapeshift");
|
|
325
|
+
var import_dumfunctions = require("dumfunctions");
|
|
326
|
+
var Handler = class {
|
|
327
|
+
client;
|
|
328
|
+
commands;
|
|
329
|
+
readyTimestamp;
|
|
330
|
+
constructor(client) {
|
|
331
|
+
this.client = client;
|
|
332
|
+
this.commands = [];
|
|
333
|
+
this.readyTimestamp = Number(Date.now());
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* @description - The loader for the message commands.
|
|
337
|
+
* @param {MessageCommandOptions} options - The options for the message command loader.
|
|
338
|
+
*/
|
|
339
|
+
loadAllMessageCommands(options) {
|
|
340
|
+
this.client.handlerOptions.message = import_shapeshift.s.object({
|
|
341
|
+
directory: import_shapeshift.s.string,
|
|
342
|
+
prefix: import_shapeshift.s.union(import_shapeshift.s.string, import_shapeshift.s.array(import_shapeshift.s.string)),
|
|
343
|
+
allowMention: import_shapeshift.s.boolean.default(false),
|
|
344
|
+
cooldown: import_shapeshift.s.number.default(0),
|
|
345
|
+
userPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
346
|
+
clientPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
347
|
+
handleEdits: import_shapeshift.s.boolean.default(false),
|
|
348
|
+
handleDeletes: import_shapeshift.s.boolean.default(false),
|
|
349
|
+
handleTyping: import_shapeshift.s.boolean.default(false),
|
|
350
|
+
logging: import_shapeshift.s.boolean.default(false)
|
|
351
|
+
}).parse(options);
|
|
352
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
353
|
+
for (const file of files) {
|
|
354
|
+
this.load(options.directory, file, "MessageCommand" /* MessageCommand */);
|
|
355
|
+
loaded.push(file.replace(".js", ""));
|
|
356
|
+
}
|
|
357
|
+
if (this.client.handlerOptions.message?.logging)
|
|
358
|
+
console.info(
|
|
359
|
+
import_dumfunctions.Style.log(`Xernerx | Loaded ${loaded.length} message commands: ${loaded.join(", ")}.`, {
|
|
360
|
+
color: import_dumfunctions.Style.TextColor.Cyan
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @description - The loader for the slash commands.
|
|
366
|
+
* @param {SlashCommandOptions} options - The options for the slash command loader.
|
|
367
|
+
*/
|
|
368
|
+
loadAllSlashCommands(options) {
|
|
369
|
+
this.client.handlerOptions.slash = import_shapeshift.s.object({
|
|
370
|
+
directory: import_shapeshift.s.string,
|
|
371
|
+
guildId: import_shapeshift.s.string,
|
|
372
|
+
global: import_shapeshift.s.boolean,
|
|
373
|
+
cooldown: import_shapeshift.s.number.default(0),
|
|
374
|
+
userPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
375
|
+
clientPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
376
|
+
logging: import_shapeshift.s.boolean.default(false),
|
|
377
|
+
defer: import_shapeshift.s.object({
|
|
378
|
+
reply: import_shapeshift.s.boolean.optional,
|
|
379
|
+
ephemeral: import_shapeshift.s.boolean.optional,
|
|
380
|
+
fetchReply: import_shapeshift.s.boolean.optional
|
|
381
|
+
}).optional
|
|
382
|
+
}).parse(options);
|
|
383
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
384
|
+
for (const file of files) {
|
|
385
|
+
this.load(options.directory, file, "SlashCommand" /* SlashCommand */);
|
|
386
|
+
loaded.push(file.replace(".js", ""));
|
|
387
|
+
}
|
|
388
|
+
if (this.client.handlerOptions.slash?.logging)
|
|
389
|
+
console.info(
|
|
390
|
+
import_dumfunctions.Style.log(`Xernerx | Loaded ${loaded.length} slash commands: ${loaded.join(", ")}.`, {
|
|
391
|
+
color: import_dumfunctions.Style.TextColor.Cyan
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @description - The loader for the context commands.
|
|
397
|
+
* @param {ContextCommandOptions} options - The options for the context command loader.
|
|
398
|
+
*/
|
|
399
|
+
loadAllContextCommands(options) {
|
|
400
|
+
this.client.handlerOptions.context = import_shapeshift.s.object({
|
|
401
|
+
directory: import_shapeshift.s.string,
|
|
402
|
+
guildId: import_shapeshift.s.string,
|
|
403
|
+
global: import_shapeshift.s.boolean,
|
|
404
|
+
cooldown: import_shapeshift.s.number.default(0),
|
|
405
|
+
userPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
406
|
+
clientPermissions: import_shapeshift.s.array(import_shapeshift.s.bigint).default([]),
|
|
407
|
+
logging: import_shapeshift.s.boolean.default(false),
|
|
408
|
+
defer: import_shapeshift.s.object({
|
|
409
|
+
reply: import_shapeshift.s.boolean.optional,
|
|
410
|
+
ephemeral: import_shapeshift.s.boolean.optional,
|
|
411
|
+
fetchReply: import_shapeshift.s.boolean.optional
|
|
412
|
+
}).optional
|
|
413
|
+
}).parse(options);
|
|
414
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
415
|
+
for (const file of files) {
|
|
416
|
+
this.load(options.directory, file, "ContextCommand" /* ContextCommand */);
|
|
417
|
+
loaded.push(file.replace(".js", ""));
|
|
418
|
+
}
|
|
419
|
+
if (this.client.handlerOptions.context?.logging)
|
|
420
|
+
console.info(
|
|
421
|
+
import_dumfunctions.Style.log(`Xernerx | Loaded ${loaded.length} context commands: ${loaded.join(", ")}.`, {
|
|
422
|
+
color: import_dumfunctions.Style.TextColor.Cyan
|
|
423
|
+
})
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* @description - The loader for the events.
|
|
428
|
+
* @param {EventLoadOptions} options - The options for the event loader.
|
|
429
|
+
*/
|
|
430
|
+
loadAllEvents(options) {
|
|
431
|
+
this.client.handlerOptions.events = import_shapeshift.s.object({
|
|
432
|
+
directory: import_shapeshift.s.string,
|
|
433
|
+
logging: import_shapeshift.s.boolean.default(false)
|
|
434
|
+
}).parse(options);
|
|
435
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
436
|
+
(async () => {
|
|
437
|
+
for (const file of files) {
|
|
438
|
+
try {
|
|
439
|
+
options.directory.split(/\//).shift();
|
|
440
|
+
let event = (await import(`file://${path.resolve(options.directory)}/${file}`)).default;
|
|
441
|
+
event = new event();
|
|
442
|
+
event.client = this.client;
|
|
443
|
+
event.commandType = "Event" /* Event */;
|
|
444
|
+
this.client.events.set(event.name, event);
|
|
445
|
+
this.emitter(event);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error(import_dumfunctions.Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: import_dumfunctions.Style.BackgroundColor.Red }));
|
|
448
|
+
}
|
|
449
|
+
loaded.push(file.replace(".js", ""));
|
|
450
|
+
}
|
|
451
|
+
if (this.client.handlerOptions.events?.logging)
|
|
452
|
+
console.info(import_dumfunctions.Style.log(`Xernerx | Loaded ${loaded.length} events: ${loaded.join(", ")}.`, { color: import_dumfunctions.Style.TextColor.Cyan }));
|
|
453
|
+
})();
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* @description - The loader for the inhibitors.
|
|
457
|
+
* @param {InhibitorLoadOptions} options - The options for the inhibitor loader.
|
|
458
|
+
*/
|
|
459
|
+
loadAllInhibitors(options) {
|
|
460
|
+
this.client.handlerOptions.inhibitors = import_shapeshift.s.object({
|
|
461
|
+
directory: import_shapeshift.s.string,
|
|
462
|
+
logging: import_shapeshift.s.boolean.default(false)
|
|
463
|
+
}).parse(options);
|
|
464
|
+
const files = this.readdir(options.directory), loaded = [];
|
|
465
|
+
for (const file of files) {
|
|
466
|
+
this.load(options.directory, file, "Inhibitor" /* Inhibitor */);
|
|
467
|
+
loaded.push(file.replace(".js", ""));
|
|
468
|
+
}
|
|
469
|
+
if (this.client.handlerOptions.inhibitors?.logging)
|
|
470
|
+
console.info(
|
|
471
|
+
import_dumfunctions.Style.log(`Xernerx | Loaded ${loaded.length} inhibitors: ${loaded.join(", ")}.`, {
|
|
472
|
+
color: import_dumfunctions.Style.TextColor.Cyan
|
|
473
|
+
})
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* @description - a reader for directories
|
|
478
|
+
* @param {string} dir - the directory to look for.
|
|
479
|
+
* @returns array of files.
|
|
480
|
+
*/
|
|
481
|
+
readdir(dir) {
|
|
482
|
+
try {
|
|
483
|
+
return import_fs.default.readdirSync(path.resolve(dir)).filter((file) => file.endsWith(".js"));
|
|
484
|
+
} catch (error) {
|
|
485
|
+
console.error(import_dumfunctions.Style.log(`Xernerx | Couldn't read ${dir} because <${error}>.`, { color: import_dumfunctions.Style.BackgroundColor.Red }));
|
|
486
|
+
}
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @description file loader.
|
|
491
|
+
* @param {string} dir - the directory.
|
|
492
|
+
* @param {string} file - the file in the directory.
|
|
493
|
+
* @param {string} type - the type of file.
|
|
494
|
+
* @returns undefined
|
|
495
|
+
*/
|
|
496
|
+
async load(dir, file, type) {
|
|
497
|
+
try {
|
|
498
|
+
dir.split(/\//).shift();
|
|
499
|
+
let command = (await import(`file://${path.resolve(dir)}/${file}`)).default;
|
|
500
|
+
command = new command();
|
|
501
|
+
command.client = this.client;
|
|
502
|
+
command.commandType = type;
|
|
503
|
+
command.filepath = `${path.resolve(dir)}\\${file}`;
|
|
504
|
+
command.file = file;
|
|
505
|
+
if (type === "MessageCommand" /* MessageCommand */)
|
|
506
|
+
this.client.commands.message.set(command?.name || command?.name, command);
|
|
507
|
+
if (type === "SlashCommand" /* SlashCommand */) {
|
|
508
|
+
this.client.commands.slash.set(command?.data?.name || command?.name, command);
|
|
509
|
+
}
|
|
510
|
+
if (type === "ContextCommand" /* ContextCommand */) {
|
|
511
|
+
this.client.commands.context.set(command?.data?.name || command?.name, command);
|
|
512
|
+
}
|
|
513
|
+
if (type === "Event" /* Event */) {
|
|
514
|
+
this.client.events.set(command.name, command);
|
|
515
|
+
}
|
|
516
|
+
if (type === "Inhibitor" /* Inhibitor */) {
|
|
517
|
+
this.client.inhibitors.set(command.name, command);
|
|
518
|
+
}
|
|
519
|
+
} catch (error) {
|
|
520
|
+
console.error(import_dumfunctions.Style.log(`Xernerx | Couldn't load ${file} because <${error}>`, { color: import_dumfunctions.Style.BackgroundColor.Red }));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* @description the event emitter to emit all events.
|
|
525
|
+
* @param {object} event - the event to be emitted.
|
|
526
|
+
* @returns void
|
|
527
|
+
*/
|
|
528
|
+
emitter(event) {
|
|
529
|
+
const client = this.client;
|
|
530
|
+
if (event.emitter === "client") {
|
|
531
|
+
if (event.once)
|
|
532
|
+
client.once(event.name, (...args) => {
|
|
533
|
+
event.run(...args);
|
|
534
|
+
});
|
|
535
|
+
else
|
|
536
|
+
client.on(event.name, (...args) => {
|
|
537
|
+
event.run(...args);
|
|
538
|
+
});
|
|
539
|
+
} else if (event.emitter === "rest") {
|
|
540
|
+
if (event.once)
|
|
541
|
+
client.once(event.name, (...args) => {
|
|
542
|
+
event.run(...args);
|
|
543
|
+
});
|
|
544
|
+
else
|
|
545
|
+
client.on(event.name, (...args) => {
|
|
546
|
+
event.run(...args);
|
|
547
|
+
});
|
|
548
|
+
} else if (event.emitter === "process") {
|
|
549
|
+
if (event.once)
|
|
550
|
+
process.once(event.name, (...args) => {
|
|
551
|
+
event.run(...args);
|
|
552
|
+
});
|
|
553
|
+
else
|
|
554
|
+
process.on(event.name, (...args) => {
|
|
555
|
+
event.run(...args);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// src/models/Events.ts
|
|
562
|
+
var import_discord3 = require("discord.js");
|
|
563
|
+
|
|
564
|
+
// src/utils/CommandUtil.ts
|
|
565
|
+
var import_discord = require("discord.js");
|
|
566
|
+
var MessageCommandUtil = class {
|
|
567
|
+
client;
|
|
568
|
+
message;
|
|
569
|
+
constructor(client, message) {
|
|
570
|
+
this.client = client;
|
|
571
|
+
this.message = message;
|
|
572
|
+
}
|
|
573
|
+
async reply(content) {
|
|
574
|
+
if (this.client.cache.messages.has(this.message.id))
|
|
575
|
+
var existingMessage = this.client.cache.messages.get(this.message.id);
|
|
576
|
+
if (!existingMessage) {
|
|
577
|
+
const msg = await this.message.reply(content);
|
|
578
|
+
this.message.response = msg.id;
|
|
579
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
580
|
+
this.client.cache.messages.set(this.message.id, this.message);
|
|
581
|
+
setInterval(() => {
|
|
582
|
+
this.client.cache.messages.delete(this.message.id);
|
|
583
|
+
}, this.client.settings.cooldown?.cache || 3e5);
|
|
584
|
+
}
|
|
585
|
+
return msg;
|
|
586
|
+
}
|
|
587
|
+
if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
|
|
588
|
+
try {
|
|
589
|
+
const msg = await this.message.channel.messages.fetch(existingMessage.response);
|
|
590
|
+
msg.edit(content);
|
|
591
|
+
return msg;
|
|
592
|
+
} catch {
|
|
593
|
+
const msg = await this.message.reply(content);
|
|
594
|
+
this.message.response = msg.id;
|
|
595
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
596
|
+
this.client.cache.messages.set(this.message.id, this.message);
|
|
597
|
+
setInterval(() => {
|
|
598
|
+
this.client.cache.messages.delete(this.message.id);
|
|
599
|
+
}, this.client.settings.cooldown?.cache || 3e5);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
async send(content) {
|
|
605
|
+
if (this.client.cache.messages.has(this.message.id))
|
|
606
|
+
var existingMessage = this.client.cache.messages.get(this.message.id);
|
|
607
|
+
if (!existingMessage) {
|
|
608
|
+
const msg = await this.message.channel.send(content);
|
|
609
|
+
this.message.response = msg.id;
|
|
610
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
611
|
+
this.client.cache.messages.set(this.message.id, this.message);
|
|
612
|
+
setInterval(() => {
|
|
613
|
+
this.client.cache.messages.delete(this.message.id);
|
|
614
|
+
}, this.client.settings.cooldown?.cache || 3e5);
|
|
615
|
+
}
|
|
616
|
+
return msg;
|
|
617
|
+
}
|
|
618
|
+
if (existingMessage && this.client.handlerOptions.message?.handleEdits) {
|
|
619
|
+
try {
|
|
620
|
+
const msg = await this.message.channel.messages.fetch(existingMessage.response);
|
|
621
|
+
msg.edit(content);
|
|
622
|
+
return msg;
|
|
623
|
+
} catch {
|
|
624
|
+
const msg = await this.message.channel.send(content);
|
|
625
|
+
this.message.response = msg.id;
|
|
626
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
627
|
+
this.client.cache.messages.set(this.message.id, this.message);
|
|
628
|
+
setInterval(() => {
|
|
629
|
+
this.client.cache.messages.delete(this.message.id);
|
|
630
|
+
}, this.client.settings.cooldown?.cache || 3e5);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async defer(time) {
|
|
636
|
+
return new Promise((resolve2) => setTimeout(resolve2, time));
|
|
637
|
+
}
|
|
638
|
+
getCommands() {
|
|
639
|
+
return this.client.commands.message;
|
|
640
|
+
}
|
|
641
|
+
getCommandName() {
|
|
642
|
+
}
|
|
643
|
+
selectMenuPaginator(embeds, options) {
|
|
644
|
+
}
|
|
645
|
+
buttonPaginator(embeds, options) {
|
|
646
|
+
}
|
|
647
|
+
buttonMenuPaginator(embeds, options) {
|
|
648
|
+
}
|
|
649
|
+
isOwner() {
|
|
650
|
+
return this.client.util.isOwner(this.message.author.id);
|
|
651
|
+
}
|
|
652
|
+
createModal() {
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
var InteractionCommandUtil = class {
|
|
656
|
+
client;
|
|
657
|
+
interaction;
|
|
658
|
+
constructor(client, interaction) {
|
|
659
|
+
this.client = client;
|
|
660
|
+
this.interaction = interaction;
|
|
661
|
+
}
|
|
662
|
+
reply(content) {
|
|
663
|
+
return this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content);
|
|
664
|
+
}
|
|
665
|
+
async defer(time) {
|
|
666
|
+
return new Promise((resolve2) => setTimeout(resolve2, time));
|
|
667
|
+
}
|
|
668
|
+
getCommands() {
|
|
669
|
+
if (this.interaction.commandType === 1)
|
|
670
|
+
return this.client.commands.slash;
|
|
671
|
+
else
|
|
672
|
+
return this.client.commands.context;
|
|
673
|
+
}
|
|
674
|
+
getCommandName() {
|
|
675
|
+
}
|
|
676
|
+
selectMenuPaginator(embeds, options) {
|
|
677
|
+
if (!Array.isArray(embeds))
|
|
678
|
+
throw new XernerxError(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
679
|
+
if (embeds.length > 25)
|
|
680
|
+
throw new XernerxError(`Max select menu length is 25.`);
|
|
681
|
+
if (typeof options !== "object")
|
|
682
|
+
options = {};
|
|
683
|
+
if (!Array.isArray(options.components))
|
|
684
|
+
options.components = [];
|
|
685
|
+
if (!options.index) {
|
|
686
|
+
options.index = new import_discord.EmbedBuilder().setTitle("Index").setColor("Random");
|
|
687
|
+
for (const embed of embeds) {
|
|
688
|
+
options.index.addFields([
|
|
689
|
+
{
|
|
690
|
+
name: embed.data.title || "No Name",
|
|
691
|
+
value: embed.data.description || "Page",
|
|
692
|
+
inline: embeds.length > 25 / 2 ? true : false
|
|
693
|
+
}
|
|
694
|
+
]);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (!options.row) {
|
|
698
|
+
options.row = new import_discord.ActionRowBuilder();
|
|
699
|
+
if (!options.id)
|
|
700
|
+
options.id = `${this.interaction.id}-menu`;
|
|
701
|
+
options.component = new import_discord.StringSelectMenuBuilder().setCustomId(options.id).setMaxValues(1).setMinValues(1).setPlaceholder("Select a page.").addOptions({ label: "index", value: "0" });
|
|
702
|
+
embeds.map((embed, i = 0) => {
|
|
703
|
+
options?.component?.addOptions({
|
|
704
|
+
label: embed.data.title || "No Name",
|
|
705
|
+
description: embed.data.description || `Page ${i}`,
|
|
706
|
+
value: String(i + 1)
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
options.row.addComponents(options.component);
|
|
710
|
+
}
|
|
711
|
+
embeds.unshift(options.index);
|
|
712
|
+
const content = {
|
|
713
|
+
embeds: [options.index],
|
|
714
|
+
components: [options.row, ...options.components],
|
|
715
|
+
ephemeral: !!options.ephemeral
|
|
716
|
+
};
|
|
717
|
+
(options.reply === void 0 || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then(() => {
|
|
718
|
+
const collector = this.interaction.channel.createMessageComponentCollector({
|
|
719
|
+
filter: options?.filter,
|
|
720
|
+
time: options?.time || 6e4
|
|
721
|
+
}).on("collect", (interaction) => {
|
|
722
|
+
if (!interaction.customId.startsWith(this.interaction.id))
|
|
723
|
+
return;
|
|
724
|
+
interaction.update({
|
|
725
|
+
embeds: [embeds[parseInt(interaction.values[0])]]
|
|
726
|
+
});
|
|
727
|
+
}).on("end", () => {
|
|
728
|
+
this.interaction.editReply({ components: [] });
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
buttonPaginator(embeds, options) {
|
|
733
|
+
if (!Array.isArray(embeds))
|
|
734
|
+
throw new XernerxError(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
735
|
+
if (embeds.length <= 0)
|
|
736
|
+
throw new XernerxError(`The minimum embeds is 1.`);
|
|
737
|
+
if (typeof options !== "object")
|
|
738
|
+
options = {};
|
|
739
|
+
if (!Array.isArray(options.components))
|
|
740
|
+
options.components = [];
|
|
741
|
+
if (!options.row) {
|
|
742
|
+
options.row = new import_discord.ActionRowBuilder();
|
|
743
|
+
if (!options.id)
|
|
744
|
+
options.id = `${this.interaction.id}-menu`;
|
|
745
|
+
}
|
|
746
|
+
if (!options.buttons)
|
|
747
|
+
options.buttons = ["\u23EE\uFE0F", "\u25C0\uFE0F", "\u23F9\uFE0F", "\u25B6\uFE0F", "\u23ED\uFE0F"];
|
|
748
|
+
for (const button of options.buttons) {
|
|
749
|
+
options.row.addComponents(
|
|
750
|
+
new import_discord.ButtonBuilder().setCustomId(`${this.interaction.id}-${options.buttons.indexOf(button)}`).setEmoji(button).setStyle(import_discord.ButtonStyle.Primary)
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
let embed = embeds[options.index || 0];
|
|
754
|
+
const content = {
|
|
755
|
+
embeds: [embed],
|
|
756
|
+
components: [options.row, ...options.components],
|
|
757
|
+
ephemeral: !!options.ephemeral
|
|
758
|
+
};
|
|
759
|
+
(options.reply === void 0 || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then((message) => {
|
|
760
|
+
const collector = message.channel.createMessageComponentCollector({
|
|
761
|
+
filter: options.filter,
|
|
762
|
+
time: options?.time || 6e4
|
|
763
|
+
}).on("collect", (interaction) => {
|
|
764
|
+
let stop = false;
|
|
765
|
+
if (interaction.customId.startsWith(this.interaction.id)) {
|
|
766
|
+
switch (Number(interaction.customId.split(/-/).pop())) {
|
|
767
|
+
case 0: {
|
|
768
|
+
embed = embeds[0];
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
case 1: {
|
|
772
|
+
embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
case 2: {
|
|
776
|
+
collector.stop();
|
|
777
|
+
stop = true;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
case 3: {
|
|
781
|
+
embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
case 4: {
|
|
785
|
+
embed = embeds[embeds.length - 1];
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
stop ? interaction.update({
|
|
790
|
+
embeds: [embed],
|
|
791
|
+
components: []
|
|
792
|
+
}) : interaction.update({
|
|
793
|
+
embeds: [embed]
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}).on("end", () => {
|
|
797
|
+
this.interaction.editReply({ components: [] });
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
buttonMenuPaginator(embeds, options) {
|
|
802
|
+
}
|
|
803
|
+
isOwner() {
|
|
804
|
+
return this.client.util.isOwner(this.interaction.user.id);
|
|
805
|
+
}
|
|
806
|
+
createModal() {
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/models/CommandArguments.ts
|
|
811
|
+
var InteractionArguments = class {
|
|
812
|
+
interaction;
|
|
813
|
+
constructor(interaction) {
|
|
814
|
+
this.interaction = interaction;
|
|
815
|
+
}
|
|
816
|
+
group() {
|
|
817
|
+
return this.interaction?.options?._group;
|
|
818
|
+
}
|
|
819
|
+
subcommand() {
|
|
820
|
+
return this.interaction?.options?._subcommand;
|
|
821
|
+
}
|
|
822
|
+
arguments() {
|
|
823
|
+
const options = {};
|
|
824
|
+
if (this.interaction?.options?._hoistedOptions) {
|
|
825
|
+
for (const option of this.interaction.options._hoistedOptions) {
|
|
826
|
+
options[option.name] = option.channel || option.user || option.role || option.value;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return options;
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
async function messageArguments(message, command) {
|
|
833
|
+
let args = { flags: {} }, separator = command.separator || " ", i = 0;
|
|
834
|
+
if (!command.args)
|
|
835
|
+
return;
|
|
836
|
+
command.args.filter((c) => c.type == "flag").map((flag) => {
|
|
837
|
+
args = args;
|
|
838
|
+
for (const flg of message.content.matchAll(flag.match)) {
|
|
839
|
+
if (flag.match == flg) {
|
|
840
|
+
message.content = message.content.replace(flag.match, "");
|
|
841
|
+
args.flags[flag.name] = true;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (!args.flags[flag.name])
|
|
845
|
+
args.flags[flag.name] = false;
|
|
846
|
+
});
|
|
847
|
+
for (const argument of command.args) {
|
|
848
|
+
args = args;
|
|
849
|
+
let content = message.content.split(/ +/).slice(1).join(separator).replace(new RegExp(`${separator}${separator}+`, "g"), separator).split(separator).slice(i);
|
|
850
|
+
if (content.join(separator) != "" && argument.type !== "flag") {
|
|
851
|
+
if (argument?.content?.includes(content[0])) {
|
|
852
|
+
args[argument.name] = content[0];
|
|
853
|
+
} else if (argument.type == "string") {
|
|
854
|
+
args[argument.name] = content[0];
|
|
855
|
+
} else if (argument.type == "number") {
|
|
856
|
+
args[argument.name] = parseInt(content[0]);
|
|
857
|
+
} else if (argument.type == "boolean") {
|
|
858
|
+
if (content[0]?.toLowerCase() != "true" && content[0]?.toLowerCase() != "false")
|
|
859
|
+
content[0] = null;
|
|
860
|
+
args[argument.name] = content[0];
|
|
861
|
+
} else if (argument.type == "user") {
|
|
862
|
+
let user = message.client.users.cache.find((u) => u?.username?.toLowerCase()?.includes(content[0])) || null;
|
|
863
|
+
try {
|
|
864
|
+
user = await message.client.users.fetch(user?.id || content[0].replace(/<@!?|>/g, "")) || null;
|
|
865
|
+
} catch (e) {
|
|
866
|
+
user = null;
|
|
867
|
+
}
|
|
868
|
+
args[argument.name] = user;
|
|
869
|
+
} else if (argument.type == "role") {
|
|
870
|
+
let role = message.guild?.roles.cache.find((r) => r?.name?.toLowerCase()?.includes(content[0])) || null;
|
|
871
|
+
try {
|
|
872
|
+
role = await message.guild?.roles.fetch(role?.id || content[0].replace(/<@&?|>/g, "")) || null;
|
|
873
|
+
} catch (e) {
|
|
874
|
+
role = null;
|
|
875
|
+
}
|
|
876
|
+
args[argument.name] = role;
|
|
877
|
+
} else if (argument.type == "member") {
|
|
878
|
+
let member = message.guild?.members.cache.find((m) => m?.nickname?.toLowerCase()?.includes(content[0]) || m?.user?.username?.toLowerCase()?.includes(content[0])) || null;
|
|
879
|
+
try {
|
|
880
|
+
member = await message.guild?.members.fetch(member?.id || content[0].replace(/<@!?|>/g, "")) || null;
|
|
881
|
+
} catch (e) {
|
|
882
|
+
member = null;
|
|
883
|
+
}
|
|
884
|
+
args[argument.name] = member;
|
|
885
|
+
} else if (argument.type == "channel") {
|
|
886
|
+
let channel = message.guild?.channels.cache.find((c) => c?.name?.toLowerCase()?.includes(content[0]));
|
|
887
|
+
try {
|
|
888
|
+
channel = await message.client.channels.fetch(channel?.id || content[0].replace(/<#|>/g, ""));
|
|
889
|
+
} catch (e) {
|
|
890
|
+
channel = null;
|
|
891
|
+
}
|
|
892
|
+
args[argument.name] = channel;
|
|
893
|
+
} else if (argument.type == "rest") {
|
|
894
|
+
args[argument.name] = content.join(separator);
|
|
895
|
+
break;
|
|
896
|
+
} else if (argument.prompt) {
|
|
897
|
+
if (argument.prompt.reply)
|
|
898
|
+
return message.util?.reply(argument.prompt.reply);
|
|
899
|
+
else if (argument.prompt.send)
|
|
900
|
+
return message.channel.send(argument.prompt.send);
|
|
901
|
+
} else
|
|
902
|
+
args[argument.name] = typeof argument.default == "function" ? argument.default(message) : argument.default;
|
|
903
|
+
i++;
|
|
904
|
+
} else
|
|
905
|
+
args[argument.name] = typeof argument.default == "function" ? argument.default(message) : argument.default;
|
|
906
|
+
}
|
|
907
|
+
return args;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// src/validators/CommandValidations.ts
|
|
911
|
+
var import_discord2 = require("discord.js");
|
|
912
|
+
function getUser(from) {
|
|
913
|
+
if (from instanceof import_discord2.Message)
|
|
914
|
+
return from.author;
|
|
915
|
+
else
|
|
916
|
+
return from.user;
|
|
917
|
+
}
|
|
918
|
+
function commandValidation(action, command, client, res = false) {
|
|
919
|
+
let user = getUser(action);
|
|
920
|
+
if ((command.ignoreOwner || client.settings.ignore?.owner) && client.util.isOwner(user.id))
|
|
921
|
+
return res;
|
|
922
|
+
else if (inCooldown(user, client, command, action))
|
|
923
|
+
return true;
|
|
924
|
+
else if (command.owner && !client.util.isOwner(user.id)) {
|
|
925
|
+
res = true;
|
|
926
|
+
emit(client, action, command, "Not an owner", client.settings.ownerId);
|
|
927
|
+
} else if (command.channelType?.length > 0 || command.channelType) {
|
|
928
|
+
if (!Array.isArray(command.channelType))
|
|
929
|
+
command.channelType = [command.channelType];
|
|
930
|
+
if (!command?.channelType?.includes(action.channel?.type)) {
|
|
931
|
+
res = true;
|
|
932
|
+
emit(client, action, command, "Not the correct channel", command.channelType);
|
|
933
|
+
}
|
|
934
|
+
} else if (command.channels?.length > 0 && !command.channels.includes(action.channel?.id)) {
|
|
935
|
+
res = true;
|
|
936
|
+
emit(client, action, command, "Not a whitelisted channel", command.channels);
|
|
937
|
+
} else if (command.guilds?.length > 0 && !command.guilds.includes(action.guild?.id)) {
|
|
938
|
+
res = true;
|
|
939
|
+
emit(client, action, command, "Not a whitelisted guild", command.guilds);
|
|
940
|
+
} else if (command.channelType && command.channelType !== action.channel?.type) {
|
|
941
|
+
res = true;
|
|
942
|
+
emit(client, action, command, "Not the correct type of channel", command.channelType);
|
|
943
|
+
} else if (action?.guild && (command.permissions?.user || client.settings.permissions?.user)) {
|
|
944
|
+
const permissions = command.permissions?.user || client?.settings?.permissions?.user?.push(...handlerPermissions(client, command.commandType, "user")), missing = [];
|
|
945
|
+
if (Array.isArray(permissions))
|
|
946
|
+
permissions.map((permission) => {
|
|
947
|
+
if (!(action.member?.permissions).has(permission)) {
|
|
948
|
+
missing.push(permission);
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
if (missing.length > 0) {
|
|
952
|
+
res = true;
|
|
953
|
+
emit(client, action, command, "Missing User Permissions", missing);
|
|
954
|
+
}
|
|
955
|
+
} else if (action?.guild && (command.permissions?.client || client.settings.permissions?.client)) {
|
|
956
|
+
const permissions = command.permissions?.client || client?.settings?.permissions?.client?.push(...handlerPermissions(client, command.commandType, "client")), missing = [];
|
|
957
|
+
if (Array.isArray(permissions))
|
|
958
|
+
permissions.map((permission) => {
|
|
959
|
+
if (!(action.member?.permissions).has(permission)) {
|
|
960
|
+
missing.push(permission);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
if (missing.length > 0) {
|
|
964
|
+
res = true;
|
|
965
|
+
emit(client, action, command, "Missing Client Permissions", missing);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return res;
|
|
969
|
+
}
|
|
970
|
+
function emit(client, action, command, reason, extra) {
|
|
971
|
+
return client.emit("commandBlock", action, command, reason, extra);
|
|
972
|
+
}
|
|
973
|
+
function inCooldown(user, client, command, action) {
|
|
974
|
+
let res = false, downs = {};
|
|
975
|
+
const { cooldowns, messageCommands, slashCommands, contextCommands, commands } = client.cache;
|
|
976
|
+
if (command.commandType === "MessageCommand" /* MessageCommand */ && client.handlerOptions.message.cooldown) {
|
|
977
|
+
if (messageCommands.has(user.id)) {
|
|
978
|
+
const usr = messageCommands.get(user.id);
|
|
979
|
+
usr.timeRemaining = usr.endsAt - Date.now();
|
|
980
|
+
downs.message = usr;
|
|
981
|
+
res = true;
|
|
982
|
+
}
|
|
983
|
+
if (!messageCommands.has(user.id)) {
|
|
984
|
+
messageCommands.set(user.id, toCooldown(action, command, client.handlerOptions.message.cooldown, user.id));
|
|
985
|
+
setInterval(() => {
|
|
986
|
+
messageCommands.delete(user.id);
|
|
987
|
+
}, client.handlerOptions.message.cooldown);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
if (command.commandType === "SlashCommand" /* SlashCommand */ && client.handlerOptions.slash.cooldown) {
|
|
991
|
+
if (slashCommands.has(user.id)) {
|
|
992
|
+
const usr = slashCommands.get(user.id);
|
|
993
|
+
usr.timeRemaining = usr.endsAt - Date.now();
|
|
994
|
+
downs.slash = usr;
|
|
995
|
+
res = true;
|
|
996
|
+
}
|
|
997
|
+
if (!slashCommands.has(user.id)) {
|
|
998
|
+
slashCommands.set(user.id, toCooldown(action, command, client.handlerOptions.slash.cooldown, user.id));
|
|
999
|
+
setInterval(() => {
|
|
1000
|
+
slashCommands.delete(user.id);
|
|
1001
|
+
}, client.handlerOptions.slash.cooldown);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (command.commandType === "ContextCommand" /* ContextCommand */ && client.handlerOptions.context.cooldown) {
|
|
1005
|
+
if (contextCommands.has(user.id)) {
|
|
1006
|
+
const usr = contextCommands.get(user.id);
|
|
1007
|
+
usr.timeRemaining = usr.endsAt - Date.now();
|
|
1008
|
+
downs.context = usr;
|
|
1009
|
+
res = true;
|
|
1010
|
+
}
|
|
1011
|
+
if (!contextCommands.has(user.id)) {
|
|
1012
|
+
contextCommands.set(user.id, toCooldown(action, command, client.handlerOptions.context.cooldown, user.id));
|
|
1013
|
+
setInterval(() => {
|
|
1014
|
+
contextCommands.delete(user.id);
|
|
1015
|
+
}, client.handlerOptions.context.cooldown);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (client.settings?.cooldown?.default) {
|
|
1019
|
+
if (cooldowns.has(user.id)) {
|
|
1020
|
+
const usr = cooldowns.get(user.id);
|
|
1021
|
+
usr.timeRemaining = usr.endsAt - Date.now();
|
|
1022
|
+
downs.default = usr;
|
|
1023
|
+
res = true;
|
|
1024
|
+
}
|
|
1025
|
+
if (!cooldowns.has(user.id)) {
|
|
1026
|
+
cooldowns.set(user.id, toCooldown(action, command, client.settings.cooldown.default, user.id));
|
|
1027
|
+
setInterval(() => {
|
|
1028
|
+
cooldowns.delete(user.id);
|
|
1029
|
+
}, client.settings.cooldown.default);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
if (command.cooldown) {
|
|
1033
|
+
const name = user.id + "-" + (command.data?.name || command?.name) + "-" + command.commandType;
|
|
1034
|
+
if (commands.has(name)) {
|
|
1035
|
+
const usr = commands.get(name);
|
|
1036
|
+
usr.timeRemaining = usr.endsAt - Date.now();
|
|
1037
|
+
downs.command = usr;
|
|
1038
|
+
res = true;
|
|
1039
|
+
}
|
|
1040
|
+
if (!commands.has(name)) {
|
|
1041
|
+
commands.set(name, toCooldown(action, command, command.cooldown, name));
|
|
1042
|
+
setInterval(() => {
|
|
1043
|
+
commands.delete(name);
|
|
1044
|
+
}, command.cooldown);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
if (Object.keys(downs).length > 0)
|
|
1048
|
+
client.emit("commandCooldown", action, command, downs);
|
|
1049
|
+
return res;
|
|
1050
|
+
}
|
|
1051
|
+
function toCooldown(action, command, cooldown, name) {
|
|
1052
|
+
let user = getUser(action);
|
|
1053
|
+
return {
|
|
1054
|
+
name,
|
|
1055
|
+
id: user.id,
|
|
1056
|
+
tag: user.tag,
|
|
1057
|
+
commandType: command.commandType,
|
|
1058
|
+
commandName: command?.data?.name || command?.name,
|
|
1059
|
+
guildId: action?.guild?.id,
|
|
1060
|
+
channelId: action?.channel?.id,
|
|
1061
|
+
startsAt: Number(Date.now()),
|
|
1062
|
+
endsAt: Number(Date.now()) + cooldown
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
function handlerPermissions(client, commandType, type) {
|
|
1066
|
+
let permissions = [];
|
|
1067
|
+
if (commandType === "MessageCommand" /* MessageCommand */) {
|
|
1068
|
+
if (type === "user")
|
|
1069
|
+
permissions = client.handlerOptions.message?.userPermissions || [];
|
|
1070
|
+
else if (type === "client")
|
|
1071
|
+
permissions = client.handlerOptions.message?.clientPermissions || [];
|
|
1072
|
+
} else if (commandType === "SlashCommand" /* SlashCommand */) {
|
|
1073
|
+
if (type === "user")
|
|
1074
|
+
permissions = client.handlerOptions.slash?.userPermissions || [];
|
|
1075
|
+
else if (type === "client")
|
|
1076
|
+
permissions = client.handlerOptions.slash?.clientPermissions || [];
|
|
1077
|
+
} else if (commandType === "ContextCommand" /* ContextCommand */) {
|
|
1078
|
+
if (type === "user")
|
|
1079
|
+
permissions = client.handlerOptions.context?.userPermissions || [];
|
|
1080
|
+
else if (type === "client")
|
|
1081
|
+
permissions = client.handlerOptions.context?.clientPermissions || [];
|
|
1082
|
+
}
|
|
1083
|
+
return permissions;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// src/models/Events.ts
|
|
1087
|
+
var import_dumfunctions2 = require("dumfunctions");
|
|
1088
|
+
|
|
1089
|
+
// src/validators/InhibitorValidations.ts
|
|
1090
|
+
var InhibitorValidation = class {
|
|
1091
|
+
client;
|
|
1092
|
+
action;
|
|
1093
|
+
command;
|
|
1094
|
+
inhibited;
|
|
1095
|
+
constructor(client, action, command) {
|
|
1096
|
+
this.client = client;
|
|
1097
|
+
this.action = action;
|
|
1098
|
+
this.command = command;
|
|
1099
|
+
this.inhibited = {};
|
|
1100
|
+
}
|
|
1101
|
+
async inhibit() {
|
|
1102
|
+
for (const inhibitor of this.client.inhibitors) {
|
|
1103
|
+
const inhibit = inhibitor[1];
|
|
1104
|
+
if (inhibit)
|
|
1105
|
+
this.inhibited[inhibit.name] = await inhibit.check(this.action, this.args(this.action, inhibit.type));
|
|
1106
|
+
}
|
|
1107
|
+
for (const inhibit of Object.values(this.inhibited)) {
|
|
1108
|
+
if (inhibit)
|
|
1109
|
+
return this.inhibited;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
args(action, type) {
|
|
1113
|
+
if (type === "Channel" /* Channel */)
|
|
1114
|
+
return action.channel;
|
|
1115
|
+
if (type === "User" /* User */)
|
|
1116
|
+
return action.author || action.user;
|
|
1117
|
+
if (type === "Guild" /* Guild */)
|
|
1118
|
+
return action.guild;
|
|
1119
|
+
if (type === "Member" /* Member */)
|
|
1120
|
+
return action.member;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
// src/models/Events.ts
|
|
1125
|
+
var MessageCommandEvents = class {
|
|
1126
|
+
client;
|
|
1127
|
+
constructor(client) {
|
|
1128
|
+
this.client = client;
|
|
1129
|
+
}
|
|
1130
|
+
messageCreate() {
|
|
1131
|
+
this.client.on("messageCreate", async (message) => {
|
|
1132
|
+
if (!message.author.bot) {
|
|
1133
|
+
let command = void 0, px = void 0;
|
|
1134
|
+
message.author.isOwner = this.client.util.isOwner(message.author.id);
|
|
1135
|
+
message.util = new MessageCommandUtil(this.client, message);
|
|
1136
|
+
const commands = this.client.commands.message;
|
|
1137
|
+
commands.filter((c) => !c.regex).map(async (cmd) => {
|
|
1138
|
+
if (cmd.prefix) {
|
|
1139
|
+
cmd.prefix.map((prefix2) => {
|
|
1140
|
+
if (message.content.startsWith(prefix2)) {
|
|
1141
|
+
command = message.content.replace(prefix2, "").split(/ +/).shift();
|
|
1142
|
+
px = prefix2;
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
if (this.client.handlerOptions.message?.prefix) {
|
|
1147
|
+
const prefix2 = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
|
|
1148
|
+
prefix2.map((prefix3) => {
|
|
1149
|
+
if (message.content.startsWith(prefix3)) {
|
|
1150
|
+
command = message.content.replace(prefix3, "").split(/ +/).shift();
|
|
1151
|
+
px = prefix3;
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
if (this.client.handlerOptions.message?.allowMention) {
|
|
1156
|
+
if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
1157
|
+
command = message.content.replace(`<@${this.client.user?.id}>`, "").trim().split(/ +/).shift();
|
|
1158
|
+
px = "MentionPrefix";
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
|
|
1162
|
+
if ((cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) && (cmd.prefix.includes(px) || prefix?.includes(px) || px === "MentionPrefix")) {
|
|
1163
|
+
try {
|
|
1164
|
+
if (this.client.handlerOptions.message?.handleTyping)
|
|
1165
|
+
message.channel.sendTyping();
|
|
1166
|
+
const inhibitor = new InhibitorValidation(this.client, message, command);
|
|
1167
|
+
if (commandValidation(message, cmd, this.client))
|
|
1168
|
+
return;
|
|
1169
|
+
if (await inhibitor.inhibit())
|
|
1170
|
+
return;
|
|
1171
|
+
if (cmd.conditions && await cmd.conditions(message, await messageArguments(message, cmd)))
|
|
1172
|
+
return;
|
|
1173
|
+
await cmd.exec(message, await messageArguments(message, cmd));
|
|
1174
|
+
this.client.emit("commandRun", message, cmd);
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
return this.client.emit("commandError", message, error, cmd);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
messageUpdate() {
|
|
1184
|
+
this.client.on("messageUpdate", async (old, message) => {
|
|
1185
|
+
message = message;
|
|
1186
|
+
if (!message.author?.bot) {
|
|
1187
|
+
let command = void 0, px = void 0;
|
|
1188
|
+
if (message.author)
|
|
1189
|
+
message.author.isOwner = this.client.util.isOwner(message.author.id);
|
|
1190
|
+
message.util = new MessageCommandUtil(this.client, message);
|
|
1191
|
+
const commands = this.client.commands.message;
|
|
1192
|
+
commands.filter((c) => !c.regex).map(async (cmd) => {
|
|
1193
|
+
if (cmd.prefix) {
|
|
1194
|
+
cmd.prefix.map((prefix2) => {
|
|
1195
|
+
if (message?.content?.startsWith(prefix2)) {
|
|
1196
|
+
command = message.content.replace(prefix2, "").split(/ +/).shift();
|
|
1197
|
+
px = prefix2;
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
if (this.client.handlerOptions.message?.prefix) {
|
|
1202
|
+
const prefix2 = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
|
|
1203
|
+
prefix2.map((prefix3) => {
|
|
1204
|
+
if (message?.content?.startsWith(prefix3)) {
|
|
1205
|
+
command = message.content.replace(prefix3, "").split(/ +/).shift();
|
|
1206
|
+
px = prefix3;
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
if (this.client.handlerOptions.message?.allowMention) {
|
|
1211
|
+
if (message.mentions.users.has(this.client.user?.id || "") || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
1212
|
+
command = message?.content?.replace(`<@${this.client.user?.id}>`, "").trim().split(/ +/).shift();
|
|
1213
|
+
px = "MentionPrefix";
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
|
|
1217
|
+
if ((cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) && (cmd.prefix.includes(px) || prefix?.includes(px) || px === "MentionPrefix")) {
|
|
1218
|
+
try {
|
|
1219
|
+
if (this.client.handlerOptions.message?.handleTyping)
|
|
1220
|
+
message.channel.sendTyping();
|
|
1221
|
+
message = message;
|
|
1222
|
+
const inhibitor = new InhibitorValidation(this.client, message, command);
|
|
1223
|
+
if (commandValidation(message, cmd, this.client))
|
|
1224
|
+
return;
|
|
1225
|
+
if (await inhibitor.inhibit())
|
|
1226
|
+
return;
|
|
1227
|
+
if (cmd.conditions && await cmd.conditions(message, await messageArguments(message, cmd)))
|
|
1228
|
+
return;
|
|
1229
|
+
await cmd.exec(message, await messageArguments(message, cmd));
|
|
1230
|
+
this.client.emit("commandRun", message, cmd);
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
return this.client.emit("commandError", message, error, cmd);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
messageDelete() {
|
|
1240
|
+
this.client.on("messageDelete", async (message) => {
|
|
1241
|
+
if (this.client.cache.messages.has(message.id) && this.client.handlerOptions.message?.handleDeletes) {
|
|
1242
|
+
try {
|
|
1243
|
+
if (this.client.handlerOptions.message?.handleTyping)
|
|
1244
|
+
message.channel.sendTyping();
|
|
1245
|
+
const msg = this.client.cache.messages.get(message.id);
|
|
1246
|
+
const response = await message.channel.messages.fetch(msg?.response);
|
|
1247
|
+
await response.delete();
|
|
1248
|
+
} catch (error) {
|
|
1249
|
+
this.client.emit("commandError", message, error, null);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
var SlashCommandEvents = class {
|
|
1256
|
+
client;
|
|
1257
|
+
constructor(client) {
|
|
1258
|
+
this.client = client;
|
|
1259
|
+
}
|
|
1260
|
+
slashCreate() {
|
|
1261
|
+
this.client.on("interactionCreate", async (interaction) => {
|
|
1262
|
+
interaction.util = new InteractionCommandUtil(this.client, interaction);
|
|
1263
|
+
interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
|
|
1264
|
+
if (interaction.type === import_discord3.InteractionType.ApplicationCommand) {
|
|
1265
|
+
if (this.client.commands.slash.has(interaction.commandName)) {
|
|
1266
|
+
let command = this.client.commands.slash.get(interaction.commandName);
|
|
1267
|
+
const argumentsInfo = new InteractionArguments(interaction);
|
|
1268
|
+
try {
|
|
1269
|
+
const inhibitor = new InhibitorValidation(this.client, interaction, command);
|
|
1270
|
+
if (await inhibitor.inhibit())
|
|
1271
|
+
return;
|
|
1272
|
+
if (commandValidation(interaction, command, this.client))
|
|
1273
|
+
return;
|
|
1274
|
+
if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
|
|
1275
|
+
await interaction.deferReply({
|
|
1276
|
+
ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
|
|
1277
|
+
fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply
|
|
1278
|
+
});
|
|
1279
|
+
if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
|
|
1280
|
+
await interaction.deferReply({
|
|
1281
|
+
ephemeral: command.defer?.ephemeral,
|
|
1282
|
+
fetchReply: command.defer?.fetchReply
|
|
1283
|
+
});
|
|
1284
|
+
if (command.conditions && await command.conditions(interaction, {
|
|
1285
|
+
group: argumentsInfo.group(),
|
|
1286
|
+
subcommand: argumentsInfo.subcommand(),
|
|
1287
|
+
args: await argumentsInfo.arguments()
|
|
1288
|
+
}))
|
|
1289
|
+
return;
|
|
1290
|
+
await command.exec(interaction, {
|
|
1291
|
+
group: argumentsInfo.group(),
|
|
1292
|
+
subcommand: argumentsInfo.subcommand(),
|
|
1293
|
+
args: await argumentsInfo.arguments()
|
|
1294
|
+
});
|
|
1295
|
+
this.client.emit("commandRun", interaction, command);
|
|
1296
|
+
} catch (error) {
|
|
1297
|
+
this.client.emit("commandError", interaction, error, command);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
var ContextCommandEvents = class {
|
|
1305
|
+
client;
|
|
1306
|
+
constructor(client) {
|
|
1307
|
+
this.client = client;
|
|
1308
|
+
}
|
|
1309
|
+
contextCreate() {
|
|
1310
|
+
this.client.on("interactionCreate", async (interaction) => {
|
|
1311
|
+
interaction.util = new InteractionCommandUtil(this.client, interaction);
|
|
1312
|
+
interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
|
|
1313
|
+
if (interaction.type === import_discord3.InteractionType.ApplicationCommand) {
|
|
1314
|
+
if (this.client.commands.context.has(interaction.commandName)) {
|
|
1315
|
+
let command = this.client.commands.context.get(interaction.commandName);
|
|
1316
|
+
try {
|
|
1317
|
+
const inhibitor = new InhibitorValidation(this.client, interaction, command);
|
|
1318
|
+
if (commandValidation(interaction, command, this.client))
|
|
1319
|
+
return;
|
|
1320
|
+
if (await inhibitor.inhibit())
|
|
1321
|
+
return;
|
|
1322
|
+
if (command.conditions && await command.conditions(interaction))
|
|
1323
|
+
return;
|
|
1324
|
+
if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
|
|
1325
|
+
await interaction.deferReply({
|
|
1326
|
+
ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
|
|
1327
|
+
fetchReply: this.client.handlerOptions.context?.defer?.fetchReply
|
|
1328
|
+
});
|
|
1329
|
+
if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
|
|
1330
|
+
await interaction.deferReply({
|
|
1331
|
+
ephemeral: command.defer?.ephemeral,
|
|
1332
|
+
fetchReply: command.defer?.fetchReply
|
|
1333
|
+
});
|
|
1334
|
+
let args = {};
|
|
1335
|
+
if (command.type === 3)
|
|
1336
|
+
args = await interaction.channel.messages.fetch(interaction.targetId);
|
|
1337
|
+
if (command.type === 2)
|
|
1338
|
+
args = await this.client.users.fetch(interaction.targetId);
|
|
1339
|
+
await command.exec(interaction, args);
|
|
1340
|
+
this.client.emit("commandRun", interaction, command);
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
this.client.emit("commandError", interaction, error, command);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
var CommandsDeploy = class {
|
|
1350
|
+
client;
|
|
1351
|
+
constructor(client) {
|
|
1352
|
+
this.client = client;
|
|
1353
|
+
}
|
|
1354
|
+
deploy() {
|
|
1355
|
+
this.client.once("ready", async (client) => {
|
|
1356
|
+
const slashCommands = [], contextCommands = [];
|
|
1357
|
+
this.client.commands.context.map((command) => command.data ? contextCommands.push(command.data.toJSON()) : null);
|
|
1358
|
+
this.client.commands.slash.map((command) => command.data ? slashCommands.push(command.data.toJSON()) : null);
|
|
1359
|
+
try {
|
|
1360
|
+
const global = {
|
|
1361
|
+
slash: this.client.handlerOptions.slash?.global,
|
|
1362
|
+
context: this.client.handlerOptions.context?.global
|
|
1363
|
+
};
|
|
1364
|
+
const guild = {
|
|
1365
|
+
slash: this.client.handlerOptions.slash?.guildId,
|
|
1366
|
+
context: this.client.handlerOptions.context?.guildId
|
|
1367
|
+
};
|
|
1368
|
+
if (global.slash && global.context) {
|
|
1369
|
+
if (guild.slash !== guild.context)
|
|
1370
|
+
console.info(
|
|
1371
|
+
import_dumfunctions2.Style.log(
|
|
1372
|
+
`Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${(await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name}!`,
|
|
1373
|
+
{ color: import_dumfunctions2.Style.TextColor.Red }
|
|
1374
|
+
)
|
|
1375
|
+
);
|
|
1376
|
+
this.put("global", guild.slash, [...contextCommands, ...slashCommands]);
|
|
1377
|
+
this.put("guild", guild.slash, []);
|
|
1378
|
+
}
|
|
1379
|
+
if (global.slash && global.context === false) {
|
|
1380
|
+
this.put("global", guild.slash, slashCommands);
|
|
1381
|
+
}
|
|
1382
|
+
if (global.slash === false && global.context) {
|
|
1383
|
+
this.put("global", guild.context, contextCommands);
|
|
1384
|
+
}
|
|
1385
|
+
if (global.slash === false && global.context === false) {
|
|
1386
|
+
this.put("guild", guild.slash, [...contextCommands, ...slashCommands]);
|
|
1387
|
+
}
|
|
1388
|
+
if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
|
|
1389
|
+
console.info(
|
|
1390
|
+
import_dumfunctions2.Style.log(
|
|
1391
|
+
`Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? "globally" : "locally"} and ${contextCommands.length} context commands ${global.context ? "globally" : "locally"}.`,
|
|
1392
|
+
{ color: import_dumfunctions2.Style.TextColor.Purple }
|
|
1393
|
+
)
|
|
1394
|
+
);
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
console.error(
|
|
1397
|
+
import_dumfunctions2.Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
|
|
1398
|
+
color: import_dumfunctions2.Style.BackgroundColor.Red
|
|
1399
|
+
})
|
|
1400
|
+
);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
put(type, guild, body) {
|
|
1405
|
+
const rest = new import_discord3.REST({ version: import_discord3.GatewayVersion }).setToken(this.client.token);
|
|
1406
|
+
if (type === "guild")
|
|
1407
|
+
rest.put(import_discord3.Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
|
|
1408
|
+
else
|
|
1409
|
+
rest.put(import_discord3.Routes.applicationCommands(this.client.user?.id), { body });
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
// src/handlers/CommandHandler.ts
|
|
1414
|
+
var CommandHandler = class {
|
|
1415
|
+
client;
|
|
1416
|
+
handler;
|
|
1417
|
+
constructor(client) {
|
|
1418
|
+
this.client = client;
|
|
1419
|
+
this.handler = new Handler(client);
|
|
1420
|
+
new CommandsDeploy(this.client).deploy();
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* @description - The message command loader.
|
|
1424
|
+
* @param {MessageCommandOptions} options - message command loader options.
|
|
1425
|
+
*/
|
|
1426
|
+
loadAllMessageCommands(options) {
|
|
1427
|
+
this.handler.loadAllMessageCommands(options);
|
|
1428
|
+
const events = new MessageCommandEvents(this.client);
|
|
1429
|
+
events.messageCreate();
|
|
1430
|
+
events.messageUpdate();
|
|
1431
|
+
events.messageDelete();
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* @description - The slash command loader.
|
|
1435
|
+
* @param {SlashCommandOptions} options - slash command loader options.
|
|
1436
|
+
*/
|
|
1437
|
+
loadAllSlashCommands(options) {
|
|
1438
|
+
this.handler.loadAllSlashCommands(options);
|
|
1439
|
+
new SlashCommandEvents(this.client).slashCreate();
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* @description - The context command loader.
|
|
1443
|
+
* @param {ContextCommandOptions} options - context command loader options.
|
|
1444
|
+
*/
|
|
1445
|
+
loadAllContextCommands(options) {
|
|
1446
|
+
this.handler.loadAllContextCommands(options);
|
|
1447
|
+
new ContextCommandEvents(this.client).contextCreate();
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/handlers/EventHandler.ts
|
|
1452
|
+
var EventHandler = class {
|
|
1453
|
+
client;
|
|
1454
|
+
handler;
|
|
1455
|
+
constructor(client) {
|
|
1456
|
+
this.client = client;
|
|
1457
|
+
this.handler = new Handler(client);
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* @description - The event loader
|
|
1461
|
+
* @param {EventLoadOptions} options - message command options
|
|
1462
|
+
*/
|
|
1463
|
+
loadAllEvents(options) {
|
|
1464
|
+
return this.handler.loadAllEvents(options);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
|
|
1468
|
+
// src/handlers/InhibitorHandler.ts
|
|
1469
|
+
var InhibitorHandler = class {
|
|
1470
|
+
client;
|
|
1471
|
+
handler;
|
|
1472
|
+
constructor(client) {
|
|
1473
|
+
this.client = client;
|
|
1474
|
+
this.handler = new Handler(client);
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* @description - The loader for all inhibitors.
|
|
1478
|
+
* @param {InhibitorLoadOptions} options - the inhibitor loader options.
|
|
1479
|
+
* @returns undefined
|
|
1480
|
+
*/
|
|
1481
|
+
loadAllInhibitors(options) {
|
|
1482
|
+
this.handler.loadAllInhibitors(options);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
// src/models/Extensions.ts
|
|
1487
|
+
var import_dumfunctions3 = require("dumfunctions");
|
|
1488
|
+
var Extensions = class {
|
|
1489
|
+
client;
|
|
1490
|
+
constructor(client) {
|
|
1491
|
+
this.client = client;
|
|
1492
|
+
}
|
|
1493
|
+
async load(extensions, logging = false) {
|
|
1494
|
+
const exts = [];
|
|
1495
|
+
extensions.map((extension) => {
|
|
1496
|
+
try {
|
|
1497
|
+
this.client.extensions[extension.name] = extension;
|
|
1498
|
+
exts.push(extension.name);
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
console.error(
|
|
1501
|
+
import_dumfunctions3.Style.log(`Xernerx | An error occurred trying to load ${extension.name}, error: <${error}>`, {
|
|
1502
|
+
color: import_dumfunctions3.Style.BackgroundColor.Red
|
|
1503
|
+
})
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
if (logging)
|
|
1508
|
+
console.info(import_dumfunctions3.Style.log(`Xernerx | Loaded ${exts.length} extensions: ${exts.join(", ")}`, { color: import_dumfunctions3.Style.TextColor.Cyan }));
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
|
|
1512
|
+
// src/client/XernerxClient.ts
|
|
1513
|
+
var XernerxClient = class extends import_discord4.Client {
|
|
1514
|
+
settings;
|
|
1515
|
+
commands;
|
|
1516
|
+
cache;
|
|
1517
|
+
modules;
|
|
1518
|
+
util;
|
|
1519
|
+
handlerOptions;
|
|
1520
|
+
events;
|
|
1521
|
+
extensions;
|
|
1522
|
+
inhibitors;
|
|
1523
|
+
config;
|
|
1524
|
+
constructor(discordOptions, clientOptions, config) {
|
|
1525
|
+
super(discordOptions);
|
|
1526
|
+
this.settings = import_zod.z.object({
|
|
1527
|
+
ownerId: import_zod.z.string().or(import_zod.z.array(import_zod.z.string())).default([]),
|
|
1528
|
+
permissions: import_zod.z.object({
|
|
1529
|
+
client: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1530
|
+
user: import_zod.z.array(import_zod.z.string()).default([]),
|
|
1531
|
+
dm: import_zod.z.boolean().default(false)
|
|
1532
|
+
}).optional(),
|
|
1533
|
+
ignore: import_zod.z.object({
|
|
1534
|
+
owner: import_zod.z.boolean().default(false),
|
|
1535
|
+
users: import_zod.z.array(import_zod.z.string()),
|
|
1536
|
+
channels: import_zod.z.array(import_zod.z.string()),
|
|
1537
|
+
guilds: import_zod.z.array(import_zod.z.string())
|
|
1538
|
+
}).optional(),
|
|
1539
|
+
log: import_zod.z.object({
|
|
1540
|
+
ready: import_zod.z.boolean().default(false),
|
|
1541
|
+
error: import_zod.z.boolean().default(false)
|
|
1542
|
+
}).optional(),
|
|
1543
|
+
cooldown: import_zod.z.object({
|
|
1544
|
+
command: import_zod.z.number().default(0),
|
|
1545
|
+
cache: import_zod.z.number().default(0)
|
|
1546
|
+
}).optional()
|
|
1547
|
+
}).parse(clientOptions);
|
|
1548
|
+
this.config = config || {};
|
|
1549
|
+
this.commands = {
|
|
1550
|
+
message: new import_discord4.Collection(),
|
|
1551
|
+
slash: new import_discord4.Collection(),
|
|
1552
|
+
context: new import_discord4.Collection()
|
|
1553
|
+
};
|
|
1554
|
+
this.events = new import_discord4.Collection();
|
|
1555
|
+
this.inhibitors = new import_discord4.Collection();
|
|
1556
|
+
this.cache = {
|
|
1557
|
+
messages: new import_discord4.Collection(),
|
|
1558
|
+
cooldowns: new import_discord4.Collection(),
|
|
1559
|
+
messageCommands: new import_discord4.Collection(),
|
|
1560
|
+
slashCommands: new import_discord4.Collection(),
|
|
1561
|
+
contextCommands: new import_discord4.Collection(),
|
|
1562
|
+
commands: new import_discord4.Collection()
|
|
1563
|
+
};
|
|
1564
|
+
this.modules = {
|
|
1565
|
+
commandHandler: new CommandHandler(this),
|
|
1566
|
+
eventHandler: new EventHandler(this),
|
|
1567
|
+
inhibitorHandler: new InhibitorHandler(this)
|
|
1568
|
+
};
|
|
1569
|
+
this.extensions = {};
|
|
1570
|
+
this.util = new ClientUtil(this);
|
|
1571
|
+
this.handlerOptions = {};
|
|
1572
|
+
if (this.settings?.log?.ready) {
|
|
1573
|
+
this.once("ready", async (client) => {
|
|
1574
|
+
const size = (await client.guilds.fetch()).size;
|
|
1575
|
+
console.info(
|
|
1576
|
+
import_dumfunctions4.Style.log(
|
|
1577
|
+
`Xernerx | ${client.user.tag} signed in watching ${size} server${size > 1 ? "s" : ""}. ${(this.handlerOptions.slash || this.handlerOptions.context)?.guildId ? `Using ${(await this.guilds.fetch((this.handlerOptions.slash || this.handlerOptions.context)?.guildId || "0")).name} as local guild.` : ""}`,
|
|
1578
|
+
{ color: import_dumfunctions4.Style.TextColor.Purple }
|
|
1579
|
+
)
|
|
1580
|
+
);
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
register(token) {
|
|
1585
|
+
this.login(token);
|
|
1586
|
+
}
|
|
1587
|
+
loadAllExtensions(options) {
|
|
1588
|
+
const extensions = new Extensions(this);
|
|
1589
|
+
return extensions.load(options.extensions, options.logging || false);
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
// src/build/EventBuilder.ts
|
|
1594
|
+
var import_zod2 = require("zod");
|
|
1595
|
+
var EventBuilder = class {
|
|
1596
|
+
id;
|
|
1597
|
+
name;
|
|
1598
|
+
emitter;
|
|
1599
|
+
type;
|
|
1600
|
+
once;
|
|
1601
|
+
client;
|
|
1602
|
+
constructor(id, options) {
|
|
1603
|
+
this.id = id;
|
|
1604
|
+
import_zod2.z.object({
|
|
1605
|
+
name: import_zod2.z.string(),
|
|
1606
|
+
emitter: import_zod2.z.string().optional(),
|
|
1607
|
+
type: import_zod2.z.string().optional(),
|
|
1608
|
+
once: import_zod2.z.boolean().optional()
|
|
1609
|
+
}).parse(options);
|
|
1610
|
+
this.name = options.name;
|
|
1611
|
+
this.emitter = options.emitter || "client";
|
|
1612
|
+
this.type = options.type || "discord";
|
|
1613
|
+
this.once = options.once || false;
|
|
1614
|
+
this.client = XernerxClient;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* @description run your custom event here.
|
|
1618
|
+
* TODO - update description
|
|
1619
|
+
*/
|
|
1620
|
+
async run() {
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
// src/build/InhibitorBuilder.ts
|
|
1625
|
+
var import_zod3 = require("zod");
|
|
1626
|
+
var InhibitorBuilder = class {
|
|
1627
|
+
id;
|
|
1628
|
+
name;
|
|
1629
|
+
type;
|
|
1630
|
+
client;
|
|
1631
|
+
constructor(id, options) {
|
|
1632
|
+
this.id = id;
|
|
1633
|
+
import_zod3.z.object({
|
|
1634
|
+
name: import_zod3.z.string(),
|
|
1635
|
+
type: import_zod3.z.string()
|
|
1636
|
+
}).parse(options);
|
|
1637
|
+
this.name = options.name;
|
|
1638
|
+
this.type = options.type;
|
|
1639
|
+
this.client = XernerxClient;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* TODO - update description
|
|
1643
|
+
*/
|
|
1644
|
+
async check(interaction, args) {
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
// src/build/MessageCommandBuilder.ts
|
|
1649
|
+
var import_zod4 = require("zod");
|
|
1650
|
+
var MessageCommandBuilder = class {
|
|
1651
|
+
id;
|
|
1652
|
+
name;
|
|
1653
|
+
aliases;
|
|
1654
|
+
separator;
|
|
1655
|
+
description;
|
|
1656
|
+
info;
|
|
1657
|
+
category;
|
|
1658
|
+
prefix;
|
|
1659
|
+
regex;
|
|
1660
|
+
channelType;
|
|
1661
|
+
ignore;
|
|
1662
|
+
strict;
|
|
1663
|
+
permissions;
|
|
1664
|
+
cooldown;
|
|
1665
|
+
args;
|
|
1666
|
+
client;
|
|
1667
|
+
constructor(id, options) {
|
|
1668
|
+
this.id = id;
|
|
1669
|
+
import_zod4.z.object({
|
|
1670
|
+
name: import_zod4.z.string(),
|
|
1671
|
+
aliases: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1672
|
+
separator: import_zod4.z.string().min(1).max(1).optional(),
|
|
1673
|
+
description: import_zod4.z.string().optional(),
|
|
1674
|
+
info: import_zod4.z.string().optional(),
|
|
1675
|
+
category: import_zod4.z.string().optional(),
|
|
1676
|
+
prefix: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional(),
|
|
1677
|
+
regex: import_zod4.z.unknown(),
|
|
1678
|
+
channelType: import_zod4.z.array(import_zod4.z.number()).or(import_zod4.z.number()).optional(),
|
|
1679
|
+
cooldown: import_zod4.z.number().optional(),
|
|
1680
|
+
ignore: import_zod4.z.object({
|
|
1681
|
+
owners: import_zod4.z.boolean().optional(),
|
|
1682
|
+
users: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional(),
|
|
1683
|
+
channels: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional(),
|
|
1684
|
+
guilds: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional()
|
|
1685
|
+
}).optional(),
|
|
1686
|
+
strict: import_zod4.z.object({
|
|
1687
|
+
owners: import_zod4.z.boolean().optional(),
|
|
1688
|
+
users: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional(),
|
|
1689
|
+
channels: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional(),
|
|
1690
|
+
guilds: import_zod4.z.array(import_zod4.z.string()).or(import_zod4.z.string()).optional()
|
|
1691
|
+
}).optional(),
|
|
1692
|
+
permissions: import_zod4.z.object({
|
|
1693
|
+
client: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1694
|
+
users: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1695
|
+
dm: import_zod4.z.boolean().optional()
|
|
1696
|
+
}).optional()
|
|
1697
|
+
}).parse(options);
|
|
1698
|
+
this.name = options.name;
|
|
1699
|
+
this.aliases = options.aliases;
|
|
1700
|
+
this.separator = options.separator || " ";
|
|
1701
|
+
this.description = options.description;
|
|
1702
|
+
this.info = options.info;
|
|
1703
|
+
this.category = options.category;
|
|
1704
|
+
this.prefix = options.prefix ? Array.isArray(options.prefix) ? options.prefix : [options.prefix] : [];
|
|
1705
|
+
this.regex = options.regex;
|
|
1706
|
+
this.channelType = options.channelType;
|
|
1707
|
+
this.ignore = options.ignore;
|
|
1708
|
+
this.strict = options.strict;
|
|
1709
|
+
this.permissions = options.permissions;
|
|
1710
|
+
this.cooldown = options.cooldown || 0;
|
|
1711
|
+
this.args = options.args || [];
|
|
1712
|
+
this.client = XernerxClient;
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* @param {Message} message - The Discord message event data.
|
|
1716
|
+
* @param {object} args - The arguments you created.
|
|
1717
|
+
* @description make any preconditions here.
|
|
1718
|
+
*/
|
|
1719
|
+
async conditions(message, args) {
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* @param {Message} message - The Discord message event data.
|
|
1723
|
+
* @param {object} args - The arguments you created.
|
|
1724
|
+
* @description Make your custom command here.
|
|
1725
|
+
*/
|
|
1726
|
+
async exec(message, args) {
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
// src/build/ContextCommandBuilder.ts
|
|
1731
|
+
var import_discord5 = require("discord.js");
|
|
1732
|
+
var import_zod5 = require("zod");
|
|
1733
|
+
var ContextCommandBuilder = class {
|
|
1734
|
+
id;
|
|
1735
|
+
data;
|
|
1736
|
+
name;
|
|
1737
|
+
type;
|
|
1738
|
+
description;
|
|
1739
|
+
info;
|
|
1740
|
+
category;
|
|
1741
|
+
channelType;
|
|
1742
|
+
cooldown;
|
|
1743
|
+
ignore;
|
|
1744
|
+
strict;
|
|
1745
|
+
permissions;
|
|
1746
|
+
defer;
|
|
1747
|
+
client;
|
|
1748
|
+
constructor(id, options) {
|
|
1749
|
+
this.id = id;
|
|
1750
|
+
this.data = new import_discord5.ContextMenuCommandBuilder();
|
|
1751
|
+
if (options.name)
|
|
1752
|
+
this.data.setName(options.name);
|
|
1753
|
+
if (options.type)
|
|
1754
|
+
this.data.setType(options.type);
|
|
1755
|
+
if (options.permissions?.users)
|
|
1756
|
+
this.data.setDefaultMemberPermissions(options.permissions?.users);
|
|
1757
|
+
if (options.permissions?.dm === false)
|
|
1758
|
+
this.data.setDMPermission(options.permissions?.dm);
|
|
1759
|
+
if (options.nameLocalizations)
|
|
1760
|
+
this.data.setNameLocalizations(options.nameLocalizations);
|
|
1761
|
+
import_zod5.z.object({
|
|
1762
|
+
description: import_zod5.z.string(),
|
|
1763
|
+
info: import_zod5.z.string(),
|
|
1764
|
+
category: import_zod5.z.string(),
|
|
1765
|
+
channelType: import_zod5.z.array(import_zod5.z.number()).or(import_zod5.z.number()),
|
|
1766
|
+
cooldown: import_zod5.z.number(),
|
|
1767
|
+
ignore: import_zod5.z.object({
|
|
1768
|
+
owner: import_zod5.z.boolean(),
|
|
1769
|
+
users: import_zod5.z.array(import_zod5.z.string()),
|
|
1770
|
+
channels: import_zod5.z.array(import_zod5.z.string()),
|
|
1771
|
+
guilds: import_zod5.z.array(import_zod5.z.string())
|
|
1772
|
+
}),
|
|
1773
|
+
strict: import_zod5.z.object({
|
|
1774
|
+
owner: import_zod5.z.boolean(),
|
|
1775
|
+
users: import_zod5.z.array(import_zod5.z.string()),
|
|
1776
|
+
channels: import_zod5.z.array(import_zod5.z.string()),
|
|
1777
|
+
guilds: import_zod5.z.array(import_zod5.z.string())
|
|
1778
|
+
}),
|
|
1779
|
+
permissions: import_zod5.z.object({
|
|
1780
|
+
client: import_zod5.z.array(import_zod5.z.string()),
|
|
1781
|
+
users: import_zod5.z.array(import_zod5.z.string()),
|
|
1782
|
+
dm: import_zod5.z.boolean()
|
|
1783
|
+
}),
|
|
1784
|
+
defer: import_zod5.z.object({
|
|
1785
|
+
reply: import_zod5.z.boolean(),
|
|
1786
|
+
ephemeral: import_zod5.z.boolean(),
|
|
1787
|
+
fetch: import_zod5.z.boolean()
|
|
1788
|
+
})
|
|
1789
|
+
}).deepPartial().parse(options);
|
|
1790
|
+
this.name = options.name;
|
|
1791
|
+
this.type = options.type;
|
|
1792
|
+
this.description = options.description;
|
|
1793
|
+
this.info = options.info;
|
|
1794
|
+
this.category = options.category;
|
|
1795
|
+
this.channelType = options.channelType;
|
|
1796
|
+
this.cooldown = options.cooldown;
|
|
1797
|
+
this.ignore = options.ignore;
|
|
1798
|
+
this.strict = options.strict;
|
|
1799
|
+
this.permissions = options.permissions;
|
|
1800
|
+
this.defer = options.defer;
|
|
1801
|
+
this.client = XernerxClient;
|
|
1802
|
+
}
|
|
1803
|
+
/**
|
|
1804
|
+
* @param {Interaction} interaction - The Discord interaction event data.
|
|
1805
|
+
* @description make any preconditions here.
|
|
1806
|
+
* TODO - update description
|
|
1807
|
+
*/
|
|
1808
|
+
async conditions(interaction, args) {
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* @param {Interaction} interaction - The Discord interaction event data.
|
|
1812
|
+
* @description Make your custom command here.
|
|
1813
|
+
* TODO - update description
|
|
1814
|
+
*/
|
|
1815
|
+
async exec(interaction, args) {
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
// src/build/SlashCommandBuilder.ts
|
|
1820
|
+
var import_discord6 = __toESM(require("discord.js"), 1);
|
|
1821
|
+
var import_zod6 = require("zod");
|
|
1822
|
+
var SlashCommandBuilder = class {
|
|
1823
|
+
id;
|
|
1824
|
+
data;
|
|
1825
|
+
name;
|
|
1826
|
+
description;
|
|
1827
|
+
info;
|
|
1828
|
+
category;
|
|
1829
|
+
channelType;
|
|
1830
|
+
cooldown;
|
|
1831
|
+
ignore;
|
|
1832
|
+
strict;
|
|
1833
|
+
permissions;
|
|
1834
|
+
args;
|
|
1835
|
+
subcommands;
|
|
1836
|
+
groups;
|
|
1837
|
+
defer;
|
|
1838
|
+
client;
|
|
1839
|
+
constructor(id, options) {
|
|
1840
|
+
this.id = id;
|
|
1841
|
+
this.data = new import_discord6.default.SlashCommandBuilder().setName(options.name).setDescription(options.description);
|
|
1842
|
+
if (options.args && options?.args?.length > 0) {
|
|
1843
|
+
this.addArgs(this.data, options.args);
|
|
1844
|
+
}
|
|
1845
|
+
if (options.subcommands && options?.subcommands?.length > 0) {
|
|
1846
|
+
this.addSubcommands(this.data, options.subcommands);
|
|
1847
|
+
}
|
|
1848
|
+
if (options.groups && options?.groups?.length > 0) {
|
|
1849
|
+
this.addSubcommandGroups(options.groups);
|
|
1850
|
+
}
|
|
1851
|
+
import_zod6.z.object({
|
|
1852
|
+
description: import_zod6.z.string(),
|
|
1853
|
+
info: import_zod6.z.string(),
|
|
1854
|
+
category: import_zod6.z.string(),
|
|
1855
|
+
channelType: import_zod6.z.array(import_zod6.z.number()).or(import_zod6.z.number()),
|
|
1856
|
+
cooldown: import_zod6.z.number(),
|
|
1857
|
+
ignore: import_zod6.z.object({
|
|
1858
|
+
owner: import_zod6.z.boolean(),
|
|
1859
|
+
users: import_zod6.z.array(import_zod6.z.string()),
|
|
1860
|
+
channels: import_zod6.z.array(import_zod6.z.string()),
|
|
1861
|
+
guilds: import_zod6.z.array(import_zod6.z.string())
|
|
1862
|
+
}),
|
|
1863
|
+
strict: import_zod6.z.object({
|
|
1864
|
+
owner: import_zod6.z.boolean(),
|
|
1865
|
+
users: import_zod6.z.array(import_zod6.z.string()),
|
|
1866
|
+
channels: import_zod6.z.array(import_zod6.z.string()),
|
|
1867
|
+
guilds: import_zod6.z.array(import_zod6.z.string())
|
|
1868
|
+
}),
|
|
1869
|
+
permissions: import_zod6.z.object({
|
|
1870
|
+
client: import_zod6.z.array(import_zod6.z.string()),
|
|
1871
|
+
users: import_zod6.z.array(import_zod6.z.string()),
|
|
1872
|
+
dm: import_zod6.z.boolean()
|
|
1873
|
+
}),
|
|
1874
|
+
defer: import_zod6.z.object({
|
|
1875
|
+
reply: import_zod6.z.boolean(),
|
|
1876
|
+
ephemeral: import_zod6.z.boolean(),
|
|
1877
|
+
fetch: import_zod6.z.boolean()
|
|
1878
|
+
})
|
|
1879
|
+
}).deepPartial().parse(options);
|
|
1880
|
+
this.name = options.name;
|
|
1881
|
+
this.description = options.description;
|
|
1882
|
+
this.info = options.info;
|
|
1883
|
+
this.category = options.category;
|
|
1884
|
+
this.channelType = options.channelType;
|
|
1885
|
+
this.cooldown = options.cooldown;
|
|
1886
|
+
this.ignore = options.ignore;
|
|
1887
|
+
this.strict = options.strict;
|
|
1888
|
+
this.permissions = options.permissions;
|
|
1889
|
+
this.defer = options.defer;
|
|
1890
|
+
this.client = XernerxClient;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* TODO - update description
|
|
1894
|
+
* @param interaction
|
|
1895
|
+
*/
|
|
1896
|
+
async conditions(interaction) {
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* TODO - update description
|
|
1900
|
+
* @param interaction
|
|
1901
|
+
*/
|
|
1902
|
+
async exec(interaction) {
|
|
1903
|
+
}
|
|
1904
|
+
addArgs(command, args) {
|
|
1905
|
+
const types = ["boolean", "integer", "number", "string", "user", "role", "channel", "mentionable"];
|
|
1906
|
+
for (const argument of args) {
|
|
1907
|
+
if (!types.includes(argument.type.toLowerCase()))
|
|
1908
|
+
throw new XernerxError(`Expected one of ${types.join(", ")}, received ${argument.type} instead.`);
|
|
1909
|
+
let slashArgumentType = `${argument.type.slice(0, 1).toUpperCase()}${argument.type.slice(1).toLowerCase()}`;
|
|
1910
|
+
command[`add${slashArgumentType}Option`]((option) => {
|
|
1911
|
+
option.setName(argument.name).setDescription(argument.description).setRequired(argument.required || false);
|
|
1912
|
+
if (argument.choices)
|
|
1913
|
+
option.setChoices(...argument?.choices);
|
|
1914
|
+
return option;
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
addSubcommands(method, subcommands) {
|
|
1919
|
+
for (const subcommand of subcommands) {
|
|
1920
|
+
let sub = new import_discord6.SlashCommandSubcommandBuilder().setName(subcommand.name).setDescription(subcommand.description);
|
|
1921
|
+
if (subcommand.args?.length > 0)
|
|
1922
|
+
this.addArgs(sub, subcommand.args);
|
|
1923
|
+
method.addSubcommand(sub);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
addSubcommandGroups(groups) {
|
|
1927
|
+
for (const group of groups) {
|
|
1928
|
+
let subcommandGroup = new import_discord6.SlashCommandSubcommandGroupBuilder().setName(group.name).setDescription(group.description);
|
|
1929
|
+
if (group.subcommands?.length > 0)
|
|
1930
|
+
this.addSubcommands(subcommandGroup, group.subcommands);
|
|
1931
|
+
this.data.addSubcommandGroup(subcommandGroup);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
|
|
1936
|
+
// src/tools/package.ts
|
|
1937
|
+
var package_default = {
|
|
1938
|
+
name: "xernerx",
|
|
1939
|
+
version: "3.4.3",
|
|
1940
|
+
type: "module",
|
|
1941
|
+
description: "A bot framework for discord.js.",
|
|
1942
|
+
main: "dist/main.js",
|
|
1943
|
+
keywords: ["discord.js", "discord", "framework"],
|
|
1944
|
+
author: "Dummi",
|
|
1945
|
+
license: "MIT",
|
|
1946
|
+
homepage: "https://xernerx.github.io/xernerx/home.html",
|
|
1947
|
+
packageManager: "npm@8.5.5",
|
|
1948
|
+
scripts: {
|
|
1949
|
+
start: "npm i && npm fund && npm audit fix --force && npm link && tsc -w",
|
|
1950
|
+
patch: "npm run build && tsc && git add . && npm run commit && npm version patch && npm publish && git push",
|
|
1951
|
+
minor: "npm run build && tsc && git add . && npm run commit && npm version minor && npm publish && git push",
|
|
1952
|
+
major: "npm run build && tsc && git add . && npm run commit && npm version major && npm publish && git push",
|
|
1953
|
+
site: "git add docs && npm run commit && git push",
|
|
1954
|
+
commit: "node ../.scripts/commit.js",
|
|
1955
|
+
build: "node ../.scripts/rewritePackage.js"
|
|
1956
|
+
},
|
|
1957
|
+
repository: {
|
|
1958
|
+
type: "git",
|
|
1959
|
+
url: "git+https://github.com/xernerx/xernerx.git"
|
|
1960
|
+
},
|
|
1961
|
+
bugs: {
|
|
1962
|
+
url: "https://github.com/xernerx/xernerx/issues"
|
|
1963
|
+
},
|
|
1964
|
+
dependencies: {
|
|
1965
|
+
"@sapphire/shapeshift": "^3.8.1",
|
|
1966
|
+
"discord.js": "^14.7.0",
|
|
1967
|
+
dumfunctions: "^2.0.0",
|
|
1968
|
+
"xernerx-extension-builder": "^0.0.2"
|
|
1969
|
+
},
|
|
1970
|
+
devDependencies: {
|
|
1971
|
+
typescript: "^4.9.4"
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
|
|
1975
|
+
// src/main.ts
|
|
1976
|
+
var xernerxVersion = package_default.version;
|
|
1977
|
+
var main_default = {
|
|
1978
|
+
// Client
|
|
1979
|
+
Client: XernerxClient,
|
|
1980
|
+
XernerxClient,
|
|
1981
|
+
// Enums
|
|
1982
|
+
CommandType,
|
|
1983
|
+
EventEmitterType,
|
|
1984
|
+
InhibitorType,
|
|
1985
|
+
ContextCommandType,
|
|
1986
|
+
// Builds
|
|
1987
|
+
EventBuilder,
|
|
1988
|
+
MessageCommandBuilder,
|
|
1989
|
+
ContextCommandBuilder,
|
|
1990
|
+
SlashCommandBuilder,
|
|
1991
|
+
InhibitorBuilder,
|
|
1992
|
+
ExtensionBuilder: import_xernerx_extension_builder.default,
|
|
1993
|
+
XernerxError,
|
|
1994
|
+
// Constants
|
|
1995
|
+
version: xernerxVersion
|
|
1996
|
+
};
|
|
1997
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1998
|
+
0 && (module.exports = {
|
|
1999
|
+
CommandType,
|
|
2000
|
+
ContextCommandBuilder,
|
|
2001
|
+
ContextCommandType,
|
|
2002
|
+
EventBuilder,
|
|
2003
|
+
EventEmitterType,
|
|
2004
|
+
ExtensionBuilder,
|
|
2005
|
+
InhibitorBuilder,
|
|
2006
|
+
InhibitorType,
|
|
2007
|
+
MessageCommandBuilder,
|
|
2008
|
+
SlashCommandBuilder,
|
|
2009
|
+
XernerxClient,
|
|
2010
|
+
XernerxError,
|
|
2011
|
+
xernerxVersion
|
|
2012
|
+
});
|