@minesa-org/mini-interaction 0.0.7 → 0.0.9
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.
|
@@ -80,9 +80,8 @@ export class TextInputBuilder {
|
|
|
80
80
|
if (!this.data.customId) {
|
|
81
81
|
throw new Error("[TextInputBuilder] custom_id is required.");
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
83
|
+
// Note: label is optional when used inside a LabelComponent
|
|
84
|
+
// but required when used standalone in an ActionRow
|
|
86
85
|
return {
|
|
87
86
|
type: ComponentType.TextInput,
|
|
88
87
|
custom_id: this.data.customId,
|
|
@@ -37,13 +37,21 @@ export type MiniInteractionHandlerResult = {
|
|
|
37
37
|
};
|
|
38
38
|
/** Handler signature invoked for Discord message component interactions. */
|
|
39
39
|
export type MiniInteractionComponentHandler = (interaction: MessageComponentInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
40
|
-
/**
|
|
40
|
+
/** Handler signature invoked for Discord modal submit interactions. */
|
|
41
|
+
export type MiniInteractionModalHandler = (interaction: ModalSubmitInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
42
|
+
/** Unified handler signature that accepts both component and modal interactions. */
|
|
43
|
+
export type MiniInteractionHandler = MiniInteractionComponentHandler | MiniInteractionModalHandler;
|
|
44
|
+
/**
|
|
45
|
+
* Structure describing a component or modal handler mapped to a custom id.
|
|
46
|
+
* When auto-loading from the components directory:
|
|
47
|
+
* - Files in `components/modals/` are treated as modal handlers
|
|
48
|
+
* - Other files are treated as component handlers
|
|
49
|
+
* You can use this type for both - the system will figure out which one it is.
|
|
50
|
+
*/
|
|
41
51
|
export type MiniInteractionComponent = {
|
|
42
52
|
customId: string;
|
|
43
|
-
handler:
|
|
53
|
+
handler: MiniInteractionHandler;
|
|
44
54
|
};
|
|
45
|
-
/** Handler signature invoked for Discord modal submit interactions. */
|
|
46
|
-
export type MiniInteractionModalHandler = (interaction: ModalSubmitInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
47
55
|
/** Structure describing a modal handler mapped to a custom id. */
|
|
48
56
|
export type MiniInteractionModal = {
|
|
49
57
|
customId: string;
|
|
@@ -185,6 +193,7 @@ export declare class MiniInteraction {
|
|
|
185
193
|
private importCommandModule;
|
|
186
194
|
/**
|
|
187
195
|
* Dynamically imports and validates a component module from disk.
|
|
196
|
+
* Also handles modal components if they're in a "modals" subdirectory.
|
|
188
197
|
*/
|
|
189
198
|
private importComponentModule;
|
|
190
199
|
/**
|
|
@@ -545,6 +545,7 @@ export class MiniInteraction {
|
|
|
545
545
|
}
|
|
546
546
|
/**
|
|
547
547
|
* Dynamically imports and validates a component module from disk.
|
|
548
|
+
* Also handles modal components if they're in a "modals" subdirectory.
|
|
548
549
|
*/
|
|
549
550
|
async importComponentModule(absolutePath) {
|
|
550
551
|
try {
|
|
@@ -554,11 +555,16 @@ export class MiniInteraction {
|
|
|
554
555
|
imported.component ??
|
|
555
556
|
imported.components ??
|
|
556
557
|
imported.componentDefinition ??
|
|
558
|
+
imported.modal ??
|
|
559
|
+
imported.modals ??
|
|
557
560
|
imported;
|
|
558
561
|
const candidates = Array.isArray(candidate)
|
|
559
562
|
? candidate
|
|
560
563
|
: [candidate];
|
|
561
564
|
const components = [];
|
|
565
|
+
// Check if this file is in a "modals" subdirectory
|
|
566
|
+
const isModalFile = absolutePath.includes(path.sep + "modals" + path.sep) ||
|
|
567
|
+
absolutePath.includes("/modals/");
|
|
562
568
|
for (const item of candidates) {
|
|
563
569
|
if (!item || typeof item !== "object") {
|
|
564
570
|
continue;
|
|
@@ -572,9 +578,18 @@ export class MiniInteraction {
|
|
|
572
578
|
console.warn(`[MiniInteraction] Component module "${absolutePath}" is missing a "handler" function. Skipping.`);
|
|
573
579
|
continue;
|
|
574
580
|
}
|
|
575
|
-
|
|
581
|
+
// If it's in a modals directory, register it as a modal
|
|
582
|
+
if (isModalFile) {
|
|
583
|
+
this.useModal({
|
|
584
|
+
customId,
|
|
585
|
+
handler: handler,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
components.push({ customId, handler });
|
|
590
|
+
}
|
|
576
591
|
}
|
|
577
|
-
if (components.length === 0) {
|
|
592
|
+
if (components.length === 0 && !isModalFile) {
|
|
578
593
|
console.warn(`[MiniInteraction] Component module "${absolutePath}" did not export any valid components. Skipping.`);
|
|
579
594
|
}
|
|
580
595
|
return components;
|
|
@@ -755,6 +770,7 @@ export class MiniInteraction {
|
|
|
755
770
|
},
|
|
756
771
|
};
|
|
757
772
|
}
|
|
773
|
+
await this.ensureComponentsLoaded();
|
|
758
774
|
const handler = this.modalHandlers.get(customId);
|
|
759
775
|
if (!handler) {
|
|
760
776
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { CommandInteractionOptionResolver, createCommandInteraction, } from "./u
|
|
|
7
7
|
export type { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
8
8
|
export type { MiniInteractionFetchHandler, MiniInteractionNodeHandler, MiniInteractionHandlerResult, MiniInteractionRequest, MiniInteractionOptions, } from "./clients/MiniInteraction.js";
|
|
9
9
|
export type { MiniInteractionCommand, SlashCommandHandler, } from "./types/Commands.js";
|
|
10
|
-
export type { MiniInteractionComponent, MiniInteractionComponentHandler, MiniInteractionModal, MiniInteractionModalHandler, } from "./clients/MiniInteraction.js";
|
|
10
|
+
export type { MiniInteractionComponent, MiniInteractionComponentHandler, MiniInteractionModal, MiniInteractionModalHandler, MiniInteractionHandler, } from "./clients/MiniInteraction.js";
|
|
11
11
|
export type { MessageComponentInteraction } from "./utils/MessageComponentInteraction.js";
|
|
12
12
|
export type { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
13
13
|
export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
|
package/package.json
CHANGED