gralonium 0.2.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.
Files changed (47) hide show
  1. package/lib/classes/Client.d.ts +9 -11
  2. package/lib/classes/Client.js +10 -13
  3. package/lib/classes/Context.d.ts +43 -4
  4. package/lib/classes/Context.js +251 -12
  5. package/lib/classes/Cooldowns.d.ts +3 -3
  6. package/lib/classes/Cooldowns.js +3 -8
  7. package/lib/classes/HelpCommand.d.ts +55 -13
  8. package/lib/classes/HelpCommand.js +319 -1
  9. package/lib/classes/Loader.d.ts +17 -11
  10. package/lib/classes/Loader.js +43 -42
  11. package/lib/classes/Utils.d.ts +4 -5
  12. package/lib/classes/Utils.js +32 -21
  13. package/lib/classes/builders/CommandBuilder.d.ts +10 -0
  14. package/lib/classes/builders/CommandBuilder.js +16 -0
  15. package/lib/classes/builders/ComponentsV2Builder.d.ts +285 -113
  16. package/lib/classes/builders/ComponentsV2Builder.js +1069 -182
  17. package/lib/classes/builders/GroupBuilder.d.ts +9 -0
  18. package/lib/classes/builders/GroupBuilder.js +16 -0
  19. package/lib/classes/builders/InteractionBuilder.d.ts +40 -25
  20. package/lib/classes/builders/InteractionBuilder.js +102 -1
  21. package/lib/classes/builders/components/StyleMapper.d.ts +1 -1
  22. package/lib/classes/builders/components/StyleMapper.js +2 -1
  23. package/lib/classes/builders/components/helpers.d.ts +68 -4
  24. package/lib/classes/builders/components/helpers.js +366 -7
  25. package/lib/classes/builders/components/templates.d.ts +151 -9
  26. package/lib/classes/builders/components/templates.js +376 -17
  27. package/lib/classes/builders/components/text.d.ts +24 -0
  28. package/lib/classes/builders/components/text.js +91 -0
  29. package/lib/classes/experiments/Confirmator.d.ts +45 -50
  30. package/lib/classes/experiments/Confirmator.js +37 -21
  31. package/lib/classes/experiments/Paginator.d.ts +49 -56
  32. package/lib/classes/experiments/Paginator.js +48 -19
  33. package/lib/classes/views/V2Paginator.d.ts +91 -0
  34. package/lib/classes/views/V2Paginator.js +268 -0
  35. package/lib/classes/views/V2View.d.ts +113 -0
  36. package/lib/classes/views/V2View.js +438 -0
  37. package/lib/experiments.d.ts +2 -0
  38. package/lib/experiments.js +9 -1
  39. package/lib/main.d.ts +3 -3
  40. package/lib/main.js +5 -5
  41. package/package.json +6 -15
  42. package/lib/events/interactionCreate.d.ts +0 -4
  43. package/lib/events/interactionCreate.js +0 -17
  44. package/lib/events/messageCreate.d.ts +0 -4
  45. package/lib/events/messageCreate.js +0 -17
  46. package/lib/events/messageUpdate.d.ts +0 -4
  47. package/lib/events/messageUpdate.js +0 -17
@@ -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;
@@ -4,20 +4,20 @@ import { CommandBuilder } from "./builders/CommandBuilder.js";
4
4
  import { ParamsBuilder } from "./builders/ParamsBuilder.js";
5
5
  import { EventBuilder } from "./builders/EventBuilder.js";
6
6
  import { GroupBuilder } from "./builders/GroupBuilder.js";
7
- import { Plugins as EnirePlugins } from "../main.js";
7
+ import { Plugins as GraloniumPlugins } from "../main.js";
8
8
  import { Context } from "./Context.js";
9
- import { Enire } from "./Client.js";
9
+ import { Gralonium } from "./Client.js";
10
10
 
