@carzo/enire 3.0.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 +57 -0
- package/lib/classes/Client.d.ts +37 -0
- package/lib/classes/Client.js +125 -0
- package/lib/classes/Context.d.ts +24 -0
- package/lib/classes/Context.js +87 -0
- package/lib/classes/Cooldowns.d.ts +22 -0
- package/lib/classes/Cooldowns.js +1 -0
- package/lib/classes/Errors.d.ts +135 -0
- package/lib/classes/Errors.js +1 -0
- package/lib/classes/HelpCommand.d.ts +15 -0
- package/lib/classes/HelpCommand.js +1 -0
- package/lib/classes/Loader.d.ts +85 -0
- package/lib/classes/Loader.js +302 -0
- package/lib/classes/Plugins.d.ts +52 -0
- package/lib/classes/Plugins.js +107 -0
- package/lib/classes/Utils.d.ts +25 -0
- package/lib/classes/Utils.js +563 -0
- package/lib/classes/builders/CommandBuilder.d.ts +44 -0
- package/lib/classes/builders/CommandBuilder.js +91 -0
- package/lib/classes/builders/EventBuilder.d.ts +19 -0
- package/lib/classes/builders/EventBuilder.js +1 -0
- package/lib/classes/builders/GroupBuilder.d.ts +40 -0
- package/lib/classes/builders/GroupBuilder.js +72 -0
- package/lib/classes/builders/InteractionBuilder.d.ts +32 -0
- package/lib/classes/builders/InteractionBuilder.js +1 -0
- package/lib/classes/builders/ParamsBuilder.d.ts +87 -0
- package/lib/classes/builders/ParamsBuilder.js +1 -0
- package/lib/classes/experiments/Confirmator.d.ts +58 -0
- package/lib/classes/experiments/Confirmator.js +1 -0
- package/lib/classes/experiments/Paginator.d.ts +65 -0
- package/lib/classes/experiments/Paginator.js +1 -0
- package/lib/events/interactionCreate.d.ts +4 -0
- package/lib/events/interactionCreate.js +17 -0
- package/lib/events/messageCreate.d.ts +4 -0
- package/lib/events/messageCreate.js +17 -0
- package/lib/events/messageUpdate.d.ts +4 -0
- package/lib/events/messageUpdate.js +17 -0
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +1 -0
- package/lib/main.d.ts +15 -0
- package/lib/main.js +22 -0
- package/package.json +55 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Loader = exports.Types = void 0;
|
|
4
|
+
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const process_1 = require("process");
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const Client_js_1 = require("./Client.js");
|
|
11
|
+
const CommandBuilder_js_1 = require("./builders/CommandBuilder.js");
|
|
12
|
+
const GroupBuilder_js_1 = require("./builders/GroupBuilder.js");
|
|
13
|
+
const EventBuilder_js_1 = require("./builders/EventBuilder.js");
|
|
14
|
+
const InteractionBuilder_js_1 = require("./builders/InteractionBuilder.js");
|
|
15
|
+
|
|
16
|
+
const isValidFile = (file) => {
|
|
17
|
+
if (file.endsWith(".d.ts")) return false;
|
|
18
|
+
return file.endsWith(".js") || file.endsWith(".mjs") || file.endsWith(".ts") || file.endsWith(".mts");
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var Types;
|
|
22
|
+
(function (Types) {
|
|
23
|
+
Types["Normal"] = "normal";
|
|
24
|
+
Types["Group"] = "group";
|
|
25
|
+
})(Types || (exports.Types = Types = {}));
|
|
26
|
+
|
|
27
|
+
class Loader {
|
|
28
|
+
client;
|
|
29
|
+
commands;
|
|
30
|
+
interactions;
|
|
31
|
+
globalPlugins;
|
|
32
|
+
listeners;
|
|
33
|
+
rest;
|
|
34
|
+
#eventHandlers;
|
|
35
|
+
|
|
36
|
+
constructor(options) {
|
|
37
|
+
if (!(options?.client instanceof Client_js_1.Enire)) {
|
|
38
|
+
throw new SyntaxError("Invalid client provided in options");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.client = options.client;
|
|
42
|
+
this.commands = { normal: null, group: null };
|
|
43
|
+
this.interactions = {
|
|
44
|
+
autocomplete: new discord_js_1.Collection(),
|
|
45
|
+
button: new discord_js_1.Collection(),
|
|
46
|
+
chatInput: new discord_js_1.Collection(),
|
|
47
|
+
modalSubmit: new discord_js_1.Collection(),
|
|
48
|
+
userContextMenu: new discord_js_1.Collection(),
|
|
49
|
+
messageContextMenu: new discord_js_1.Collection(),
|
|
50
|
+
channelSelectMenu: new discord_js_1.Collection(),
|
|
51
|
+
roleSelectMenu: new discord_js_1.Collection(),
|
|
52
|
+
stringSelectMenu: new discord_js_1.Collection(),
|
|
53
|
+
userSelectMenu: new discord_js_1.Collection(),
|
|
54
|
+
mentionableSelectMenu: new discord_js_1.Collection(),
|
|
55
|
+
anyInteraction: new discord_js_1.Collection(),
|
|
56
|
+
};
|
|
57
|
+
this.globalPlugins = [];
|
|
58
|
+
this.listeners = null;
|
|
59
|
+
this.rest = new discord_js_1.REST();
|
|
60
|
+
this.#eventHandlers = new Map();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#toAbsolutePath(inputPath) {
|
|
64
|
+
if ((0, path_1.isAbsolute)(inputPath)) return inputPath;
|
|
65
|
+
return (0, path_1.join)((0, process_1.cwd)(), inputPath);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#collectModules(dirPath, reload, output) {
|
|
69
|
+
const entries = (0, fs_1.readdirSync)(dirPath);
|
|
70
|
+
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const absolute = (0, path_1.join)(dirPath, entry);
|
|
73
|
+
const stat = (0, fs_1.lstatSync)(absolute);
|
|
74
|
+
|
|
75
|
+
if (stat.isDirectory()) {
|
|
76
|
+
this.#collectModules(absolute, reload, output);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!isValidFile(entry)) continue;
|
|
81
|
+
|
|
82
|
+
if (reload) {
|
|
83
|
+
try {
|
|
84
|
+
delete require.cache[require.resolve(absolute)];
|
|
85
|
+
} catch {
|
|
86
|
+
/* ignore */
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const mod = require(absolute)?.data;
|
|
91
|
+
if (!mod) continue;
|
|
92
|
+
|
|
93
|
+
if (Array.isArray(mod)) output.push(...mod);
|
|
94
|
+
else output.push(mod);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#attachEvent(moduleData) {
|
|
99
|
+
const eventData = moduleData.data;
|
|
100
|
+
const key = `${eventData.name}:${(0, crypto_1.randomUUID)()}`;
|
|
101
|
+
const handler = (...args) => moduleData.code?.(this.client, ...args);
|
|
102
|
+
|
|
103
|
+
this.#eventHandlers.set(key, { eventName: eventData.name, handler });
|
|
104
|
+
|
|
105
|
+
if (eventData.once) this.client.once(eventData.name, handler);
|
|
106
|
+
else this.client.on(eventData.name, handler);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#clearEventHandlers() {
|
|
110
|
+
for (const { eventName, handler } of this.#eventHandlers.values()) {
|
|
111
|
+
this.client.off(eventName, handler);
|
|
112
|
+
}
|
|
113
|
+
this.#eventHandlers.clear();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#resetCollectionsForReload() {
|
|
117
|
+
this.commands = { normal: new discord_js_1.Collection(), group: new discord_js_1.Collection() };
|
|
118
|
+
|
|
119
|
+
for (const key of Object.keys(this.interactions)) {
|
|
120
|
+
this.interactions[key].clear();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#storeInteraction(moduleData) {
|
|
125
|
+
const interaction = moduleData.data;
|
|
126
|
+
|
|
127
|
+
switch (interaction.type) {
|
|
128
|
+
case InteractionBuilder_js_1.Interactions.Autocomplete:
|
|
129
|
+
this.interactions.autocomplete.set(interaction.name, moduleData);
|
|
130
|
+
break;
|
|
131
|
+
case InteractionBuilder_js_1.Interactions.Button:
|
|
132
|
+
this.interactions.button.set(interaction.name, moduleData);
|
|
133
|
+
break;
|
|
134
|
+
case InteractionBuilder_js_1.Interactions.ChannelSelectMenu:
|
|
135
|
+
this.interactions.channelSelectMenu.set(interaction.name, moduleData);
|
|
136
|
+
break;
|
|
137
|
+
case InteractionBuilder_js_1.Interactions.ChatInput:
|
|
138
|
+
this.interactions.chatInput.set(interaction.name, moduleData);
|
|
139
|
+
break;
|
|
140
|
+
case InteractionBuilder_js_1.Interactions.MessageContextMenu:
|
|
141
|
+
this.interactions.messageContextMenu.set(interaction.name, moduleData);
|
|
142
|
+
break;
|
|
143
|
+
case InteractionBuilder_js_1.Interactions.Modal:
|
|
144
|
+
this.interactions.modalSubmit.set(interaction.name, moduleData);
|
|
145
|
+
break;
|
|
146
|
+
case InteractionBuilder_js_1.Interactions.RoleSelectMenu:
|
|
147
|
+
this.interactions.roleSelectMenu.set(interaction.name, moduleData);
|
|
148
|
+
break;
|
|
149
|
+
case InteractionBuilder_js_1.Interactions.StringSelectMenu:
|
|
150
|
+
this.interactions.stringSelectMenu.set(interaction.name, moduleData);
|
|
151
|
+
break;
|
|
152
|
+
case InteractionBuilder_js_1.Interactions.UserContextMenu:
|
|
153
|
+
this.interactions.userContextMenu.set(interaction.name, moduleData);
|
|
154
|
+
break;
|
|
155
|
+
case InteractionBuilder_js_1.Interactions.UserSelectMenu:
|
|
156
|
+
this.interactions.userSelectMenu.set(interaction.name, moduleData);
|
|
157
|
+
break;
|
|
158
|
+
case InteractionBuilder_js_1.Interactions.MentionableSelectMenu:
|
|
159
|
+
this.interactions.mentionableSelectMenu.set(interaction.name, moduleData);
|
|
160
|
+
break;
|
|
161
|
+
case InteractionBuilder_js_1.Interactions.AnyInteraction:
|
|
162
|
+
this.interactions.anyInteraction.set((0, crypto_1.randomUUID)(), moduleData);
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async load(dir, reload = false) {
|
|
170
|
+
const modules = [];
|
|
171
|
+
const absoluteDir = this.#toAbsolutePath(dir);
|
|
172
|
+
|
|
173
|
+
if (!(0, fs_1.existsSync)(absoluteDir)) {
|
|
174
|
+
throw new Error(`Path not found: ${absoluteDir}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (reload) {
|
|
178
|
+
this.#clearEventHandlers();
|
|
179
|
+
this.#resetCollectionsForReload();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.#collectModules(absoluteDir, reload, modules);
|
|
183
|
+
|
|
184
|
+
for (const moduleData of modules) {
|
|
185
|
+
if (moduleData.data instanceof EventBuilder_js_1.EventBuilder) {
|
|
186
|
+
this.#attachEvent(moduleData);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (moduleData.data instanceof InteractionBuilder_js_1.InteractionBuilder) {
|
|
191
|
+
this.#storeInteraction(moduleData);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (moduleData.data instanceof CommandBuilder_js_1.CommandBuilder) {
|
|
196
|
+
if (!this.commands.normal) this.commands.normal = new discord_js_1.Collection();
|
|
197
|
+
this.commands.normal.set(moduleData.data.name, moduleData);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (moduleData.data instanceof GroupBuilder_js_1.GroupBuilder) {
|
|
202
|
+
if (!this.commands.group) this.commands.group = new discord_js_1.Collection();
|
|
203
|
+
this.commands.group.set(moduleData.data.name, moduleData);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return modules;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
walkCommands(sorter = () => 0) {
|
|
211
|
+
const output = [];
|
|
212
|
+
|
|
213
|
+
if (this.commands.normal) {
|
|
214
|
+
output.push(...this.commands.normal.map((command) => ({ ...command, group: null })));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (this.commands.group) {
|
|
218
|
+
for (const group of this.commands.group.values()) {
|
|
219
|
+
for (const command of group.data.commands) {
|
|
220
|
+
output.push({ ...command, group });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return output.sort(sorter);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#buildTopLevelSlash(command) {
|
|
229
|
+
const payload = { ...command.data.toJSON() };
|
|
230
|
+
payload.options = command.params?.params || [];
|
|
231
|
+
return payload;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#mergeGroupSlashPayload(payloads, groupRef, commandRef) {
|
|
235
|
+
const groupJSON = { ...groupRef.data.toJSON() };
|
|
236
|
+
const subCommandJSON = { ...commandRef.data.toJSON() };
|
|
237
|
+
|
|
238
|
+
subCommandJSON.type = 1;
|
|
239
|
+
subCommandJSON.options = commandRef.params?.params || [];
|
|
240
|
+
|
|
241
|
+
if (subCommandJSON.default_member_permissions === undefined && groupJSON.default_member_permissions !== undefined) {
|
|
242
|
+
subCommandJSON.default_member_permissions = groupJSON.default_member_permissions;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (subCommandJSON.dm_permission === undefined && groupJSON.dm_permission !== undefined) {
|
|
246
|
+
subCommandJSON.dm_permission = groupJSON.dm_permission;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const existingIndex = payloads.findIndex((entry) => entry.name === groupJSON.name && entry.type === 1);
|
|
250
|
+
|
|
251
|
+
if (existingIndex >= 0) {
|
|
252
|
+
payloads[existingIndex].options ||= [];
|
|
253
|
+
payloads[existingIndex].options.push(subCommandJSON);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const groupPayload = {
|
|
258
|
+
...groupJSON,
|
|
259
|
+
type: 1,
|
|
260
|
+
options: [subCommandJSON],
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
payloads.push(groupPayload);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async sync(guildIDs) {
|
|
267
|
+
if (!this.client.token) {
|
|
268
|
+
throw new Error("Cannot sync application commands before login token is set.");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (!this.client.user?.id) {
|
|
272
|
+
throw new Error("Cannot sync application commands before client is ready.");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.rest.setToken(this.client.token);
|
|
276
|
+
|
|
277
|
+
const commands = this.walkCommands();
|
|
278
|
+
const payload = [];
|
|
279
|
+
|
|
280
|
+
for (const command of commands) {
|
|
281
|
+
if (!command.data.as_slash) continue;
|
|
282
|
+
|
|
283
|
+
if (!command.group) {
|
|
284
|
+
payload.push(this.#buildTopLevelSlash(command));
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (!command.group.data.as_slash) continue;
|
|
289
|
+
this.#mergeGroupSlashPayload(payload, command.group, command);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (!guildIDs?.length) {
|
|
293
|
+
await this.rest.put(discord_js_1.Routes.applicationCommands(this.client.user.id), { body: payload });
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
for (const guildID of guildIDs) {
|
|
298
|
+
await this.rest.put(discord_js_1.Routes.applicationGuildCommands(this.client.user.id, guildID), { body: payload });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.Loader = Loader;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Context } from "./Context.js";
|
|
2
|
+
import { ChannelType, PermissionsString } from "discord.js";
|
|
3
|
+
import { Bucket } from "./Cooldowns.js";
|
|
4
|
+
import { AsyncFunction } from "./Loader.js";
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the author is in a guild (Guild Only)
|
|
7
|
+
*/
|
|
8
|
+
export declare function isGuild(ctx: Context): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the author is in specified channel types
|
|
11
|
+
* @param types The channel types
|
|
12
|
+
*/
|
|
13
|
+
export declare function isInChannelType(...types: ChannelType[]): (ctx: Context) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the author is in a NSFW channel
|
|
16
|
+
*/
|
|
17
|
+
export declare function isNSFW(ctx: Context): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the author is a bot owner
|
|
20
|
+
*/
|
|
21
|
+
export declare function isOwner(ctx: Context): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the bot has any of the specified permissions in this guild
|
|
24
|
+
* @param permissions The bot permissions
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasAnyBotPerms(...permissions: PermissionsString[]): (ctx: Context) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the bot has ALL of the specified permissions in this guild
|
|
29
|
+
* @param permissions The required bot permissions
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasBotPerms(...permissions: PermissionsString[]): (ctx: Context) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the author has any of the specified permissions in this guild
|
|
34
|
+
* @param permissions The author permissions
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasAnyPerms(...permissions: PermissionsString[]): (ctx: Context) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the author has ALL of the specified permissions in this guild
|
|
39
|
+
* @param permissions The required author permissions
|
|
40
|
+
*/
|
|
41
|
+
export declare function hasPerms(...permissions: PermissionsString[]): (ctx: Context) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the Bucket has a cooldown in this command
|
|
44
|
+
* @param seconds The cooldown for this command
|
|
45
|
+
* @param bucket The type of object to set the cooldown, ex: Bucket.User, Bucket.Member
|
|
46
|
+
*/
|
|
47
|
+
export declare function cooldown(seconds: number, bucket: Bucket): (ctx: Context) => Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Checks a custom condition using an async function
|
|
50
|
+
* @param predicate The async function
|
|
51
|
+
*/
|
|
52
|
+
export declare function check<T = Context>(predicate: AsyncFunction<T, boolean>): AsyncFunction<T, boolean>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.check = exports.cooldown = exports.hasPerms = exports.hasAnyPerms = exports.hasBotPerms = exports.hasAnyBotPerms = exports.isOwner = exports.isNSFW = exports.isInChannelType = exports.isGuild = void 0;
|
|
4
|
+
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const Errors = tslib_1.__importStar(require("./Errors.js"));
|
|
8
|
+
const Cooldowns_js_1 = require("./Cooldowns.js");
|
|
9
|
+
|
|
10
|
+
function isGuild(ctx) {
|
|
11
|
+
if (ctx.channel?.type === discord_js_1.ChannelType.DM) throw new Errors.GuildOnly(ctx);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
exports.isGuild = isGuild;
|
|
15
|
+
|
|
16
|
+
function isInChannelType(...types) {
|
|
17
|
+
return function (ctx) {
|
|
18
|
+
if (ctx.channel && types.includes(ctx.channel.type)) return true;
|
|
19
|
+
throw new Errors.NotInChannelType(ctx, types, ctx.channel);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.isInChannelType = isInChannelType;
|
|
23
|
+
|
|
24
|
+
function isNSFW(ctx) {
|
|
25
|
+
if (!ctx.channel || !("nsfw" in ctx.channel) || !ctx.channel.nsfw) {
|
|
26
|
+
throw new Errors.NotNSFW(ctx);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
exports.isNSFW = isNSFW;
|
|
32
|
+
|
|
33
|
+
function isOwner(ctx) {
|
|
34
|
+
if (ctx.bot.ops.owners?.includes(ctx.author.id)) return true;
|
|
35
|
+
throw new Errors.NotOwner(ctx);
|
|
36
|
+
}
|
|
37
|
+
exports.isOwner = isOwner;
|
|
38
|
+
|
|
39
|
+
function hasAnyBotPerms(...permissions) {
|
|
40
|
+
return function (ctx) {
|
|
41
|
+
if (permissions.some((permission) => ctx.guild?.members.me?.permissions.has(permission))) return true;
|
|
42
|
+
throw new Errors.MissingBotPermission(ctx, permissions);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.hasAnyBotPerms = hasAnyBotPerms;
|
|
46
|
+
|
|
47
|
+
function hasBotPerms(...permissions) {
|
|
48
|
+
return function (ctx) {
|
|
49
|
+
if (permissions.every((permission) => ctx.guild?.members.me?.permissions.has(permission))) return true;
|
|
50
|
+
throw new Errors.MissingBotPermission(ctx, permissions);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.hasBotPerms = hasBotPerms;
|
|
54
|
+
|
|
55
|
+
function hasAnyPerms(...permissions) {
|
|
56
|
+
return function (ctx) {
|
|
57
|
+
if (permissions.some((permission) => ctx.member?.permissions?.has?.(permission))) return true;
|
|
58
|
+
throw new Errors.MissingPermission(ctx, permissions);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.hasAnyPerms = hasAnyPerms;
|
|
62
|
+
|
|
63
|
+
function hasPerms(...permissions) {
|
|
64
|
+
return function (ctx) {
|
|
65
|
+
if (permissions.every((permission) => ctx.member?.permissions?.has?.(permission))) return true;
|
|
66
|
+
throw new Errors.MissingPermission(ctx, permissions);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.hasPerms = hasPerms;
|
|
70
|
+
|
|
71
|
+
function cooldown(seconds, bucket) {
|
|
72
|
+
return async function (ctx) {
|
|
73
|
+
let source = "-1";
|
|
74
|
+
|
|
75
|
+
switch (bucket) {
|
|
76
|
+
case Cooldowns_js_1.Bucket.Guild:
|
|
77
|
+
source = ctx.guild?.id || "-1";
|
|
78
|
+
break;
|
|
79
|
+
case Cooldowns_js_1.Bucket.Member:
|
|
80
|
+
source = ctx.guild ? `${ctx.guild.id}_${ctx.author.id}` : ctx.author.id;
|
|
81
|
+
break;
|
|
82
|
+
case Cooldowns_js_1.Bucket.User:
|
|
83
|
+
source = ctx.author.id;
|
|
84
|
+
break;
|
|
85
|
+
case Cooldowns_js_1.Bucket.Channel:
|
|
86
|
+
source = ctx.channel?.id || "-1";
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
source = ctx.author.id;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const cooldownInMs = 1000 * seconds;
|
|
94
|
+
|
|
95
|
+
const active = await ctx.bot.cooldowns.check(ctx.command.data.name, source, cooldownInMs, bucket);
|
|
96
|
+
if (active) throw new Errors.CommandInCooldown(ctx, active.left);
|
|
97
|
+
|
|
98
|
+
await ctx.bot.cooldowns.setCooldownSource(ctx.command.data.name, source, bucket, cooldownInMs);
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.cooldown = cooldown;
|
|
103
|
+
|
|
104
|
+
function check(predicate) {
|
|
105
|
+
return predicate;
|
|
106
|
+
}
|
|
107
|
+
exports.check = check;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command, Types } from "../classes/Loader.js";
|
|
2
|
+
import * as P from "./builders/ParamsBuilder.js";
|
|
3
|
+
import { Context } from "./Context.js";
|
|
4
|
+
import { Enire } from "./Client.js";
|
|
5
|
+
import * as DJS from "discord.js";
|
|
6
|
+
|
|
7
|
+
export declare class Utils {
|
|
8
|
+
static isType<T, R>(obj: any, func: (obj: R) => boolean): obj is T;
|
|
9
|
+
static noop(n?: null): null;
|
|
10
|
+
static getMember(query: string, options: { guild: DJS.Guild; force: boolean }): Promise<DJS.GuildMember | null>;
|
|
11
|
+
static getChannel<T = DJS.Channel>(query: string, options: { guild: DJS.Guild; force?: boolean }): Promise<T | null>;
|
|
12
|
+
static getRole(query: string, options: { guild: DJS.Guild; force?: boolean }): Promise<DJS.Role | null>;
|
|
13
|
+
static getUser(query: string, bot: Enire): Promise<DJS.User | null>;
|
|
14
|
+
static transform(input: string, param: P.BaseParam, ctx: Context, seeable?: boolean): Promise<{ break: boolean; value: any }>;
|
|
15
|
+
static executeCommand(
|
|
16
|
+
ctx: Context,
|
|
17
|
+
command: Command<Types.Normal>,
|
|
18
|
+
options: { group?: Command<Types.Group> | null; source: "prefix" | "slash"; args?: string[] | null; interaction?: DJS.ChatInputCommandInteraction | null; prefix?: string }
|
|
19
|
+
): Promise<void>;
|
|
20
|
+
static handleMessage(bot: Enire, message: DJS.Message, isEdit?: boolean): Promise<void>;
|
|
21
|
+
static handleInteraction(bot: Enire, interaction: DJS.Interaction): Promise<void>;
|
|
22
|
+
static runPrefixCommand(ctx: Context, command: Command<Types.Normal>, args: string[], group?: Command<Types.Group>): Promise<void>;
|
|
23
|
+
static runInteractionCommand(ctx: Context, int: DJS.ChatInputCommandInteraction): Promise<void>;
|
|
24
|
+
static splitArgs(text: string, special?: boolean, removeNewLines?: boolean): string[];
|
|
25
|
+
}
|