gralonium 0.3.0 → 0.4.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/lib/classes/Client.d.ts +3 -1
- package/lib/classes/Client.js +1 -1
- package/lib/classes/Context.d.ts +40 -1
- package/lib/classes/Context.js +250 -11
- package/lib/classes/HelpCommand.d.ts +55 -13
- package/lib/classes/HelpCommand.js +319 -1
- package/lib/classes/Loader.d.ts +2 -0
- package/lib/classes/Loader.js +42 -39
- package/lib/classes/Utils.js +30 -11
- package/lib/classes/builders/CommandBuilder.d.ts +10 -0
- package/lib/classes/builders/CommandBuilder.js +16 -0
- package/lib/classes/builders/ComponentsV2Builder.d.ts +285 -113
- package/lib/classes/builders/ComponentsV2Builder.js +1069 -180
- package/lib/classes/builders/GroupBuilder.d.ts +9 -0
- package/lib/classes/builders/GroupBuilder.js +16 -0
- package/lib/classes/builders/InteractionBuilder.d.ts +40 -25
- package/lib/classes/builders/InteractionBuilder.js +102 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +1 -1
- package/lib/classes/builders/components/StyleMapper.js +2 -1
- package/lib/classes/builders/components/helpers.d.ts +68 -4
- package/lib/classes/builders/components/helpers.js +366 -7
- package/lib/classes/builders/components/templates.d.ts +151 -9
- package/lib/classes/builders/components/templates.js +376 -17
- package/lib/classes/builders/components/text.d.ts +24 -0
- package/lib/classes/builders/components/text.js +91 -0
- package/lib/classes/experiments/Confirmator.d.ts +44 -26
- package/lib/classes/experiments/Confirmator.js +37 -21
- package/lib/classes/experiments/Paginator.d.ts +48 -29
- package/lib/classes/experiments/Paginator.js +48 -19
- package/lib/classes/views/V2Paginator.d.ts +91 -0
- package/lib/classes/views/V2Paginator.js +268 -0
- package/lib/classes/views/V2View.d.ts +113 -0
- package/lib/classes/views/V2View.js +438 -0
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +9 -1
- package/lib/main.d.ts +3 -0
- package/lib/main.js +3 -0
- package/package.json +3 -1
|
@@ -1 +1,319 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HelpCommand = void 0;
|
|
4
|
+
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const { CommandBuilder } = require("./builders/CommandBuilder.js");
|
|
7
|
+
const { ParamsBuilder } = require("./builders/ParamsBuilder.js");
|
|
8
|
+
const { ComponentsV2Builder } = require("./builders/ComponentsV2Builder.js");
|
|
9
|
+
const { V2Paginator } = require("./views/V2Paginator.js");
|
|
10
|
+
|
|
11
|
+
const DEFAULT_LABELS = {
|
|
12
|
+
welcomeTitle: "Help",
|
|
13
|
+
welcomeDescription: "Welcome to my help",
|
|
14
|
+
notFound: "I was unable to find something related to that!",
|
|
15
|
+
usage: "Usage",
|
|
16
|
+
arguments: "Arguments",
|
|
17
|
+
noArguments: "Without arguments.",
|
|
18
|
+
subcommands: "Subcommands",
|
|
19
|
+
noSubcommands: "Without sub commands.",
|
|
20
|
+
commandsHeader: "Available commands",
|
|
21
|
+
footerSuffix: "'s Help",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Built-in help command supporting both classic Embed mode (default for backwards compatibility)
|
|
26
|
+
* and rich Components V2 mode (`useV2: true`) with optional pagination and custom labels.
|
|
27
|
+
*/
|
|
28
|
+
class HelpCommand {
|
|
29
|
+
options;
|
|
30
|
+
labels;
|
|
31
|
+
data;
|
|
32
|
+
plugins;
|
|
33
|
+
params;
|
|
34
|
+
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
this.options = options || {};
|
|
37
|
+
this.labels = { ...DEFAULT_LABELS, ...(this.options.labels || {}) };
|
|
38
|
+
this.plugins = Array.isArray(this.options.plugins) ? this.options.plugins : [];
|
|
39
|
+
|
|
40
|
+
this.data = new CommandBuilder({
|
|
41
|
+
name: this.options.name || "help",
|
|
42
|
+
aliases: this.options.aliases || ["h"],
|
|
43
|
+
description: this.options.description || "Shows this command",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.params = new ParamsBuilder().addString({
|
|
47
|
+
name: "query",
|
|
48
|
+
description: this.options.queryDescription || "An optional command/group/subcommand name",
|
|
49
|
+
required: false,
|
|
50
|
+
ellipsis: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async code(ctx) {
|
|
55
|
+
const query = ctx.get("query");
|
|
56
|
+
if (!query) {
|
|
57
|
+
return this.sendEmpty(ctx);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const command = this.getCommand(ctx, query);
|
|
61
|
+
if (command) {
|
|
62
|
+
return this.sendCommand(ctx, command);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const group = this.getGroup(ctx, query);
|
|
66
|
+
if (group) {
|
|
67
|
+
return this.sendGroup(ctx, group);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.sendNotFound(ctx);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#getVisibleCommandEntries(ctx) {
|
|
74
|
+
const hidden = new Set((this.options.hiddenCommands || []).map((n) => this.c(String(n))));
|
|
75
|
+
const prefix = ctx.prefix || "/";
|
|
76
|
+
const commands = ctx.bot.loader.walkCommands();
|
|
77
|
+
const seenGroups = new Set();
|
|
78
|
+
const entries = [];
|
|
79
|
+
|
|
80
|
+
for (const entry of commands) {
|
|
81
|
+
const name = entry.group ? `${entry.group.data.name} ${entry.data.name}` : entry.data.name;
|
|
82
|
+
if (hidden.has(this.c(entry.data.name)) || hidden.has(this.c(name))) continue;
|
|
83
|
+
if (typeof this.options.filterCommand === "function" && !this.options.filterCommand(entry, ctx)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (entry.group) {
|
|
88
|
+
const gName = entry.group.data.name;
|
|
89
|
+
if (!seenGroups.has(gName)) {
|
|
90
|
+
seenGroups.add(gName);
|
|
91
|
+
entries.push(`\`${prefix}${gName}\` — ${entry.group.data.description || "..."}`);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
entries.push(`\`${prefix}${entry.data.name}\` — ${entry.data.description || "..."}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return entries;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async sendEmpty(ctx) {
|
|
102
|
+
if (!this.options.useV2) {
|
|
103
|
+
await ctx.send({ embeds: [this.doEmbed(ctx).setDescription(this.labels.welcomeDescription)] });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const items = this.#getVisibleCommandEntries(ctx);
|
|
108
|
+
const botName = ctx.bot.user?.username || "Bot";
|
|
109
|
+
const cardColor = this.options.color ?? "Blurple";
|
|
110
|
+
const perPage = Math.max(1, Number(this.options.perPage) || 8);
|
|
111
|
+
|
|
112
|
+
if (items.length === 0) {
|
|
113
|
+
const card = ComponentsV2Builder.card({
|
|
114
|
+
color: cardColor,
|
|
115
|
+
title: this.labels.welcomeTitle,
|
|
116
|
+
description: this.labels.welcomeDescription,
|
|
117
|
+
thumbnail: ctx.bot.user?.displayAvatarURL?.(),
|
|
118
|
+
footer: `${botName}${this.labels.footerSuffix}`,
|
|
119
|
+
});
|
|
120
|
+
await ctx.send(card, { ephemeral: this.options.ephemeral });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.options.paginated !== false && items.length > perPage) {
|
|
125
|
+
const paginator = new V2Paginator({
|
|
126
|
+
author: ctx.author,
|
|
127
|
+
color: cardColor,
|
|
128
|
+
title: this.labels.welcomeTitle,
|
|
129
|
+
subtitle: this.labels.welcomeDescription,
|
|
130
|
+
thumbnail: ctx.bot.user?.displayAvatarURL?.(),
|
|
131
|
+
items,
|
|
132
|
+
perPage,
|
|
133
|
+
footer: `${botName}${this.labels.footerSuffix}`,
|
|
134
|
+
thirdPartyMode: this.options.thirdPartyMode || "reject",
|
|
135
|
+
closeButton: this.options.closeButton,
|
|
136
|
+
});
|
|
137
|
+
await paginator.send(ctx, { ephemeral: this.options.ephemeral });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const list = ComponentsV2Builder.list({
|
|
142
|
+
color: cardColor,
|
|
143
|
+
title: this.labels.welcomeTitle,
|
|
144
|
+
subtitle: this.labels.welcomeDescription,
|
|
145
|
+
thumbnail: ctx.bot.user?.displayAvatarURL?.(),
|
|
146
|
+
items,
|
|
147
|
+
footer: `${botName}${this.labels.footerSuffix}`,
|
|
148
|
+
});
|
|
149
|
+
await ctx.send(list, { ephemeral: this.options.ephemeral });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async sendNotFound(ctx) {
|
|
153
|
+
if (!this.options.useV2) {
|
|
154
|
+
await ctx.send(this.labels.notFound);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const card = ComponentsV2Builder.card({
|
|
159
|
+
color: this.options.errorColor ?? "danger",
|
|
160
|
+
description: this.labels.notFound,
|
|
161
|
+
});
|
|
162
|
+
await ctx.send(card, { ephemeral: this.options.ephemeral ?? true });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async sendCommand(ctx, command) {
|
|
166
|
+
const cmdName = command.data.aliases?.length
|
|
167
|
+
? `[${[command.data.name].concat(command.data.aliases).join("|")}]`
|
|
168
|
+
: command.data.name;
|
|
169
|
+
|
|
170
|
+
const groupName = command.group
|
|
171
|
+
? command.group.data.aliases?.length
|
|
172
|
+
? `[${[command.group.data.name].concat(command.group.data.aliases).join("|")}] `
|
|
173
|
+
: `${command.group.data.name} `
|
|
174
|
+
: "";
|
|
175
|
+
|
|
176
|
+
const argsDetails = command.params?.params?.length
|
|
177
|
+
? command.params.params.map((p) => `**${p.name}**${p.required ? "*" : "?"} :: ${p.description}`).join("\n")
|
|
178
|
+
: null;
|
|
179
|
+
|
|
180
|
+
const argsUsage = command.params?.params?.length
|
|
181
|
+
? command.params.params.map((p) => `${p.name}${p.required ? "*" : "?"}`).join(" ")
|
|
182
|
+
: "";
|
|
183
|
+
|
|
184
|
+
const usageStr = `${ctx.prefix}${groupName}${cmdName}${argsUsage ? ` ${argsUsage}` : ""}`.trim();
|
|
185
|
+
|
|
186
|
+
if (!this.options.useV2) {
|
|
187
|
+
await ctx.send({
|
|
188
|
+
embeds: [
|
|
189
|
+
this.doEmbed(ctx)
|
|
190
|
+
.setTitle(command.data.name)
|
|
191
|
+
.setDescription(command.data.description)
|
|
192
|
+
.addFields({ name: this.labels.usage, value: usageStr })
|
|
193
|
+
.addFields({ name: this.labels.arguments, value: argsDetails || this.labels.noArguments }),
|
|
194
|
+
],
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const botName = ctx.bot.user?.username || "Bot";
|
|
200
|
+
const card = ComponentsV2Builder.card({
|
|
201
|
+
color: this.options.color ?? "Blurple",
|
|
202
|
+
title: `### ${command.data.name}`,
|
|
203
|
+
subtitle: command.data.description,
|
|
204
|
+
thumbnail: ctx.bot.user?.displayAvatarURL?.(),
|
|
205
|
+
fields: [
|
|
206
|
+
[this.labels.usage, `\`${usageStr}\``],
|
|
207
|
+
[this.labels.arguments, argsDetails || this.labels.noArguments],
|
|
208
|
+
],
|
|
209
|
+
footer: `${botName}${this.labels.footerSuffix}`,
|
|
210
|
+
});
|
|
211
|
+
await ctx.send(card, { ephemeral: this.options.ephemeral });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async sendGroup(ctx, group) {
|
|
215
|
+
const groupTitle = group.data.aliases?.length
|
|
216
|
+
? `[${[group.data.name].concat(group.data.aliases).join("|")}] `
|
|
217
|
+
: group.data.name;
|
|
218
|
+
|
|
219
|
+
const subList = group.subcommands.map((sub) => `\`${group.data.name} ${sub.data.name}\` :: ${sub.data.description}`);
|
|
220
|
+
|
|
221
|
+
if (!this.options.useV2) {
|
|
222
|
+
await ctx.send({
|
|
223
|
+
embeds: [
|
|
224
|
+
this.doEmbed(ctx)
|
|
225
|
+
.setTitle(groupTitle)
|
|
226
|
+
.setDescription(group.data.description)
|
|
227
|
+
.addFields({ name: this.labels.subcommands, value: subList.length ? subList.join("\n") : this.labels.noSubcommands }),
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const botName = ctx.bot.user?.username || "Bot";
|
|
234
|
+
const card = ComponentsV2Builder.card({
|
|
235
|
+
color: this.options.color ?? "Blurple",
|
|
236
|
+
title: `### ${groupTitle.trim()}`,
|
|
237
|
+
subtitle: group.data.description,
|
|
238
|
+
thumbnail: ctx.bot.user?.displayAvatarURL?.(),
|
|
239
|
+
sections: [
|
|
240
|
+
{
|
|
241
|
+
heading: this.labels.subcommands,
|
|
242
|
+
text: subList.length ? subList.join("\n") : this.labels.noSubcommands,
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
footer: `${botName}${this.labels.footerSuffix}`,
|
|
246
|
+
});
|
|
247
|
+
await ctx.send(card, { ephemeral: this.options.ephemeral });
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
getCommand(ctx, query) {
|
|
251
|
+
const all = ctx.bot.loader.walkCommands();
|
|
252
|
+
const normalized = this.c(query);
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
all.find(
|
|
256
|
+
(cmd) =>
|
|
257
|
+
(!cmd.group && this.c(cmd.data.name) === normalized) ||
|
|
258
|
+
cmd.data.aliases.map((a) => this.c(a)).includes(normalized)
|
|
259
|
+
) ||
|
|
260
|
+
all
|
|
261
|
+
.filter((cmd) => cmd.group)
|
|
262
|
+
.map((cmd) => ({
|
|
263
|
+
...cmd,
|
|
264
|
+
regexp: new RegExp(
|
|
265
|
+
`^(${(cmd.group.data.aliases || []).concat(cmd.group.data.name).join("|")})( +)(${(cmd.data.aliases || [])
|
|
266
|
+
.concat(cmd.data.name)
|
|
267
|
+
.join("|")})$`,
|
|
268
|
+
"gi"
|
|
269
|
+
),
|
|
270
|
+
full: `${cmd.group.data.name} ${cmd.data.name}`,
|
|
271
|
+
}))
|
|
272
|
+
.find((cmd) => cmd.regexp.test(normalized)) ||
|
|
273
|
+
null
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
getGroup(ctx, query) {
|
|
278
|
+
const normalized = this.c(query);
|
|
279
|
+
const group = ctx.bot.loader
|
|
280
|
+
.walkCommands()
|
|
281
|
+
.filter((cmd) => cmd.group)
|
|
282
|
+
.map((cmd) => cmd.group)
|
|
283
|
+
.find(
|
|
284
|
+
(grp) => this.c(grp.data.name) === normalized || grp.data.aliases?.map((a) => this.c(a)).includes(normalized)
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (!group) return null;
|
|
288
|
+
|
|
289
|
+
const subcommands = ctx.bot.loader
|
|
290
|
+
.walkCommands()
|
|
291
|
+
.filter((cmd) => cmd.group && cmd.group.data.name === group.data.name)
|
|
292
|
+
.map((cmd) => ({
|
|
293
|
+
...cmd,
|
|
294
|
+
regexp: new RegExp(
|
|
295
|
+
`^(${(cmd.group.data.aliases || []).concat(cmd.group.data.name).join("|")})( +)(${(cmd.data.aliases || [])
|
|
296
|
+
.concat(cmd.data.name)
|
|
297
|
+
.join("|")})$`,
|
|
298
|
+
"gi"
|
|
299
|
+
),
|
|
300
|
+
full: `${cmd.group.data.name} ${cmd.data.name}`,
|
|
301
|
+
}));
|
|
302
|
+
|
|
303
|
+
return { ...group, subcommands };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
doEmbed(ctx) {
|
|
307
|
+
return new discord_js_1.EmbedBuilder()
|
|
308
|
+
.setAuthor({ name: ctx.author.username, iconURL: ctx.author.displayAvatarURL() })
|
|
309
|
+
.setTimestamp()
|
|
310
|
+
.setColor("Blurple")
|
|
311
|
+
.setFooter({ text: `${ctx.bot.user?.username}${this.labels.footerSuffix}`, iconURL: ctx.bot.user?.displayAvatarURL?.() });
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
c(str) {
|
|
315
|
+
return String(str).toLowerCase().trim();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
exports.HelpCommand = HelpCommand;
|
package/lib/classes/Loader.d.ts
CHANGED
|
@@ -80,10 +80,12 @@ export declare class Loader {
|
|
|
80
80
|
client: Gralonium;
|
|
81
81
|
commands: GraloniumCollected;
|
|
82
82
|
interactions: Record<InteractionTypes, Collection<string, ModuleData<InteractionBuilder>>>;
|
|
83
|
+
interactionMatchers: Map<InteractionTypes, ModuleData<InteractionBuilder>[]>;
|
|
83
84
|
globalPlugins: Plugin[];
|
|
84
85
|
rest: REST;
|
|
85
86
|
constructor(options: LoaderOptions);
|
|
86
87
|
load(dir: string, reload?: boolean): Promise<ModuleData<InteractionBuilder | CommandBuilder | EventBuilder | GroupBuilder, any[]>[]>;
|
|
88
|
+
resolvePatternInteraction(type: InteractionTypes, key: string, interaction?: any): ModuleData<InteractionBuilder> | null;
|
|
87
89
|
walkCommands(callable?: (command: Command<Types>) => number): CommandHelpingObject[];
|
|
88
90
|
sync(guildIDs?: string[]): Promise<void>;
|
|
89
91
|
}
|
package/lib/classes/Loader.js
CHANGED
|
@@ -56,6 +56,7 @@ class Loader {
|
|
|
56
56
|
};
|
|
57
57
|
this.globalPlugins = [];
|
|
58
58
|
this.rest = new discord_js_1.REST();
|
|
59
|
+
this.interactionMatchers = new Map();
|
|
59
60
|
this.#eventHandlers = new Map();
|
|
60
61
|
this.#loadedSignature = new Set();
|
|
61
62
|
}
|
|
@@ -98,6 +99,15 @@ class Loader {
|
|
|
98
99
|
#moduleSignature(moduleData) {
|
|
99
100
|
const data = moduleData?.data;
|
|
100
101
|
const type = data?.constructor?.name || "Unknown";
|
|
102
|
+
if (data instanceof InteractionBuilder_js_1.InteractionBuilder) {
|
|
103
|
+
const kind = data.type || "unknown";
|
|
104
|
+
const patternTag =
|
|
105
|
+
data.name ||
|
|
106
|
+
(data.prefix ? `prefix:${data.prefix}` : undefined) ||
|
|
107
|
+
(data.match ? `match:${String(data.match)}` : undefined) ||
|
|
108
|
+
(0, crypto_1.randomUUID)();
|
|
109
|
+
return `${type}:${kind}:${patternTag}`;
|
|
110
|
+
}
|
|
101
111
|
const name = data?.name || "unknown";
|
|
102
112
|
return `${type}:${name}`;
|
|
103
113
|
}
|
|
@@ -156,6 +166,7 @@ class Loader {
|
|
|
156
166
|
#resetCollectionsForReload() {
|
|
157
167
|
this.commands = { normal: new discord_js_1.Collection(), group: new discord_js_1.Collection() };
|
|
158
168
|
this.#loadedSignature.clear();
|
|
169
|
+
this.interactionMatchers.clear();
|
|
159
170
|
|
|
160
171
|
for (const key of Object.keys(this.interactions)) {
|
|
161
172
|
this.interactions[key].clear();
|
|
@@ -165,46 +176,38 @@ class Loader {
|
|
|
165
176
|
#storeInteraction(moduleData) {
|
|
166
177
|
const interaction = moduleData.data;
|
|
167
178
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
break;
|
|
199
|
-
case InteractionBuilder_js_1.Interactions.MentionableSelectMenu:
|
|
200
|
-
this.interactions.mentionableSelectMenu.set(interaction.name, moduleData);
|
|
201
|
-
break;
|
|
202
|
-
case InteractionBuilder_js_1.Interactions.AnyInteraction:
|
|
203
|
-
this.interactions.anyInteraction.set((0, crypto_1.randomUUID)(), moduleData);
|
|
204
|
-
break;
|
|
205
|
-
default:
|
|
206
|
-
break;
|
|
179
|
+
if (interaction.type === InteractionBuilder_js_1.Interactions.AnyInteraction) {
|
|
180
|
+
this.interactions.anyInteraction.set((0, crypto_1.randomUUID)(), moduleData);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const bucket = this.interactions[interaction.type];
|
|
185
|
+
if (!bucket) return;
|
|
186
|
+
|
|
187
|
+
if (interaction.name) {
|
|
188
|
+
bucket.set(interaction.name, moduleData);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (typeof interaction.hasPattern === "function" && interaction.hasPattern()) {
|
|
192
|
+
const list = this.interactionMatchers.get(interaction.type) || [];
|
|
193
|
+
list.push(moduleData);
|
|
194
|
+
this.interactionMatchers.set(interaction.type, list);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Resolves a dynamically matched interaction handler (`prefix` or `match`) for a given type and key.
|
|
200
|
+
*/
|
|
201
|
+
resolvePatternInteraction(type, key, interaction) {
|
|
202
|
+
const matchers = this.interactionMatchers.get(type);
|
|
203
|
+
if (!matchers?.length) return null;
|
|
204
|
+
|
|
205
|
+
for (const moduleData of matchers) {
|
|
206
|
+
if (moduleData.data?.matches?.(key, interaction)) {
|
|
207
|
+
return moduleData;
|
|
208
|
+
}
|
|
207
209
|
}
|
|
210
|
+
return null;
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
async load(dir, reload = false) {
|
package/lib/classes/Utils.js
CHANGED
|
@@ -591,20 +591,39 @@ class Utils {
|
|
|
591
591
|
return { command, group: null };
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
static #
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
594
|
+
static #extractInteractionLookup(interaction) {
|
|
595
|
+
const checks = [
|
|
596
|
+
["isAutocomplete", "autocomplete", "commandName"],
|
|
597
|
+
["isButton", "button", "customId"],
|
|
598
|
+
["isModalSubmit", "modalSubmit", "customId"],
|
|
599
|
+
["isMessageContextMenuCommand", "messageContextMenu", "commandName"],
|
|
600
|
+
["isUserContextMenuCommand", "userContextMenu", "commandName"],
|
|
601
|
+
["isChannelSelectMenu", "channelSelectMenu", "customId"],
|
|
602
|
+
["isMentionableSelectMenu", "mentionableSelectMenu", "customId"],
|
|
603
|
+
["isRoleSelectMenu", "roleSelectMenu", "customId"],
|
|
604
|
+
["isStringSelectMenu", "stringSelectMenu", "customId"],
|
|
605
|
+
["isUserSelectMenu", "userSelectMenu", "customId"],
|
|
606
|
+
];
|
|
607
|
+
|
|
608
|
+
for (const [guard, typeKey, prop] of checks) {
|
|
609
|
+
if (typeof interaction[guard] === "function" && interaction[guard]()) {
|
|
610
|
+
return { typeKey, key: interaction[prop] };
|
|
611
|
+
}
|
|
612
|
+
}
|
|
605
613
|
return null;
|
|
606
614
|
}
|
|
607
615
|
|
|
616
|
+
static #resolveInteractionModule(bot, interaction) {
|
|
617
|
+
const target = Utils.#extractInteractionLookup(interaction);
|
|
618
|
+
if (!target) return null;
|
|
619
|
+
|
|
620
|
+
const bucket = bot.loader.interactions?.[target.typeKey];
|
|
621
|
+
const exact = bucket?.get?.(target.key);
|
|
622
|
+
if (exact) return exact;
|
|
623
|
+
|
|
624
|
+
return bot.loader.resolvePatternInteraction?.(target.typeKey, target.key, interaction) || null;
|
|
625
|
+
}
|
|
626
|
+
|
|
608
627
|
static async #executeInteractionModule(bot, interaction, moduleData) {
|
|
609
628
|
if (!moduleData?.code) return;
|
|
610
629
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ApplicationIntegrationType, InteractionContextType } from "discord.js";
|
|
2
|
+
|
|
1
3
|
export declare function validateDefaultMemberPermissions(permissions: unknown): string | null | undefined;
|
|
2
4
|
|
|
3
5
|
export interface CommandDataBuilder {
|
|
@@ -14,6 +16,8 @@ export interface CommandDataBuilder {
|
|
|
14
16
|
botPermissions?: string[];
|
|
15
17
|
guards?: Array<(ctx: any) => boolean | Promise<boolean>>;
|
|
16
18
|
cooldown?: { seconds: number; bucket?: string };
|
|
19
|
+
integrationTypes?: Array<ApplicationIntegrationType | number>;
|
|
20
|
+
contexts?: Array<InteractionContextType | number>;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export declare class CommandBuilder {
|
|
@@ -30,6 +34,8 @@ export declare class CommandBuilder {
|
|
|
30
34
|
botPermissions: string[];
|
|
31
35
|
guards: Array<(ctx: any) => boolean | Promise<boolean>>;
|
|
32
36
|
cooldown?: { seconds: number; bucket?: string };
|
|
37
|
+
integrationTypes?: Array<ApplicationIntegrationType | number>;
|
|
38
|
+
contexts?: Array<InteractionContextType | number>;
|
|
33
39
|
constructor(options?: CommandDataBuilder);
|
|
34
40
|
setName(name: string): CommandBuilder;
|
|
35
41
|
setDescription(description: string): CommandBuilder;
|
|
@@ -41,10 +47,14 @@ export declare class CommandBuilder {
|
|
|
41
47
|
setUserPermissions(...permissions: string[]): CommandBuilder;
|
|
42
48
|
setBotPermissions(...permissions: string[]): CommandBuilder;
|
|
43
49
|
setCooldown(seconds: number, bucket?: string): CommandBuilder;
|
|
50
|
+
setIntegrationTypes(...types: Array<ApplicationIntegrationType | number | Array<ApplicationIntegrationType | number>>): CommandBuilder;
|
|
51
|
+
setContexts(...contexts: Array<InteractionContextType | number | Array<InteractionContextType | number>>): CommandBuilder;
|
|
44
52
|
toJSON(): {
|
|
45
53
|
name: string;
|
|
46
54
|
description: string;
|
|
47
55
|
default_member_permissions: string | null | undefined;
|
|
48
56
|
dm_permission: boolean | undefined;
|
|
57
|
+
integration_types?: Array<ApplicationIntegrationType | number>;
|
|
58
|
+
contexts?: Array<InteractionContextType | number>;
|
|
49
59
|
};
|
|
50
60
|
}
|
|
@@ -29,6 +29,8 @@ class CommandBuilder {
|
|
|
29
29
|
botPermissions;
|
|
30
30
|
guards;
|
|
31
31
|
cooldown;
|
|
32
|
+
integrationTypes;
|
|
33
|
+
contexts;
|
|
32
34
|
|
|
33
35
|
constructor(options) {
|
|
34
36
|
this.name = options?.name ?? "";
|
|
@@ -43,6 +45,8 @@ class CommandBuilder {
|
|
|
43
45
|
this.botPermissions = permissionArrayPredicate.parse(options?.botPermissions ?? []);
|
|
44
46
|
this.guards = options?.guards ?? [];
|
|
45
47
|
this.cooldown = options?.cooldown;
|
|
48
|
+
this.integrationTypes = options?.integrationTypes;
|
|
49
|
+
this.contexts = options?.contexts;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
setName(name) {
|
|
@@ -95,12 +99,24 @@ class CommandBuilder {
|
|
|
95
99
|
return this;
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
setIntegrationTypes(...types) {
|
|
103
|
+
this.integrationTypes = types.flat();
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setContexts(...contexts) {
|
|
108
|
+
this.contexts = contexts.flat();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
98
112
|
toJSON() {
|
|
99
113
|
return {
|
|
100
114
|
name: this.name,
|
|
101
115
|
description: this.description,
|
|
102
116
|
default_member_permissions: this.defaultMemberPermissions ? validateDefaultMemberPermissions(this.defaultMemberPermissions) : undefined,
|
|
103
117
|
dm_permission: typeof this.guildOnly === "boolean" ? !this.guildOnly : undefined,
|
|
118
|
+
...(this.integrationTypes !== undefined ? { integration_types: this.integrationTypes } : {}),
|
|
119
|
+
...(this.contexts !== undefined ? { contexts: this.contexts } : {}),
|
|
104
120
|
};
|
|
105
121
|
}
|
|
106
122
|
}
|