@hyperneutrino/djs-lite 1.6.0 → 1.6.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.
- package/index.ts +28 -23
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -35,11 +35,36 @@ const identity = <T>(value: T): T => value;
|
|
|
35
35
|
|
|
36
36
|
type Wrapper<T extends Function> = (fn: T) => T;
|
|
37
37
|
|
|
38
|
-
type
|
|
38
|
+
type Handleable = CommandInteraction | AutocompleteInteraction | MessageComponentInteraction | ModalSubmitInteraction;
|
|
39
|
+
|
|
40
|
+
type Handler<T extends Handleable> = (
|
|
39
41
|
interaction: T,
|
|
40
42
|
...args: T extends MessageComponentInteraction | ModalSubmitInteraction ? (string | undefined)[] : []
|
|
41
43
|
) => Awaitable<unknown>;
|
|
42
44
|
|
|
45
|
+
type WrapperConfig<R extends Record<string, Handleable>> = {
|
|
46
|
+
[K in keyof R]?: Wrapper<Handler<R[K]>>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface CommandWrappers extends WrapperConfig<{
|
|
50
|
+
slashCommands: ChatInputCommandInteraction;
|
|
51
|
+
userCommands: UserContextMenuCommandInteraction;
|
|
52
|
+
messageCommands: MessageContextMenuCommandInteraction;
|
|
53
|
+
autocompletes: AutocompleteInteraction;
|
|
54
|
+
}> {}
|
|
55
|
+
|
|
56
|
+
export interface InteractionWrappers extends WrapperConfig<{
|
|
57
|
+
modal: ModalSubmitInteraction;
|
|
58
|
+
button: ButtonInteraction;
|
|
59
|
+
stringSelectMenu: StringSelectMenuInteraction;
|
|
60
|
+
userSelectMenu: UserSelectMenuInteraction;
|
|
61
|
+
roleSelectMenu: RoleSelectMenuInteraction;
|
|
62
|
+
mentionableSelectMenu: MentionableSelectMenuInteraction;
|
|
63
|
+
channelSelectMenu: ChannelSelectMenuInteraction;
|
|
64
|
+
}> {}
|
|
65
|
+
|
|
66
|
+
export interface Wrappers extends CommandWrappers, InteractionWrappers {}
|
|
67
|
+
|
|
43
68
|
abstract class Command<T extends BaseApplicationCommandData, U extends CommandInteraction, Z extends boolean = false> {
|
|
44
69
|
data: T;
|
|
45
70
|
handler: Handler<U>;
|
|
@@ -190,19 +215,7 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
|
|
|
190
215
|
};
|
|
191
216
|
}
|
|
192
217
|
|
|
193
|
-
export async function loadCommands(
|
|
194
|
-
client: Client<true>,
|
|
195
|
-
directory: string,
|
|
196
|
-
config?: {
|
|
197
|
-
guildId?: string;
|
|
198
|
-
wrappers?: {
|
|
199
|
-
slashCommands?: Wrapper<Handler<ChatInputCommandInteraction>>;
|
|
200
|
-
userCommands?: Wrapper<Handler<UserContextMenuCommandInteraction>>;
|
|
201
|
-
messageCommands?: Wrapper<Handler<MessageContextMenuCommandInteraction>>;
|
|
202
|
-
autocompletes?: Wrapper<Handler<AutocompleteInteraction>>;
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
) {
|
|
218
|
+
export async function loadCommands(client: Client<true>, directory: string, config?: { guildId?: string; wrappers?: CommandWrappers }) {
|
|
206
219
|
const commandData: (ChatInputApplicationCommandData | UserApplicationCommandData | MessageApplicationCommandData)[] = [];
|
|
207
220
|
|
|
208
221
|
const slashCommandHandlers = new Map<string, Handler<ChatInputCommandInteraction>>();
|
|
@@ -271,15 +284,7 @@ export async function loadInteractions(
|
|
|
271
284
|
directory: string,
|
|
272
285
|
config?: {
|
|
273
286
|
argumentSeparator?: string;
|
|
274
|
-
wrappers?:
|
|
275
|
-
modal?: Wrapper<Handler<ModalSubmitInteraction>>;
|
|
276
|
-
button?: Wrapper<Handler<ButtonInteraction>>;
|
|
277
|
-
stringSelectMenu?: Wrapper<Handler<StringSelectMenuInteraction>>;
|
|
278
|
-
userSelectMenu?: Wrapper<Handler<UserSelectMenuInteraction>>;
|
|
279
|
-
roleSelectMenu?: Wrapper<Handler<RoleSelectMenuInteraction>>;
|
|
280
|
-
mentionableSelectMenu?: Wrapper<Handler<MentionableSelectMenuInteraction>>;
|
|
281
|
-
channelSelectMenu?: Wrapper<Handler<ChannelSelectMenuInteraction>>;
|
|
282
|
-
};
|
|
287
|
+
wrappers?: InteractionWrappers;
|
|
283
288
|
},
|
|
284
289
|
) {
|
|
285
290
|
const modalHandlers = new Map<string, Handler<ModalSubmitInteraction>>();
|