@minesa-org/mini-interaction 0.0.13 → 0.0.14
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.
|
@@ -8,6 +8,7 @@ import { DISCORD_BASE_URL } from "../utils/constants.js";
|
|
|
8
8
|
import { createCommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
9
9
|
import { createMessageComponentInteraction, } from "../utils/MessageComponentInteraction.js";
|
|
10
10
|
import { createModalSubmitInteraction, } from "../utils/ModalSubmitInteraction.js";
|
|
11
|
+
import { createUserContextMenuInteraction, createMessageContextMenuInteraction, } from "../utils/ContextMenuInteraction.js";
|
|
11
12
|
/** File extensions that are treated as loadable modules when auto-loading. */
|
|
12
13
|
const SUPPORTED_MODULE_EXTENSIONS = new Set([
|
|
13
14
|
".js",
|
|
@@ -842,8 +843,22 @@ export class MiniInteraction {
|
|
|
842
843
|
resolvedResponse =
|
|
843
844
|
response ?? interactionWithHelpers.getResponse();
|
|
844
845
|
}
|
|
846
|
+
else if (commandInteraction.data.type === ApplicationCommandType.User) {
|
|
847
|
+
// User context menu command
|
|
848
|
+
const interactionWithHelpers = createUserContextMenuInteraction(commandInteraction);
|
|
849
|
+
response = await command.handler(interactionWithHelpers);
|
|
850
|
+
resolvedResponse =
|
|
851
|
+
response ?? interactionWithHelpers.getResponse();
|
|
852
|
+
}
|
|
853
|
+
else if (commandInteraction.data.type === ApplicationCommandType.Message) {
|
|
854
|
+
// Message context menu command
|
|
855
|
+
const interactionWithHelpers = createMessageContextMenuInteraction(commandInteraction);
|
|
856
|
+
response = await command.handler(interactionWithHelpers);
|
|
857
|
+
resolvedResponse =
|
|
858
|
+
response ?? interactionWithHelpers.getResponse();
|
|
859
|
+
}
|
|
845
860
|
else {
|
|
846
|
-
//
|
|
861
|
+
// Unknown command type
|
|
847
862
|
response = await command.handler(commandInteraction);
|
|
848
863
|
resolvedResponse = response ?? null;
|
|
849
864
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { UserCommandBuilder, MessageCommandBuilder, } from "./commands/ContextMe
|
|
|
6
6
|
export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBuilder, NumberOptionBuilder, RoleOptionBuilder, StringOptionBuilder, SubcommandBuilder, SubcommandGroupBuilder, UserOptionBuilder, } from "./commands/CommandBuilder.js";
|
|
7
7
|
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
8
8
|
export type { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
9
|
+
export type { UserContextMenuInteraction, MessageContextMenuInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
9
10
|
export type { MiniInteractionFetchHandler, MiniInteractionNodeHandler, MiniInteractionHandlerResult, MiniInteractionRequest, MiniInteractionOptions, } from "./clients/MiniInteraction.js";
|
|
10
11
|
export type { MiniInteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, CommandHandler, } from "./types/Commands.js";
|
|
11
12
|
export type { MiniInteractionComponent, MiniInteractionButtonHandler, MiniInteractionStringSelectHandler, MiniInteractionRoleSelectHandler, MiniInteractionUserSelectHandler, MiniInteractionChannelSelectHandler, MiniInteractionMentionableSelectHandler, MiniInteractionComponentHandler, MiniInteractionModal, MiniInteractionModalHandler, MiniInteractionHandler, } from "./clients/MiniInteraction.js";
|
package/dist/types/Commands.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody
|
|
1
|
+
import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody } from "discord-api-types/v10";
|
|
2
2
|
import type { CommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
3
|
+
import type { UserContextMenuInteraction, MessageContextMenuInteraction } from "../utils/ContextMenuInteraction.js";
|
|
3
4
|
import type { MiniInteractionComponent, MiniInteractionModal } from "../clients/MiniInteraction.js";
|
|
4
5
|
/** Handler signature for slash command executions within MiniInteraction. */
|
|
5
6
|
export type SlashCommandHandler = (interaction: CommandInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
6
7
|
/** Handler signature for user context menu command executions within MiniInteraction. */
|
|
7
|
-
export type UserCommandHandler = (interaction:
|
|
8
|
+
export type UserCommandHandler = (interaction: UserContextMenuInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
8
9
|
/** Handler signature for message context menu command executions within MiniInteraction. */
|
|
9
|
-
export type MessageCommandHandler = (interaction:
|
|
10
|
+
export type MessageCommandHandler = (interaction: MessageContextMenuInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
10
11
|
/** Union of all command handler types. */
|
|
11
12
|
export type CommandHandler = SlashCommandHandler | UserCommandHandler | MessageCommandHandler;
|
|
12
13
|
/** Structure representing a slash command definition and its runtime handler. */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, type APIInteractionResponseDeferredChannelMessageWithSource, type APIMessageApplicationCommandInteraction, type APIModalInteractionResponse, type APIModalInteractionResponseCallbackData, type APIUserApplicationCommandInteraction } from "discord-api-types/v10";
|
|
2
|
+
import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageHelpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base helper methods for context menu interactions.
|
|
5
|
+
*/
|
|
6
|
+
type ContextMenuInteractionHelpers = {
|
|
7
|
+
getResponse: () => APIInteractionResponse | null;
|
|
8
|
+
reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource;
|
|
9
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
10
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
11
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
12
|
+
}) => APIModalInteractionResponse;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* User context menu interaction with helper methods.
|
|
16
|
+
*/
|
|
17
|
+
export type UserContextMenuInteraction = APIUserApplicationCommandInteraction & ContextMenuInteractionHelpers;
|
|
18
|
+
/**
|
|
19
|
+
* Message context menu interaction with helper methods.
|
|
20
|
+
*/
|
|
21
|
+
export type MessageContextMenuInteraction = APIMessageApplicationCommandInteraction & ContextMenuInteractionHelpers;
|
|
22
|
+
/**
|
|
23
|
+
* Wraps a raw user context menu interaction with helper methods.
|
|
24
|
+
*
|
|
25
|
+
* @param interaction - The raw user context menu interaction payload from Discord.
|
|
26
|
+
* @returns A helper-augmented interaction object.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createUserContextMenuInteraction(interaction: APIUserApplicationCommandInteraction): UserContextMenuInteraction;
|
|
29
|
+
/**
|
|
30
|
+
* Wraps a raw message context menu interaction with helper methods.
|
|
31
|
+
*
|
|
32
|
+
* @param interaction - The raw message context menu interaction payload from Discord.
|
|
33
|
+
* @returns A helper-augmented interaction object.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createMessageContextMenuInteraction(interaction: APIMessageApplicationCommandInteraction): MessageContextMenuInteraction;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { InteractionResponseType, } from "discord-api-types/v10";
|
|
2
|
+
import { normaliseInteractionMessageData, normaliseMessageFlags, } from "./interactionMessageHelpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a raw user context menu interaction with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @param interaction - The raw user context menu interaction payload from Discord.
|
|
7
|
+
* @returns A helper-augmented interaction object.
|
|
8
|
+
*/
|
|
9
|
+
export function createUserContextMenuInteraction(interaction) {
|
|
10
|
+
let capturedResponse = null;
|
|
11
|
+
const reply = (data) => {
|
|
12
|
+
const normalised = normaliseInteractionMessageData(data);
|
|
13
|
+
if (!normalised) {
|
|
14
|
+
throw new Error("[MiniInteraction] Channel message responses require data to be provided.");
|
|
15
|
+
}
|
|
16
|
+
const response = {
|
|
17
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
18
|
+
data: normalised,
|
|
19
|
+
};
|
|
20
|
+
capturedResponse = response;
|
|
21
|
+
return response;
|
|
22
|
+
};
|
|
23
|
+
const deferReply = (options = {}) => {
|
|
24
|
+
const flags = normaliseMessageFlags(options.flags);
|
|
25
|
+
const response = {
|
|
26
|
+
type: InteractionResponseType.DeferredChannelMessageWithSource,
|
|
27
|
+
data: flags ? { flags } : undefined,
|
|
28
|
+
};
|
|
29
|
+
capturedResponse = response;
|
|
30
|
+
return response;
|
|
31
|
+
};
|
|
32
|
+
const showModal = (data) => {
|
|
33
|
+
const modalData = typeof data === "object" && "toJSON" in data ? data.toJSON() : data;
|
|
34
|
+
const response = {
|
|
35
|
+
type: InteractionResponseType.Modal,
|
|
36
|
+
data: modalData,
|
|
37
|
+
};
|
|
38
|
+
capturedResponse = response;
|
|
39
|
+
return response;
|
|
40
|
+
};
|
|
41
|
+
const getResponse = () => capturedResponse;
|
|
42
|
+
return Object.assign(interaction, {
|
|
43
|
+
reply,
|
|
44
|
+
deferReply,
|
|
45
|
+
showModal,
|
|
46
|
+
getResponse,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Wraps a raw message context menu interaction with helper methods.
|
|
51
|
+
*
|
|
52
|
+
* @param interaction - The raw message context menu interaction payload from Discord.
|
|
53
|
+
* @returns A helper-augmented interaction object.
|
|
54
|
+
*/
|
|
55
|
+
export function createMessageContextMenuInteraction(interaction) {
|
|
56
|
+
let capturedResponse = null;
|
|
57
|
+
const reply = (data) => {
|
|
58
|
+
const normalised = normaliseInteractionMessageData(data);
|
|
59
|
+
if (!normalised) {
|
|
60
|
+
throw new Error("[MiniInteraction] Channel message responses require data to be provided.");
|
|
61
|
+
}
|
|
62
|
+
const response = {
|
|
63
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
64
|
+
data: normalised,
|
|
65
|
+
};
|
|
66
|
+
capturedResponse = response;
|
|
67
|
+
return response;
|
|
68
|
+
};
|
|
69
|
+
const deferReply = (options = {}) => {
|
|
70
|
+
const flags = normaliseMessageFlags(options.flags);
|
|
71
|
+
const response = {
|
|
72
|
+
type: InteractionResponseType.DeferredChannelMessageWithSource,
|
|
73
|
+
data: flags ? { flags } : undefined,
|
|
74
|
+
};
|
|
75
|
+
capturedResponse = response;
|
|
76
|
+
return response;
|
|
77
|
+
};
|
|
78
|
+
const showModal = (data) => {
|
|
79
|
+
const modalData = typeof data === "object" && "toJSON" in data ? data.toJSON() : data;
|
|
80
|
+
const response = {
|
|
81
|
+
type: InteractionResponseType.Modal,
|
|
82
|
+
data: modalData,
|
|
83
|
+
};
|
|
84
|
+
capturedResponse = response;
|
|
85
|
+
return response;
|
|
86
|
+
};
|
|
87
|
+
const getResponse = () => capturedResponse;
|
|
88
|
+
return Object.assign(interaction, {
|
|
89
|
+
reply,
|
|
90
|
+
deferReply,
|
|
91
|
+
showModal,
|
|
92
|
+
getResponse,
|
|
93
|
+
});
|
|
94
|
+
}
|
package/package.json
CHANGED