@minesa-org/mini-interaction 0.0.10 → 0.0.11
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord-api-types/v10";
|
|
2
|
+
import { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody } from "discord-api-types/v10";
|
|
3
3
|
import type { MiniInteractionCommand } from "../types/Commands.js";
|
|
4
4
|
import { RoleConnectionMetadataTypes } from "../types/RoleConnectionMetadataTypes.js";
|
|
5
5
|
import { type MessageComponentInteraction } from "../utils/MessageComponentInteraction.js";
|
|
@@ -138,14 +138,14 @@ export declare class MiniInteraction {
|
|
|
138
138
|
/**
|
|
139
139
|
* Lists the raw command data payloads for registration with Discord.
|
|
140
140
|
*/
|
|
141
|
-
listCommandData(): RESTPostAPIChatInputApplicationCommandsJSONBody[];
|
|
141
|
+
listCommandData(): (RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody)[];
|
|
142
142
|
/**
|
|
143
|
-
* Registers
|
|
143
|
+
* Registers commands with Discord's REST API.
|
|
144
144
|
*
|
|
145
145
|
* @param botToken - The bot token authorising the registration request.
|
|
146
146
|
* @param commands - Optional command list to register instead of auto-loaded commands.
|
|
147
147
|
*/
|
|
148
|
-
registerCommands(botToken: string, commands?: RESTPostAPIChatInputApplicationCommandsJSONBody[]): Promise<unknown>;
|
|
148
|
+
registerCommands(botToken: string, commands?: (RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody)[]): Promise<unknown>;
|
|
149
149
|
/**
|
|
150
150
|
* Registers role connection metadata with Discord's REST API.
|
|
151
151
|
*
|
|
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { readdir, stat } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
-
import { InteractionResponseType, InteractionType, } from "discord-api-types/v10";
|
|
5
|
+
import { ApplicationCommandType, InteractionResponseType, InteractionType, } from "discord-api-types/v10";
|
|
6
6
|
import { verifyKey } from "discord-interactions";
|
|
7
7
|
import { DISCORD_BASE_URL } from "../utils/constants.js";
|
|
8
8
|
import { createCommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
@@ -251,7 +251,7 @@ export class MiniInteraction {
|
|
|
251
251
|
return Array.from(this.commands.values(), (command) => command.data);
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
|
-
* Registers
|
|
254
|
+
* Registers commands with Discord's REST API.
|
|
255
255
|
*
|
|
256
256
|
* @param botToken - The bot token authorising the registration request.
|
|
257
257
|
* @param commands - Optional command list to register instead of auto-loaded commands.
|
|
@@ -831,10 +831,22 @@ export class MiniInteraction {
|
|
|
831
831
|
},
|
|
832
832
|
};
|
|
833
833
|
}
|
|
834
|
-
const interactionWithHelpers = createCommandInteraction(commandInteraction);
|
|
835
834
|
try {
|
|
836
|
-
|
|
837
|
-
|
|
835
|
+
let response;
|
|
836
|
+
let resolvedResponse = null;
|
|
837
|
+
// Check if it's a chat input (slash) command
|
|
838
|
+
if (commandInteraction.data.type ===
|
|
839
|
+
ApplicationCommandType.ChatInput) {
|
|
840
|
+
const interactionWithHelpers = createCommandInteraction(commandInteraction);
|
|
841
|
+
response = await command.handler(interactionWithHelpers);
|
|
842
|
+
resolvedResponse =
|
|
843
|
+
response ?? interactionWithHelpers.getResponse();
|
|
844
|
+
}
|
|
845
|
+
else {
|
|
846
|
+
// Context menu commands (User or Message) - pass raw interaction
|
|
847
|
+
response = await command.handler(commandInteraction);
|
|
848
|
+
resolvedResponse = response ?? null;
|
|
849
|
+
}
|
|
838
850
|
if (!resolvedResponse) {
|
|
839
851
|
return {
|
|
840
852
|
status: 500,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBu
|
|
|
7
7
|
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
8
8
|
export type { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
9
9
|
export type { MiniInteractionFetchHandler, MiniInteractionNodeHandler, MiniInteractionHandlerResult, MiniInteractionRequest, MiniInteractionOptions, } from "./clients/MiniInteraction.js";
|
|
10
|
-
export type { MiniInteractionCommand, SlashCommandHandler, } from "./types/Commands.js";
|
|
10
|
+
export type { MiniInteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, CommandHandler, } from "./types/Commands.js";
|
|
11
11
|
export type { MiniInteractionComponent, MiniInteractionComponentHandler, MiniInteractionModal, MiniInteractionModalHandler, MiniInteractionHandler, } from "./clients/MiniInteraction.js";
|
|
12
12
|
export type { MessageComponentInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
13
13
|
export type { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
package/dist/types/Commands.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord-api-types/v10";
|
|
1
|
+
import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, APIUserApplicationCommandInteraction, APIMessageApplicationCommandInteraction } from "discord-api-types/v10";
|
|
2
2
|
import type { CommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
3
3
|
import type { MiniInteractionComponent, MiniInteractionModal } from "../clients/MiniInteraction.js";
|
|
4
4
|
/** Handler signature for slash command executions within MiniInteraction. */
|
|
5
5
|
export type SlashCommandHandler = (interaction: CommandInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
6
|
+
/** Handler signature for user context menu command executions within MiniInteraction. */
|
|
7
|
+
export type UserCommandHandler = (interaction: APIUserApplicationCommandInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
8
|
+
/** Handler signature for message context menu command executions within MiniInteraction. */
|
|
9
|
+
export type MessageCommandHandler = (interaction: APIMessageApplicationCommandInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
10
|
+
/** Union of all command handler types. */
|
|
11
|
+
export type CommandHandler = SlashCommandHandler | UserCommandHandler | MessageCommandHandler;
|
|
6
12
|
/** Structure representing a slash command definition and its runtime handler. */
|
|
7
13
|
export type MiniInteractionCommand = {
|
|
8
|
-
data: RESTPostAPIChatInputApplicationCommandsJSONBody;
|
|
9
|
-
handler:
|
|
14
|
+
data: RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody;
|
|
15
|
+
handler: CommandHandler;
|
|
10
16
|
/**
|
|
11
17
|
* Optional array of component handlers related to this command.
|
|
12
18
|
* These will be automatically registered when the command is loaded.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minesa-org/mini-interaction",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"ts-node": "^10.9.2",
|
|
49
49
|
"typescript": "^5.9.3"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|