gralonium 0.3.0 → 0.4.1

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.
Files changed (44) hide show
  1. package/lib/classes/Client.d.ts +9 -3
  2. package/lib/classes/Client.js +2 -2
  3. package/lib/classes/Context.d.ts +42 -1
  4. package/lib/classes/Context.js +276 -13
  5. package/lib/classes/Cooldowns.d.ts +2 -0
  6. package/lib/classes/Cooldowns.js +28 -0
  7. package/lib/classes/HelpCommand.d.ts +55 -13
  8. package/lib/classes/HelpCommand.js +319 -1
  9. package/lib/classes/Loader.d.ts +10 -1
  10. package/lib/classes/Loader.js +143 -58
  11. package/lib/classes/Plugins.js +3 -2
  12. package/lib/classes/Utils.d.ts +1 -1
  13. package/lib/classes/Utils.js +103 -24
  14. package/lib/classes/builders/CommandBuilder.d.ts +24 -0
  15. package/lib/classes/builders/CommandBuilder.js +66 -2
  16. package/lib/classes/builders/ComponentsV2Builder.d.ts +288 -113
  17. package/lib/classes/builders/ComponentsV2Builder.js +1071 -180
  18. package/lib/classes/builders/GroupBuilder.d.ts +20 -0
  19. package/lib/classes/builders/GroupBuilder.js +37 -1
  20. package/lib/classes/builders/InteractionBuilder.d.ts +86 -25
  21. package/lib/classes/builders/InteractionBuilder.js +212 -1
  22. package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
  23. package/lib/classes/builders/ParamsBuilder.js +167 -1
  24. package/lib/classes/builders/components/StyleMapper.d.ts +14 -2
  25. package/lib/classes/builders/components/StyleMapper.js +35 -9
  26. package/lib/classes/builders/components/helpers.d.ts +68 -4
  27. package/lib/classes/builders/components/helpers.js +366 -7
  28. package/lib/classes/builders/components/templates.d.ts +151 -9
  29. package/lib/classes/builders/components/templates.js +376 -17
  30. package/lib/classes/builders/components/text.d.ts +24 -0
  31. package/lib/classes/builders/components/text.js +91 -0
  32. package/lib/classes/experiments/Confirmator.d.ts +44 -26
  33. package/lib/classes/experiments/Confirmator.js +37 -21
  34. package/lib/classes/experiments/Paginator.d.ts +48 -29
  35. package/lib/classes/experiments/Paginator.js +48 -19
  36. package/lib/classes/views/V2Paginator.d.ts +91 -0
  37. package/lib/classes/views/V2Paginator.js +268 -0
  38. package/lib/classes/views/V2View.d.ts +113 -0
  39. package/lib/classes/views/V2View.js +438 -0
  40. package/lib/experiments.d.ts +2 -0
  41. package/lib/experiments.js +9 -1
  42. package/lib/main.d.ts +3 -0
  43. package/lib/main.js +3 -0
  44. package/package.json +3 -1
