@minesa-org/mini-interaction 0.3.8 → 0.3.10
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.
|
@@ -12,6 +12,7 @@ export type InteractionClientOptions = {
|
|
|
12
12
|
commandsDirectory?: string | false;
|
|
13
13
|
componentsDirectory?: string | false;
|
|
14
14
|
utilsDirectory?: string | false;
|
|
15
|
+
debug?: boolean;
|
|
15
16
|
fetchImplementation?: typeof fetch;
|
|
16
17
|
verifyKeyImplementation?: VerifyKeyFunction;
|
|
17
18
|
timeoutConfig?: InteractionTimeoutConfig;
|
|
@@ -178,6 +179,7 @@ export declare class MiniInteraction {
|
|
|
178
179
|
private readonly commandsDirectory;
|
|
179
180
|
private readonly componentsDirectory;
|
|
180
181
|
readonly utilsDirectory: string | null;
|
|
182
|
+
private readonly debug;
|
|
181
183
|
private readonly timeoutConfig;
|
|
182
184
|
private readonly commands;
|
|
183
185
|
private readonly componentHandlers;
|
|
@@ -196,6 +198,7 @@ export declare class MiniInteraction {
|
|
|
196
198
|
* Creates a new MiniInteraction client with optional command auto-loading and custom runtime hooks.
|
|
197
199
|
*/
|
|
198
200
|
constructor(options?: InteractionClientOptions);
|
|
201
|
+
private log;
|
|
199
202
|
private trackInteractionState;
|
|
200
203
|
/**
|
|
201
204
|
* Checks if an interaction can still respond (not expired and not already responded).
|
|
@@ -31,6 +31,7 @@ export class MiniInteraction {
|
|
|
31
31
|
commandsDirectory;
|
|
32
32
|
componentsDirectory;
|
|
33
33
|
utilsDirectory;
|
|
34
|
+
debug;
|
|
34
35
|
timeoutConfig;
|
|
35
36
|
commands = new Map();
|
|
36
37
|
componentHandlers = new Map();
|
|
@@ -54,7 +55,8 @@ export class MiniInteraction {
|
|
|
54
55
|
// @ts-ignore - Optional dependency, may not have types available during build
|
|
55
56
|
import("dotenv/config").catch(() => { });
|
|
56
57
|
}
|
|
57
|
-
const { applicationId, publicKey, commandsDirectory, componentsDirectory, utilsDirectory, fetchImplementation, verifyKeyImplementation, timeoutConfig, } = options;
|
|
58
|
+
const { applicationId, publicKey, commandsDirectory, componentsDirectory, utilsDirectory, debug, fetchImplementation, verifyKeyImplementation, timeoutConfig, } = options;
|
|
59
|
+
this.debug = debug ?? (typeof process !== "undefined" ? process.env.DEBUG === "true" || process.env.MINI_DEBUG === "true" : false);
|
|
58
60
|
const resolvedAppId = applicationId ?? (typeof process !== "undefined" ? process.env.DISCORD_APPLICATION_ID : undefined);
|
|
59
61
|
const resolvedPublicKey = publicKey ?? (typeof process !== "undefined" ? (process.env.DISCORD_PUBLIC_KEY ?? process.env.DISCORD_APP_PUBLIC_KEY) : undefined);
|
|
60
62
|
const fetchImpl = fetchImplementation ?? globalThis.fetch;
|
|
@@ -85,6 +87,11 @@ export class MiniInteraction {
|
|
|
85
87
|
...timeoutConfig,
|
|
86
88
|
};
|
|
87
89
|
}
|
|
90
|
+
log(message, ...args) {
|
|
91
|
+
if (this.debug) {
|
|
92
|
+
console.log(`[MiniInteraction] ${message}`, ...args);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
88
95
|
trackInteractionState(interactionId, token, state) {
|
|
89
96
|
const now = Date.now();
|
|
90
97
|
this.interactionStates.set(interactionId, {
|
|
@@ -856,6 +863,9 @@ export class MiniInteraction {
|
|
|
856
863
|
* Recursively collects all command module file paths from the target directory.
|
|
857
864
|
*/
|
|
858
865
|
async collectModuleFiles(directory) {
|
|
866
|
+
if (this.debug) {
|
|
867
|
+
this.log(`Collecting module files from: ${directory}`);
|
|
868
|
+
}
|
|
859
869
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
860
870
|
const files = [];
|
|
861
871
|
for (const entry of entries) {
|
|
@@ -891,6 +901,7 @@ export class MiniInteraction {
|
|
|
891
901
|
async importCommandModule(absolutePath) {
|
|
892
902
|
try {
|
|
893
903
|
const moduleUrl = pathToFileURL(absolutePath).href;
|
|
904
|
+
this.log(`Dynamically importing command: ${moduleUrl}`);
|
|
894
905
|
const imported = await import(moduleUrl);
|
|
895
906
|
// Try to find a command object from various export patterns
|
|
896
907
|
let candidate = imported.default ??
|
|
@@ -954,6 +965,7 @@ export class MiniInteraction {
|
|
|
954
965
|
async importComponentModule(absolutePath) {
|
|
955
966
|
try {
|
|
956
967
|
const moduleUrl = pathToFileURL(absolutePath).href;
|
|
968
|
+
this.log(`Dynamically importing component: ${moduleUrl}`);
|
|
957
969
|
const imported = await import(moduleUrl);
|
|
958
970
|
// Collect all potential component candidates
|
|
959
971
|
const candidates = [];
|
|
@@ -1139,10 +1151,17 @@ export class MiniInteraction {
|
|
|
1139
1151
|
pushCandidate(path.resolve(root, defaultFolder));
|
|
1140
1152
|
}
|
|
1141
1153
|
for (const candidate of candidates) {
|
|
1142
|
-
|
|
1154
|
+
const exists = existsSync(candidate);
|
|
1155
|
+
if (this.debug) {
|
|
1156
|
+
this.log(`Checking directory: ${candidate} (exists: ${exists})`);
|
|
1157
|
+
}
|
|
1158
|
+
if (exists) {
|
|
1143
1159
|
return candidate;
|
|
1144
1160
|
}
|
|
1145
1161
|
}
|
|
1162
|
+
if (this.debug) {
|
|
1163
|
+
this.log(`No existing directory found for ${defaultFolder}, using default candidate: ${candidates[0]}`);
|
|
1164
|
+
}
|
|
1146
1165
|
return candidates[0];
|
|
1147
1166
|
}
|
|
1148
1167
|
/**
|
|
@@ -63,24 +63,29 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
63
63
|
};
|
|
64
64
|
const getResponse = () => capturedResponse;
|
|
65
65
|
const getTextFieldValue = (customId) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const result = findValue(
|
|
66
|
+
const findValue = (components) => {
|
|
67
|
+
for (const component of components) {
|
|
68
|
+
if (component?.custom_id === customId &&
|
|
69
|
+
typeof component.value === "string") {
|
|
70
|
+
return component.value;
|
|
71
|
+
}
|
|
72
|
+
// Nested Label wrapper: single child in .component
|
|
73
|
+
if (component?.component) {
|
|
74
|
+
const found = findValue([component.component]);
|
|
75
|
+
if (found)
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
for (const top of interaction.data.components) {
|
|
82
|
+
if ("components" in top && Array.isArray(top.components)) {
|
|
83
|
+
const result = findValue(top.components);
|
|
84
|
+
if (result)
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
if ("component" in top && top.component) {
|
|
88
|
+
const result = findValue([top.component]);
|
|
84
89
|
if (result)
|
|
85
90
|
return result;
|
|
86
91
|
}
|
|
@@ -89,28 +94,36 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
89
94
|
};
|
|
90
95
|
/**
|
|
91
96
|
* Helper method to get the value(s) of a select menu component by its custom ID.
|
|
92
|
-
* Handles the nested structure of modal components (Action Rows -> Components
|
|
93
|
-
*
|
|
97
|
+
* Handles the nested structure of modal components (Action Rows -> Components,
|
|
98
|
+
* and Label -> single component). Select menus in modals are typically inside
|
|
99
|
+
* Label components, not Action Rows.
|
|
94
100
|
*/
|
|
95
101
|
const getSelectMenuValues = (customId) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
const findValues = (components) => {
|
|
103
|
+
for (const component of components) {
|
|
104
|
+
if (component?.custom_id === customId &&
|
|
105
|
+
Array.isArray(component.values)) {
|
|
106
|
+
return component.values;
|
|
107
|
+
}
|
|
108
|
+
// Nested Label wrapper: single child in .component
|
|
109
|
+
if (component?.component) {
|
|
110
|
+
const found = findValues([component.component]);
|
|
111
|
+
if (found)
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
|
117
|
+
for (const top of interaction.data.components) {
|
|
118
|
+
// Action Row: multiple components in .components
|
|
119
|
+
if ("components" in top && Array.isArray(top.components)) {
|
|
120
|
+
const result = findValues(top.components);
|
|
121
|
+
if (result)
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
// Label: select menu (and other modal components) wrapped in .component
|
|
125
|
+
if ("component" in top && top.component) {
|
|
126
|
+
const result = findValues([top.component]);
|
|
114
127
|
if (result)
|
|
115
128
|
return result;
|
|
116
129
|
}
|
package/package.json
CHANGED