11
11
  export interface ModuleData<T extends unknown = unknown, K extends any[] = any[]> {
12
12
  data: CommandBuilder | GroupBuilder | InteractionBuilder | EventBuilder;
13
- plugins?: T extends CommandBuilder ? (typeof EnirePlugins[] | Plugin[]) : never;
13
+ plugins?: T extends CommandBuilder ? (typeof GraloniumPlugins[] | Plugin[]) : never;
14
14
  params?: T extends CommandBuilder ? ParamsBuilder : never;
15
15
  code?: T extends CommandBuilder
16
16
  ? (ctx: Context) => Promise<void>
17
17
  : T extends InteractionBuilder
18
18
  ? (interaction: any) => Promise<void>
19
19
  : T extends EventBuilder
20
- ? (bot: Enire, ...args: K) => Promise<void>
20
+ ? (bot: Gralonium, ...args: K) => Promise<void>
21
21
  : undefined;
22
22
  }
23
23
 
@@ -44,20 +44,25 @@ export declare enum Types {
44
44
 
45
45
  export type Command<K extends keyof CommandStructures = "normal"> = CommandStructures[K];
46
46
 
47
- interface EnireCollected {
47
+ interface GraloniumCollected {
48
48
  normal: Collection<string, Command<"normal">> | null;
49
49
  group: Collection<string, Command<"group">> | null;
50
50
  }
51
51
 
52
52
  interface LoaderOptions {
53
- client: Enire;
53
+ client: Gralonium;
54
54
  }
55
55
 
56
56
  export interface CommandHelpingObject extends Command<Types.Normal> {
57
57
  group: Command<Types.Group> | null;
58
58
  }
59
59
 
60
- type ErineInteractionTypes =
60
+ export interface GroupHelpingObject {
61
+ data: GroupBuilder;
62
+ subcommands: CommandHelpingObject[];
63
+ }
64
+
65
+ type InteractionTypes =
61
66
  | "autocomplete"
62
67
  | "button"
63
68
  | "chatInput"
@@ -72,14 +77,15 @@ type ErineInteractionTypes =
72
77
  | "anyInteraction";
73
78
 
74
79
  export declare class Loader {
75
- client: Enire;
76
- commands: EnireCollected;
77
- interactions: Record<ErineInteractionTypes, Collection<string, ModuleData<InteractionBuilder>>>;
80
+ client: Gralonium;
81
+ commands: GraloniumCollected;
82
+ interactions: Record<InteractionTypes, Collection<string, ModuleData<InteractionBuilder>>>;
83
+ interactionMatchers: Map<InteractionTypes, ModuleData<InteractionBuilder>[]>;
78
84
  globalPlugins: Plugin[];
79
- listeners: Collection<string, ModuleData<InteractionBuilder>> | null;
80
85
  rest: REST;
81
86
  constructor(options: LoaderOptions);
82
87
  load(dir: string, reload?: boolean): Promise<ModuleData<InteractionBuilder | CommandBuilder | EventBuilder | GroupBuilder, any[]>[]>;
88
+ resolvePatternInteraction(type: InteractionTypes, key: string, interaction?: any): ModuleData<InteractionBuilder> | null;
83
89
  walkCommands(callable?: (command: Command<Types>) => number): CommandHelpingObject[];
84
90
  sync(guildIDs?: string[]): Promise<void>;
85
91
  }
@@ -29,13 +29,12 @@ class Loader {
29
29
  commands;
30
30
  interactions;
31
31
  globalPlugins;
32
- listeners;
33
32
  rest;
34
33
  #eventHandlers;
35
34
  #loadedSignature;
36
35
 
37
36
  constructor(options) {
38
- if (!(options?.client instanceof Client_js_1.Enire)) {
37
+ if (!(options?.client instanceof Client_js_1.Gralonium)) {
39
38
  throw new SyntaxError("Invalid client provided in options");
40
39
  }
41
40
 
@@ -56,8 +55,8 @@ class Loader {
56
55
  anyInteraction: new discord_js_1.Collection(),
57
56
  };
58
57
  this.globalPlugins = [];
59
- this.listeners = null;
60
58
  this.rest = new discord_js_1.REST();
59
+ this.interactionMatchers = new Map();
61
60
  this.#eventHandlers = new Map();
62
61
  this.#loadedSignature = new Set();
63
62
  }
@@ -100,6 +99,15 @@ class Loader {
100
99
  #moduleSignature(moduleData) {
101
100
  const data = moduleData?.data;
102
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
+ }
103
111
  const name = data?.name || "unknown";
104
112
  return `${type}:${name}`;
105
113
  }
@@ -158,6 +166,7 @@ class Loader {
158
166
  #resetCollectionsForReload() {
159
167
  this.commands = { normal: new discord_js_1.Collection(), group: new discord_js_1.Collection() };
160
168
  this.#loadedSignature.clear();
169
+ this.interactionMatchers.clear();
161
170
 
162
171
  for (const key of Object.keys(this.interactions)) {
163
172
  this.interactions[key].clear();
@@ -167,46 +176,38 @@ class Loader {
167
176
  #storeInteraction(moduleData) {
168
177
  const interaction = moduleData.data;
169
178
 
170
- switch (interaction.type) {
171
- case InteractionBuilder_js_1.Interactions.Autocomplete:
172
- this.interactions.autocomplete.set(interaction.name, moduleData);
173
- break;
174
- case InteractionBuilder_js_1.Interactions.Button:
175
- this.interactions.button.set(interaction.name, moduleData);
176
- break;
177
- case InteractionBuilder_js_1.Interactions.ChannelSelectMenu:
178
- this.interactions.channelSelectMenu.set(interaction.name, moduleData);
179
- break;
180
- case InteractionBuilder_js_1.Interactions.ChatInput:
181
- this.interactions.chatInput.set(interaction.name, moduleData);
182
- break;
183
- case InteractionBuilder_js_1.Interactions.MessageContextMenu:
184
- this.interactions.messageContextMenu.set(interaction.name, moduleData);
185
- break;
186
- case InteractionBuilder_js_1.Interactions.Modal:
187
- this.interactions.modalSubmit.set(interaction.name, moduleData);
188
- break;
189
- case InteractionBuilder_js_1.Interactions.RoleSelectMenu:
190
- this.interactions.roleSelectMenu.set(interaction.name, moduleData);
191
- break;
192
- case InteractionBuilder_js_1.Interactions.StringSelectMenu:
193
- this.interactions.stringSelectMenu.set(interaction.name, moduleData);
194
- break;
195
- case InteractionBuilder_js_1.Interactions.UserContextMenu:
196
- this.interactions.userContextMenu.set(interaction.name, moduleData);
197
- break;
198
- case InteractionBuilder_js_1.Interactions.UserSelectMenu:
199
- this.interactions.userSelectMenu.set(interaction.name, moduleData);
200
- break;
201
- case InteractionBuilder_js_1.Interactions.MentionableSelectMenu:
202
- this.interactions.mentionableSelectMenu.set(interaction.name, moduleData);
203
- break;
204
- case InteractionBuilder_js_1.Interactions.AnyInteraction:
205
- this.interactions.anyInteraction.set((0, crypto_1.randomUUID)(), moduleData);
206
- break;
207
- default:
208
- 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
+ }
209
209
  }
210
+ return null;
210
211
  }
211
212
 
212
213
  async load(dir, reload = false) {
@@ -1,24 +1,23 @@
1
1
  import { Command, Types } from "../classes/Loader.js";
2
2
  import * as P from "./builders/ParamsBuilder.js";
3
3
  import { Context } from "./Context.js";
4
- import { Enire } from "./Client.js";
4
+ import { Gralonium } from "./Client.js";
5
5
  import * as DJS from "discord.js";
6
6
 
7
7
  export declare class Utils {
8
- static isType<T, R>(obj: any, func: (obj: R) => boolean): obj is T;
9
8
  static noop(n?: null): null;
10
9
  static getMember(query: string, options: { guild: DJS.Guild; force: boolean }): Promise<DJS.GuildMember | null>;
11
10
  static getChannel<T = DJS.Channel>(query: string, options: { guild: DJS.Guild; force?: boolean }): Promise<T | null>;
12
11
  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>;
12
+ static getUser(query: string, bot: Gralonium): Promise<DJS.User | null>;
14
13
  static transform(input: string, param: P.BaseParam, ctx: Context, seeable?: boolean): Promise<{ break: boolean; value: any }>;
15
14
  static executeCommand(
16
15
  ctx: Context,
17
16
  command: Command<Types.Normal>,
18
17
  options: { group?: Command<Types.Group> | null; source: "prefix" | "slash"; args?: string[] | null; interaction?: DJS.ChatInputCommandInteraction | null; prefix?: string }
19
18
  ): Promise<void>;
20
- static handleMessage(bot: Enire, message: DJS.Message, isEdit?: boolean): Promise<void>;
21
- static handleInteraction(bot: Enire, interaction: DJS.Interaction): Promise<void>;
19
+ static handleMessage(bot: Gralonium, message: DJS.Message, isEdit?: boolean): Promise<void>;
20
+ static handleInteraction(bot: Gralonium, interaction: DJS.Interaction): Promise<void>;
22
21
  static runPrefixCommand(ctx: Context, command: Command<Types.Normal>, args: string[], group?: Command<Types.Group>): Promise<void>;
23
22
  static runInteractionCommand(ctx: Context, int: DJS.ChatInputCommandInteraction): Promise<void>;
24
23
  static splitArgs(text: string, special?: boolean, removeNewLines?: boolean): string[];
@@ -9,10 +9,6 @@ const Errors = tslib_1.__importStar(require("./Errors.js"));
9
9
  const Cooldowns_js_1 = require("./Cooldowns.js");
10
10
 
11
11
  class Utils {
12
- static isType(obj, func) {
13
- return func(obj);
14
- }
15
-
16
12
  static noop(n = null) {
17
13
  return n;
18
14
  }
@@ -137,19 +133,15 @@ class Utils {
137
133
  return paramsBuilder.params.map((param) => ({ ...param, value: undefined }));
138
134
  }
139
135
 
140
- static #normalizeChoiceInput(input) {
141
- return String(input ?? "").toLowerCase().trim();
142
- }
143
-
144
136
  static async transform(input, param, ctx, seeable = true) {
145
137
  if (!input && seeable) {
146
138
  return { break: false, value: null };
147
139
  }
148
140
 
149
141
  if (param.choices?.length) {
150
- const normalizedInput = Utils.#normalizeChoiceInput(input);
142
+ const normalizedInput = Utils.#toLower(input);
151
143
  const selected = param.choices.find(
152
- (choice) => Utils.#normalizeChoiceInput(choice.name) === normalizedInput || String(choice.value) === String(input)
144
+ (choice) => Utils.#toLower(choice.name) === normalizedInput || String(choice.value) === String(input)
153
145
  );
154
146
  if (selected) return { break: false, value: selected.value };
155
147
  throw new Errors.InvalidParamChoice(ctx, param, param.choices);
@@ -599,20 +591,39 @@ class Utils {
599
591
  return { command, group: null };
600
592
  }
601
593
 
602
- static #resolveInteractionModule(bot, interaction) {
603
- if (interaction.isAutocomplete()) return bot.loader.interactions.autocomplete.get(interaction.commandName) || null;
604
- if (interaction.isButton()) return bot.loader.interactions.button.get(interaction.customId) || null;
605
- if (interaction.isModalSubmit()) return bot.loader.interactions.modalSubmit.get(interaction.customId) || null;
606
- if (interaction.isMessageContextMenuCommand()) return bot.loader.interactions.messageContextMenu.get(interaction.commandName) || null;
607
- if (interaction.isUserContextMenuCommand()) return bot.loader.interactions.userContextMenu.get(interaction.commandName) || null;
608
- if (interaction.isChannelSelectMenu()) return bot.loader.interactions.channelSelectMenu.get(interaction.customId) || null;
609
- if (interaction.isMentionableSelectMenu()) return bot.loader.interactions.mentionableSelectMenu.get(interaction.customId) || null;
610
- if (interaction.isRoleSelectMenu()) return bot.loader.interactions.roleSelectMenu.get(interaction.customId) || null;
611
- if (interaction.isStringSelectMenu()) return bot.loader.interactions.stringSelectMenu.get(interaction.customId) || null;
612
- if (interaction.isUserSelectMenu()) return bot.loader.interactions.userSelectMenu.get(interaction.customId) || null;
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
+ }
613
613
  return null;
614
614
  }
615
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
+
616
627
  static async #executeInteractionModule(bot, interaction, moduleData) {
617
628
  if (!moduleData?.code) return;
618
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
  }