@@ -1 +1,319 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HelpCommand=void 0;const main_js_1=require("../main.js");class HelpCommand{data=new main_js_1.CommandBuilder({name:"help",aliases:["h"],description:"Shows this command"});plugins=[];params=(new main_js_1.ParamsBuilder).addString({name:"query",description:"An optional command/group/subcommand name",required:!1,ellipsis:!0});async code(a){var e;return a.get("query")?(e=this.getCommand(a,a.get("query")))?this.sendCommand(a,e):(e=this.getGroup(a,a.get("query")))?this.sendGroup(a,e):this.sendNotFound(a):this.sendEmpty(a)}async sendEmpty(a){await a.send({embeds:[this.doEmbed(a).setDescription("Welcome to my help")]})}async sendNotFound(a){await a.send("I was unable to find something related to that!")}async sendCommand(a,e){var t=e.data.aliases.length?`[${[e.data.name].concat(e.data.aliases).join("|")}]`:e.data.name,n=e.group?e.group.data.aliases?.length?`[${[e.group.data.name].concat(e.group.data.aliases).join("|")}] `:e.group.data.name+" ":"",s=e.params?.params.length?e.params.params.map(a=>`**${a.name}**${a.required?"*":"?"} :: `+a.description).join("\n"):null,d=e.params?.params.length?e.params.params.map(a=>""+a.name+(a.required?"*":"?")).join(" "):"";await a.send({embeds:[this.doEmbed(a).setTitle(e.data.name).setDescription(e.data.description).addFields({name:"Usage",value:a.prefix+n+t+" "+d}).addFields({name:"Arguments",value:s||"Without arguments."})]})}async sendGroup(a,e){var t=e.data.aliases?.length?`[${[e.data.name].concat(e.data.aliases).join("|")}] `:e.data.name,n=e.subcommands.map(a=>`\`${e.data.name} ${a.data.name}\` :: `+a.data.description);await a.send({embeds:[this.doEmbed(a).setTitle(t).setDescription(e.data.description).addFields({name:"Subcommands",value:n.length?n.join("\n"):"Without sub commands."})]})}getCommand(a,e){let t=a.bot.loader.walkCommands();return e=this.c(e),(a=t.find(a=>!a.group&&this.c(a.data.name)==e||a.data.aliases.map(this.c).includes(e)))||(t=t.filter(a=>a.group).map(a=>({...a,regexp:new RegExp(`^(${(a.group.data.aliases||[]).concat(a.group.data.name).join("|")})( +)(${(a.data.aliases||[]).concat(a.data.name).join("|")})$`,"gi"),full:a.group.data.name+" "+a.data.name}))).find(a=>a.regexp.test(e))||null}getGroup(a,e){e=this.c(e);let t=a.bot.loader.walkCommands().filter(a=>a.group).map(a=>a.group).find(a=>this.c(a.data.name)==e||a.data.aliases?.map(this.c).includes(e));return t?(a=a.bot.loader.walkCommands().filter(a=>a.group&&a.group.data.name==t.data.name).map(a=>({...a,regexp:new RegExp(`^(${(a.group.data.aliases||[]).concat(a.group.data.name).join("|")})( +)(${(a.data.aliases||[]).concat(a.data.name).join("|")})$`,"gi"),full:a.group.data.name+" "+a.data.name})),{...t,subcommands:a}):null}doEmbed(a){return(new main_js_1.EmbedBuilder).setAuthor({name:a.author.username,iconURL:a.author.displayAvatarURL()}).setTimestamp().setColor("Blurple").setFooter({text:a.bot.user?.username+"'s Help",iconURL:a.bot.user.displayAvatarURL()})}c(a){return a.toLowerCase().trim()}}exports.HelpCommand=HelpCommand;
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;
@@ -76,14 +76,23 @@ type InteractionTypes =
76
76
  | "mentionableSelectMenu"
77
77
  | "anyInteraction";
78
78
 
79
+ export type CommandLocalizer = (
80
+ commandJSON: Record<string, any>
81
+ ) => Record<string, any> | void | Promise<Record<string, any> | void>;
82
+
79
83
  export declare class Loader {
80
84
  client: Gralonium;
81
85
  commands: GraloniumCollected;
82
86
  interactions: Record<InteractionTypes, Collection<string, ModuleData<InteractionBuilder>>>;
87
+ interactionMatchers: Map<InteractionTypes, ModuleData<InteractionBuilder>[]>;
88
+ localizer: CommandLocalizer | null;
83
89
  globalPlugins: Plugin[];
84
90
  rest: REST;
85
91
  constructor(options: LoaderOptions);
92
+ setLocalizer(localizer: CommandLocalizer | null): this;
86
93
  load(dir: string, reload?: boolean): Promise<ModuleData<InteractionBuilder | CommandBuilder | EventBuilder | GroupBuilder, any[]>[]>;
94
+ resolvePatternInteraction(type: InteractionTypes, key: string, interaction?: any): ModuleData<InteractionBuilder> | null;
87
95
  walkCommands(callable?: (command: Command<Types>) => number): CommandHelpingObject[];
88
- sync(guildIDs?: string[]): Promise<void>;
96
+ buildApplicationCommands(): Promise<Record<string, any>[]>;
97
+ sync(guildIDs?: string[]): Promise<Record<string, any>[]>;
89
98
  }
@@ -56,10 +56,20 @@ class Loader {
56
56
  };
57
57
  this.globalPlugins = [];
58
58
  this.rest = new discord_js_1.REST();
59
+ this.interactionMatchers = new Map();
60
+ this.localizer = options.client?.ops?.localizeCommand ?? null;
59
61
  this.#eventHandlers = new Map();
60
62
  this.#loadedSignature = new Set();
61
63
  }
62
64
 
65
+ /**
66
+ * Registers a global command localization transformer executed before syncing application commands.
67
+ */
68
+ setLocalizer(localizer) {
69
+ this.localizer = typeof localizer === "function" ? localizer : null;
70
+ return this;
71
+ }
72
+
63
73
  #toAbsolutePath(inputPath) {
64
74
  if ((0, path_1.isAbsolute)(inputPath)) return inputPath;
65
75
  return (0, path_1.join)((0, process_1.cwd)(), inputPath);
@@ -90,14 +100,48 @@ class Loader {
90
100
  const mod = require(absolute)?.data;
91
101
  if (!mod) continue;
92
102
 
93
- if (Array.isArray(mod)) output.push(...mod);
94
- else output.push(mod);
103
+ if (Array.isArray(mod)) {
104
+ for (const item of mod) {
105
+ const normalized = this.#normalizeLoadedModule(item);
106
+ if (normalized) output.push(normalized);
107
+ }
108
+ } else {
109
+ const normalized = this.#normalizeLoadedModule(mod);
110
+ if (normalized) output.push(normalized);
111
+ }
112
+ }
113
+ }
114
+
115
+ #normalizeLoadedModule(item) {
116
+ if (!item || typeof item !== "object") return null;
117
+ if (!item.data && typeof item.name === "string" && typeof item.code === "function") {
118
+ return {
119
+ data: new EventBuilder_js_1.EventBuilder({
120
+ name: item.name,
121
+ once: Boolean(item.once),
122
+ description: item.description,
123
+ }),
124
+ code: item.code,
125
+ };
95
126
  }
127
+ return item;
96
128
  }
97
129
 
98
130
  #moduleSignature(moduleData) {
99
131
  const data = moduleData?.data;
100
132
  const type = data?.constructor?.name || "Unknown";
133
+ if (data instanceof EventBuilder_js_1.EventBuilder) {
134
+ return `${type}:${data.name}:${(0, crypto_1.randomUUID)()}`;
135
+ }
136
+ if (data instanceof InteractionBuilder_js_1.InteractionBuilder) {
137
+ const kind = data.type || "unknown";
138
+ const patternTag =
139
+ data.name ||
140
+ (data.prefix ? `prefix:${data.prefix}` : undefined) ||
141
+ (data.match ? `match:${String(data.match)}` : undefined) ||
142
+ (0, crypto_1.randomUUID)();
143
+ return `${type}:${kind}:${patternTag}`;
144
+ }
101
145
  const name = data?.name || "unknown";
102
146
  return `${type}:${name}`;
103
147
  }
@@ -156,6 +200,7 @@ class Loader {
156
200
  #resetCollectionsForReload() {
157
201
  this.commands = { normal: new discord_js_1.Collection(), group: new discord_js_1.Collection() };
158
202
  this.#loadedSignature.clear();
203
+ this.interactionMatchers.clear();
159
204
 
160
205
  for (const key of Object.keys(this.interactions)) {
161
206
  this.interactions[key].clear();
@@ -165,48 +210,40 @@ class Loader {
165
210
  #storeInteraction(moduleData) {
166
211
  const interaction = moduleData.data;
167
212
 
168
- switch (interaction.type) {
169
- case InteractionBuilder_js_1.Interactions.Autocomplete:
170
- this.interactions.autocomplete.set(interaction.name, moduleData);
171
- break;
172
- case InteractionBuilder_js_1.Interactions.Button:
173
- this.interactions.button.set(interaction.name, moduleData);
174
- break;
175
- case InteractionBuilder_js_1.Interactions.ChannelSelectMenu:
176
- this.interactions.channelSelectMenu.set(interaction.name, moduleData);
177
- break;
178
- case InteractionBuilder_js_1.Interactions.ChatInput:
179
- this.interactions.chatInput.set(interaction.name, moduleData);
180
- break;
181
- case InteractionBuilder_js_1.Interactions.MessageContextMenu:
182
- this.interactions.messageContextMenu.set(interaction.name, moduleData);
183
- break;
184
- case InteractionBuilder_js_1.Interactions.Modal:
185
- this.interactions.modalSubmit.set(interaction.name, moduleData);
186
- break;
187
- case InteractionBuilder_js_1.Interactions.RoleSelectMenu:
188
- this.interactions.roleSelectMenu.set(interaction.name, moduleData);
189
- break;
190
- case InteractionBuilder_js_1.Interactions.StringSelectMenu:
191
- this.interactions.stringSelectMenu.set(interaction.name, moduleData);
192
- break;
193
- case InteractionBuilder_js_1.Interactions.UserContextMenu:
194
- this.interactions.userContextMenu.set(interaction.name, moduleData);
195
- break;
196
- case InteractionBuilder_js_1.Interactions.UserSelectMenu:
197
- this.interactions.userSelectMenu.set(interaction.name, moduleData);
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;
213
+ if (interaction.type === InteractionBuilder_js_1.Interactions.AnyInteraction) {
214
+ this.interactions.anyInteraction.set((0, crypto_1.randomUUID)(), moduleData);
215
+ return;
216
+ }
217
+
218
+ const bucket = this.interactions[interaction.type];
219
+ if (!bucket) return;
220
+
221
+ if (interaction.name) {
222
+ bucket.set(interaction.name, moduleData);
223
+ }
224
+
225
+ if (typeof interaction.hasPattern === "function" && interaction.hasPattern()) {
226
+ const list = this.interactionMatchers.get(interaction.type) || [];
227
+ list.push(moduleData);
228
+ this.interactionMatchers.set(interaction.type, list);
207
229
  }
208
230
  }
209
231
 
232
+ /**
233
+ * Resolves a dynamically matched interaction handler (`prefix` or `match`) for a given type and key.
234
+ */
235
+ resolvePatternInteraction(type, key, interaction) {
236
+ const matchers = this.interactionMatchers.get(type);
237
+ if (!matchers?.length) return null;
238
+
239
+ for (const moduleData of matchers) {
240
+ if (moduleData.data?.matches?.(key, interaction)) {
241
+ return moduleData;
242
+ }
243
+ }
244
+ return null;
245
+ }
246
+
210
247
  async load(dir, reload = false) {
211
248
  const modules = [];
212
249
  const absoluteDir = this.#toAbsolutePath(dir);
@@ -271,9 +308,18 @@ class Loader {
271
308
  return output.sort(sorter);
272
309
  }
273
310
 
311
+ #serializeCommandParams(paramsBuilder) {
312
+ if (!paramsBuilder) return [];
313
+ if (typeof paramsBuilder.toJSON === "function") {
314
+ return paramsBuilder.toJSON();
315
+ }
316
+ return paramsBuilder.params || [];
317
+ }
318
+
274
319
  #buildTopLevelSlash(command) {
275
320
  const payload = { ...command.data.toJSON() };
276
- payload.options = command.params?.params || [];
321
+ payload.type = discord_js_1.ApplicationCommandType.ChatInput;
322
+ payload.options = this.#serializeCommandParams(command.params);
277
323
  return payload;
278
324
  }
279
325
 
@@ -282,7 +328,7 @@ class Loader {
282
328
  const subCommandJSON = { ...commandRef.data.toJSON() };
283
329
 
284
330
  subCommandJSON.type = 1;
285
- subCommandJSON.options = commandRef.params?.params || [];
331
+ subCommandJSON.options = this.#serializeCommandParams(commandRef.params);
286
332
 
287
333
  if (subCommandJSON.default_member_permissions === undefined && groupJSON.default_member_permissions !== undefined) {
288
334
  subCommandJSON.default_member_permissions = groupJSON.default_member_permissions;
@@ -312,46 +358,85 @@ class Loader {
312
358
  payloads.push(groupPayload);
313
359
  }
314
360
 
315
- async sync(guildIDs) {
316
- if (!this.client.token) {
317
- throw new Error("Cannot sync application commands before login token is set.");
318
- }
319
-
320
- if (!this.client.user?.id) {
321
- throw new Error("Cannot sync application commands before client is ready.");
322
- }
323
-
324
- this.rest.setToken(this.client.token);
325
-
361
+ /**
362
+ * Builds all application command payloads (ChatInput slash commands + User/Message Context Menus)
363
+ * and applies the configured localization hook if set.
364
+ */
365
+ async buildApplicationCommands() {
326
366
  const commands = this.walkCommands();
327
367
  const payload = [];
328
- const slashNames = new Set();
368
+ const registeredSignatures = new Set();
329
369
 
330
370
  for (const command of commands) {
331
371
  if (!command.data.as_slash) continue;
332
372
 
333
373
  if (!command.group) {
334
374
  const built = this.#buildTopLevelSlash(command);
335
- if (slashNames.has(built.name)) {
375
+ const sig = `${built.type}:${built.name}`;
376
+ if (registeredSignatures.has(sig)) {
336
377
  throw new Error(`Duplicate slash command name detected during sync: ${built.name}`);
337
378
  }
338
- slashNames.add(built.name);
379
+ registeredSignatures.add(sig);
339
380
  payload.push(built);
340
381
  continue;
341
382
  }
342
383
 
343
384
  if (!command.group.data.as_slash) continue;
344
385
  this.#mergeGroupSlashPayload(payload, command.group, command);
386
+ registeredSignatures.add(`${discord_js_1.ApplicationCommandType.ChatInput}:${command.group.data.name}`);
387
+ }
388
+
389
+ const contextMenuCollections = [this.interactions.userContextMenu, this.interactions.messageContextMenu];
390
+ for (const collection of contextMenuCollections) {
391
+ for (const entry of collection.values()) {
392
+ if (entry?.data?.as_command === false || !entry?.data?.name) continue;
393
+ const built = entry.data.toCommandJSON();
394
+ if (!built) continue;
395
+ const sig = `${built.type}:${built.name}`;
396
+ if (registeredSignatures.has(sig)) {
397
+ throw new Error(`Duplicate context menu command detected during sync: ${built.name}`);
398
+ }
399
+ registeredSignatures.add(sig);
400
+ payload.push(built);
401
+ }
402
+ }
403
+
404
+ const localizer = this.localizer ?? this.client?.ops?.localizeCommand;
405
+ if (typeof localizer === "function") {
406
+ for (let i = 0; i < payload.length; i += 1) {
407
+ const transformed = await localizer(payload[i]);
408
+ if (transformed && typeof transformed === "object") {
409
+ payload[i] = transformed;
410
+ }
411
+ }
412
+ }
413
+
414
+ return payload;
415
+ }
416
+
417
+ async sync(guildIDs) {
418
+ if (!this.client.token) {
419
+ throw new Error("Cannot sync application commands before login token is set.");
345
420
  }
346
421
 
422
+ if (!this.client.user?.id) {
423
+ throw new Error("Cannot sync application commands before client is ready.");
424
+ }
425
+
426
+ this.rest.setToken(this.client.token);
427
+
428
+ const payload = await this.buildApplicationCommands();
429
+
347
430
  if (!guildIDs?.length) {
348
431
  await this.rest.put(discord_js_1.Routes.applicationCommands(this.client.user.id), { body: payload });
349
- return;
432
+ return payload;
350
433
  }
351
434
 
352
435
  for (const guildID of guildIDs) {
353
436
  await this.rest.put(discord_js_1.Routes.applicationGuildCommands(this.client.user.id, guildID), { body: payload });
354
437
  }
438
+
439
+ return payload;
355
440
  }
356
441
  }
357
442
  exports.Loader = Loader;
@@ -91,11 +91,12 @@ function cooldown(seconds, bucket) {
91
91
  }
92
92
 
93
93
  const cooldownInMs = 1000 * seconds;
94
+ const commandKey = Cooldowns_js_1.Cooldowns.resolveKey(ctx.command, ctx.parent);
94
95
 
95
- const active = await ctx.bot.cooldowns.check(ctx.command.data.name, source, cooldownInMs, bucket);
96
+ const active = await ctx.bot.cooldowns.check(commandKey, source, cooldownInMs, bucket);
96
97
  if (active) throw new Errors.CommandInCooldown(ctx, active.left);
97
98
 
98
- await ctx.bot.cooldowns.setCooldownSource(ctx.command.data.name, source, bucket, cooldownInMs);
99
+ await ctx.bot.cooldowns.setCooldownSource(commandKey, source, bucket, cooldownInMs);
99
100
  return true;
100
101
  };
101
102
  }
@@ -10,7 +10,7 @@ export declare class Utils {
10
10
  static getChannel<T = DJS.Channel>(query: string, options: { guild: DJS.Guild; force?: boolean }): Promise<T | null>;
11
11
  static getRole(query: string, options: { guild: DJS.Guild; force?: boolean }): Promise<DJS.Role | null>;
12
12
  static getUser(query: string, bot: Gralonium): Promise<DJS.User | null>;
13
- static transform(input: string, param: P.BaseParam, ctx: Context, seeable?: boolean): Promise<{ break: boolean; value: any }>;
13
+ static transform(input: string, param: P.BaseParam, ctx: Context, seeable?: boolean, attachmentIndex?: number): Promise<{ break: boolean; value: any }>;
14
14
  static executeCommand(
15
15
  ctx: Context,
16
16
  command: Command<Types.Normal>,