@minesa-org/mini-interaction 0.4.0 → 0.4.3
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/README.md +130 -20
- package/dist/builders/ActionRowBuilder.d.ts +4 -5
- package/dist/builders/CheckboxBuilder.d.ts +17 -0
- package/dist/builders/CheckboxBuilder.js +24 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +1 -0
- package/dist/index.d.ts +6 -11
- package/dist/index.js +3 -5
- package/dist/types/Commands.d.ts +14 -0
- package/dist/types/ComponentTypes.d.ts +17 -3
- package/dist/types/InteractionFlags.d.ts +0 -4
- package/dist/types/InteractionFlags.js +0 -4
- package/dist/types/checkbox.d.ts +23 -0
- package/dist/types/checkbox.js +5 -0
- package/dist/utils/MessageComponentInteraction.d.ts +38 -0
- package/dist/utils/MessageComponentInteraction.js +2 -0
- package/dist/utils/ModalSubmitInteraction.js +5 -2
- package/dist/utils/interactionMessageHelpers.d.ts +3 -2
- package/dist/utils/interactionMessageHelpers.js +2 -0
- package/package.json +1 -1
- package/dist/clients/MiniInteraction.d.ts +0 -441
- package/dist/clients/MiniInteraction.js +0 -1731
- package/dist/compat/LegacyMiniInteractionAdapter.d.ts +0 -19
- package/dist/compat/LegacyMiniInteractionAdapter.js +0 -23
package/README.md
CHANGED
|
@@ -1,34 +1,144 @@
|
|
|
1
|
-
# Mini Interaction
|
|
1
|
+
# 🌌 Mini Interaction
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Sleek, Modular, and Type-Safe Discord Interactions Framework.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Mini Interaction is a high-performance framework designed for building Discord HTTP/Webhook-based bots. It provides a modular architecture that separates concerns, making your bot easier to maintain, test, and scale.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- **🚀 Modular Router**: Easily map commands, components, and modals to handlers.
|
|
12
|
+
- **⚡ Core V10 Engine**: Native support for Discord API v10 payloads.
|
|
13
|
+
- **🛡️ Type Safety**: Full TypeScript support with rich autocompletion.
|
|
14
|
+
- **🧩 Fluent Builders**: Construct complex messages and components with a premium API.
|
|
15
|
+
- **🔐 Integrated OAuth**: Simple handlers for Discord OAuth2 flows.
|
|
16
|
+
- **🗃️ Mini Database**: Lightweight, document-based storage integration.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @minesa-org/mini-interaction
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 🛠️ Quick Start
|
|
29
|
+
|
|
30
|
+
Mini Interaction uses a modular approach with a dedicated Router and Context.
|
|
31
|
+
|
|
32
|
+
### 1. Define your Router
|
|
6
33
|
```ts
|
|
7
|
-
import {
|
|
34
|
+
import { InteractionRouter } from '@minesa-org/mini-interaction';
|
|
35
|
+
|
|
36
|
+
const router = new InteractionRouter();
|
|
37
|
+
|
|
38
|
+
// Register a slash command
|
|
39
|
+
router.onCommand('ping', async (interaction, ctx) => {
|
|
40
|
+
return ctx.reply({ content: '🏓 Pong!' });
|
|
41
|
+
});
|
|
8
42
|
|
|
9
|
-
|
|
10
|
-
|
|
43
|
+
// Register a component handler
|
|
44
|
+
router.onComponent('my_button', async (interaction, ctx) => {
|
|
45
|
+
return ctx.reply({ content: 'Button clicked!', ephemeral: true });
|
|
46
|
+
});
|
|
11
47
|
```
|
|
12
48
|
|
|
13
|
-
|
|
49
|
+
### 2. Handle Interactions
|
|
14
50
|
```ts
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
FileUploadBuilder,
|
|
20
|
-
ModalRoleSelectMenuBuilder,
|
|
51
|
+
import {
|
|
52
|
+
verifyAndParseInteraction,
|
|
53
|
+
InteractionContext,
|
|
54
|
+
DiscordRestClient
|
|
21
55
|
} from '@minesa-org/mini-interaction';
|
|
56
|
+
|
|
57
|
+
const rest = new DiscordRestClient({
|
|
58
|
+
applicationId: process.env.DISCORD_APP_ID,
|
|
59
|
+
token: process.env.DISCORD_TOKEN
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// In your web server (e.g., Next.js, Vercel, Express)
|
|
63
|
+
export async function POST(req) {
|
|
64
|
+
const body = await req.text();
|
|
65
|
+
const signature = req.headers.get('x-signature-ed25519');
|
|
66
|
+
const timestamp = req.headers.get('x-signature-timestamp');
|
|
67
|
+
|
|
68
|
+
// Verify and parse the interaction
|
|
69
|
+
const interaction = await verifyAndParseInteraction({
|
|
70
|
+
body,
|
|
71
|
+
signature,
|
|
72
|
+
timestamp,
|
|
73
|
+
publicKey: process.env.DISCORD_PUBLIC_KEY
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (interaction.type === 1) return Response.json({ type: 1 });
|
|
77
|
+
|
|
78
|
+
const ctx = new InteractionContext({ interaction, rest });
|
|
79
|
+
const response = await router.dispatch(interaction, ctx);
|
|
80
|
+
|
|
81
|
+
return Response.json(response ?? ctx.deferReply());
|
|
82
|
+
}
|
|
22
83
|
```
|
|
23
84
|
|
|
24
|
-
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🎨 Message Builders
|
|
88
|
+
|
|
89
|
+
Mini Interaction provides a rich set of builders to create beautiful Discord content.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { ModalBuilder, TextInputBuilder, TextInputStyle } from '@minesa-org/mini-interaction';
|
|
93
|
+
|
|
94
|
+
const modal = new ModalBuilder()
|
|
95
|
+
.setCustomId('feedback_form')
|
|
96
|
+
.setTitle('Send us Feedback')
|
|
97
|
+
.addComponents(
|
|
98
|
+
new TextInputBuilder()
|
|
99
|
+
.setCustomId('feedback_text')
|
|
100
|
+
.setLabel('Your Message')
|
|
101
|
+
.setStyle(TextInputStyle.Paragraph)
|
|
102
|
+
.setPlaceholder('Tell us what you think...')
|
|
103
|
+
);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 📡 Advanced Routing
|
|
109
|
+
|
|
110
|
+
You can organize your handlers into separate modules for better scalability.
|
|
111
|
+
|
|
25
112
|
```ts
|
|
26
|
-
|
|
113
|
+
// components/modals.ts
|
|
114
|
+
router.onModal('feedback_submit', async (interaction, ctx) => {
|
|
115
|
+
const feedback = interaction.getTextFieldValue('feedback_text');
|
|
116
|
+
// Process feedback...
|
|
117
|
+
return ctx.reply({ content: 'Thank you for your feedback!' });
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🛡️ Error Handling
|
|
124
|
+
|
|
125
|
+
Mini Interaction includes built-in validation to ensure your payloads follow Discord's requirements.
|
|
27
126
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
127
|
+
```ts
|
|
128
|
+
import { ValidationError } from '@minesa-org/mini-interaction';
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const builder = new TextInputBuilder().setCustomId(''); // Too short!
|
|
132
|
+
builder.toJSON();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof ValidationError) {
|
|
135
|
+
console.error(`Validation failed for ${error.component}: ${error.message}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
31
138
|
```
|
|
32
139
|
|
|
33
|
-
|
|
34
|
-
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📜 License
|
|
143
|
+
|
|
144
|
+
MIT © [Minesa](https://github.com/minesa-org)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { APIActionRowComponent } from "discord-api-types/v10";
|
|
2
1
|
import type { JSONEncodable } from "./shared.js";
|
|
3
|
-
import type { ActionRowComponent } from "../types/ComponentTypes.js";
|
|
2
|
+
import type { ActionRowComponent, MiniActionRow } from "../types/ComponentTypes.js";
|
|
4
3
|
/** Values accepted when composing component action rows. */
|
|
5
4
|
export type ActionRowComponentLike<T extends ActionRowComponent> = JSONEncodable<T> | T;
|
|
6
5
|
/** Builder for creating Action Row components. */
|
|
7
|
-
export declare class ActionRowBuilder<T extends ActionRowComponent> implements JSONEncodable<
|
|
6
|
+
export declare class ActionRowBuilder<T extends ActionRowComponent> implements JSONEncodable<MiniActionRow<T>> {
|
|
8
7
|
private components;
|
|
9
|
-
constructor(data?: Partial<
|
|
8
|
+
constructor(data?: Partial<MiniActionRow<T>>);
|
|
10
9
|
/**
|
|
11
10
|
* Adds components to this action row.
|
|
12
11
|
*
|
|
@@ -19,5 +18,5 @@ export declare class ActionRowBuilder<T extends ActionRowComponent> implements J
|
|
|
19
18
|
* @param components - The new components to set.
|
|
20
19
|
*/
|
|
21
20
|
setComponents(...components: (T | JSONEncodable<T>)[]): this;
|
|
22
|
-
toJSON():
|
|
21
|
+
toJSON(): MiniActionRow<T>;
|
|
23
22
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JSONEncodable } from './shared.js';
|
|
2
|
+
import { APICheckboxComponent, APICheckboxOption } from '../types/checkbox.js';
|
|
3
|
+
export type CheckboxBuilderData = {
|
|
4
|
+
customId?: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
options?: APICheckboxOption[];
|
|
8
|
+
};
|
|
9
|
+
export declare class CheckboxBuilder implements JSONEncodable<APICheckboxComponent> {
|
|
10
|
+
private readonly data;
|
|
11
|
+
constructor(data?: CheckboxBuilderData);
|
|
12
|
+
setCustomId(customId: string): this;
|
|
13
|
+
setRequired(required: boolean): this;
|
|
14
|
+
setDisabled(disabled: boolean): this;
|
|
15
|
+
addOptions(...options: APICheckboxOption[]): this;
|
|
16
|
+
toJSON(): APICheckboxComponent;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CHECKBOX_COMPONENT_TYPE } from '../types/checkbox.js';
|
|
2
|
+
import { assertDefined, assertStringLength, ValidationError } from '../types/validation.js';
|
|
3
|
+
export class CheckboxBuilder {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data = {}) { this.data = { ...data, options: data.options ? [...data.options] : [] }; }
|
|
6
|
+
setCustomId(customId) { this.data.customId = customId; return this; }
|
|
7
|
+
setRequired(required) { this.data.required = required; return this; }
|
|
8
|
+
setDisabled(disabled) { this.data.disabled = disabled; return this; }
|
|
9
|
+
addOptions(...options) { this.data.options = [...(this.data.options ?? []), ...options]; return this; }
|
|
10
|
+
toJSON() {
|
|
11
|
+
const customId = assertDefined('CheckboxBuilder', 'custom_id', this.data.customId);
|
|
12
|
+
assertStringLength('CheckboxBuilder', 'custom_id', customId, 1, 100);
|
|
13
|
+
const options = [...(this.data.options ?? [])];
|
|
14
|
+
if (options.length === 0 || options.length > 25)
|
|
15
|
+
throw new ValidationError('CheckboxBuilder', 'options', 'must contain 1-25 options');
|
|
16
|
+
for (const [index, option] of options.entries()) {
|
|
17
|
+
assertStringLength('CheckboxBuilder', `options[${index}].label`, option.label, 1, 100);
|
|
18
|
+
assertStringLength('CheckboxBuilder', `options[${index}].value`, option.value, 1, 100);
|
|
19
|
+
if (option.description)
|
|
20
|
+
assertStringLength('CheckboxBuilder', `options[${index}].description`, option.description, 1, 100);
|
|
21
|
+
}
|
|
22
|
+
return { type: CHECKBOX_COMPONENT_TYPE, custom_id: customId, disabled: this.data.disabled, required: this.data.required, options };
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -38,3 +38,5 @@ export type { ContainerBuilderData, SectionBuilderData, TextDisplayBuilderData,
|
|
|
38
38
|
export type { JSONEncodable } from "./shared.js";
|
|
39
39
|
export { RadioBuilder } from "./RadioBuilder.js";
|
|
40
40
|
export type { RadioBuilderData } from "./RadioBuilder.js";
|
|
41
|
+
export { CheckboxBuilder } from "./CheckboxBuilder.js";
|
|
42
|
+
export type { CheckboxBuilderData } from "./CheckboxBuilder.js";
|
package/dist/builders/index.js
CHANGED
|
@@ -18,3 +18,4 @@ export { AutomodRuleBuilder } from "./AutomodRuleBuilder.js";
|
|
|
18
18
|
export { EmbedBuilder } from "./EmbedBuilder.js";
|
|
19
19
|
export { ContainerBuilder, SectionBuilder, TextDisplayBuilder, SeparatorBuilder, GalleryBuilder, GalleryItemBuilder, ThumbnailBuilder, } from "./MiniContainerBuilder.js";
|
|
20
20
|
export { RadioBuilder } from "./RadioBuilder.js";
|
|
21
|
+
export { CheckboxBuilder } from "./CheckboxBuilder.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
/** Entry point re-exporting MiniInteraction helpers, builders, and shared types. */
|
|
2
|
-
export { MiniInteraction } from "./clients/MiniInteraction.js";
|
|
3
|
-
export type { RoleConnectionMetadataField } from "./clients/MiniInteraction.js";
|
|
4
1
|
export { CommandBuilder, CommandContext, IntegrationType, } from "./commands/CommandBuilder.js";
|
|
5
2
|
export { UserCommandBuilder, MessageCommandBuilder, AppCommandBuilder, } from "./commands/ContextMenuCommandBuilder.js";
|
|
6
3
|
export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBuilder, NumberOptionBuilder, RoleOptionBuilder, StringOptionBuilder, SubcommandBuilder, SubcommandGroupBuilder, UserOptionBuilder, } from "./commands/CommandBuilder.js";
|
|
7
4
|
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
8
5
|
export { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
9
6
|
export { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
10
|
-
export type {
|
|
11
|
-
export
|
|
12
|
-
export type { ComponentCommand, ButtonComponentHandler, StringSelectComponentHandler, RoleSelectComponentHandler, UserSelectComponentHandler, ChannelSelectComponentHandler, MentionableSelectComponentHandler, ComponentHandler, ModalCommand, ModalHandler, InteractionHandler, } from "./clients/MiniInteraction.js";
|
|
13
|
-
export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
7
|
+
export type { InteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, AppCommandHandler, CommandHandler, ComponentInteraction, InteractionComponent, InteractionModal, } from "./types/Commands.js";
|
|
8
|
+
export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
14
9
|
export { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
15
10
|
export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
|
|
16
11
|
export { ChannelType } from "./types/ChannelType.js";
|
|
17
|
-
export {
|
|
12
|
+
export { InteractionFlags, } from "./types/InteractionFlags.js";
|
|
18
13
|
export { ButtonStyle } from "./types/ButtonStyle.js";
|
|
19
14
|
export { SeparatorSpacingSize } from "./types/SeparatorSpacingSize.js";
|
|
20
15
|
export { TextInputStyle } from "discord-api-types/v10";
|
|
21
16
|
export { MiniPermFlags } from "./types/PermissionFlags.js";
|
|
22
|
-
export type { ActionRowComponent, MessageActionRowComponent, } from "./types/ComponentTypes.js";
|
|
17
|
+
export type { ActionRowComponent, MessageActionRowComponent, InteractionComponentData, } from "./types/ComponentTypes.js";
|
|
23
18
|
export * from "./builders/index.js";
|
|
24
19
|
export { MiniDataBuilder } from "./database/MiniDataBuilder.js";
|
|
25
20
|
export type { DataField } from "./database/MiniDataBuilder.js";
|
|
@@ -35,8 +30,8 @@ export { InteractionContext } from "./core/interactions/InteractionContext.js";
|
|
|
35
30
|
export type { InteractionContextOptions } from "./core/interactions/InteractionContext.js";
|
|
36
31
|
export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
|
|
37
32
|
export { InteractionRouter } from "./router/InteractionRouter.js";
|
|
38
|
-
export { LegacyMiniInteractionAdapter } from "./compat/LegacyMiniInteractionAdapter.js";
|
|
39
|
-
export type { LegacyAdapterOptions } from "./compat/LegacyMiniInteractionAdapter.js";
|
|
40
33
|
export type { APIRadioComponent, APIRadioOption } from "./types/radio.js";
|
|
41
34
|
export { RADIO_COMPONENT_TYPE } from "./types/radio.js";
|
|
35
|
+
export type { APICheckboxComponent, APICheckboxOption } from "./types/checkbox.js";
|
|
36
|
+
export { CHECKBOX_COMPONENT_TYPE } from "./types/checkbox.js";
|
|
42
37
|
export { ValidationError } from "./types/validation.js";
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
/** Entry point re-exporting MiniInteraction helpers, builders, and shared types. */
|
|
2
|
-
export { MiniInteraction } from "./clients/MiniInteraction.js";
|
|
3
1
|
export { CommandBuilder, CommandContext, IntegrationType, } from "./commands/CommandBuilder.js";
|
|
4
2
|
export { UserCommandBuilder, MessageCommandBuilder, AppCommandBuilder, } from "./commands/ContextMenuCommandBuilder.js";
|
|
5
3
|
export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
|
|
6
4
|
export { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
|
|
7
5
|
export { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction, } from "./utils/ContextMenuInteraction.js";
|
|
8
|
-
export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
6
|
+
export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction, ResolvedUserOption as ComponentResolvedUserOption, ResolvedMentionableOption as ComponentResolvedMentionableOption, } from "./utils/MessageComponentInteraction.js";
|
|
9
7
|
export { ModalSubmitInteraction } from "./utils/ModalSubmitInteraction.js";
|
|
10
8
|
export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
|
|
11
9
|
export { ChannelType } from "./types/ChannelType.js";
|
|
12
|
-
export {
|
|
10
|
+
export { InteractionFlags, } from "./types/InteractionFlags.js";
|
|
13
11
|
export { ButtonStyle } from "./types/ButtonStyle.js";
|
|
14
12
|
export { SeparatorSpacingSize } from "./types/SeparatorSpacingSize.js";
|
|
15
13
|
export { TextInputStyle } from "discord-api-types/v10";
|
|
@@ -25,6 +23,6 @@ export { DiscordRestClient } from "./core/http/DiscordRestClient.js";
|
|
|
25
23
|
export { InteractionContext } from "./core/interactions/InteractionContext.js";
|
|
26
24
|
export { verifyAndParseInteraction } from "./core/interactions/InteractionVerifier.js";
|
|
27
25
|
export { InteractionRouter } from "./router/InteractionRouter.js";
|
|
28
|
-
export { LegacyMiniInteractionAdapter } from "./compat/LegacyMiniInteractionAdapter.js";
|
|
29
26
|
export { RADIO_COMPONENT_TYPE } from "./types/radio.js";
|
|
27
|
+
export { CHECKBOX_COMPONENT_TYPE } from "./types/checkbox.js";
|
|
30
28
|
export { ValidationError } from "./types/validation.js";
|
package/dist/types/Commands.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody } from "discord-api-types/v10";
|
|
2
2
|
import type { CommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
3
3
|
import type { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction } from "../utils/ContextMenuInteraction.js";
|
|
4
|
+
import type { ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, RadioInteraction, CheckboxInteraction } from "../utils/MessageComponentInteraction.js";
|
|
5
|
+
import type { ModalSubmitInteraction } from "../utils/ModalSubmitInteraction.js";
|
|
4
6
|
import type { JSONEncodable } from "../builders/shared.js";
|
|
5
7
|
import type { CommandBuilder } from "../commands/CommandBuilder.js";
|
|
6
8
|
import type { MessageCommandBuilder, UserCommandBuilder, AppCommandBuilder } from "../commands/ContextMenuCommandBuilder.js";
|
|
@@ -19,5 +21,17 @@ export type InteractionCommand = {
|
|
|
19
21
|
data: RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody | CommandBuilder | UserCommandBuilder | MessageCommandBuilder | AppCommandBuilder | JSONEncodable<RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody>;
|
|
20
22
|
handler: CommandHandler;
|
|
21
23
|
};
|
|
24
|
+
/** Handler for any message component interaction */
|
|
25
|
+
export type ComponentInteraction = ButtonInteraction | StringSelectInteraction | RoleSelectInteraction | UserSelectInteraction | ChannelSelectInteraction | MentionableSelectInteraction | RadioInteraction | CheckboxInteraction;
|
|
26
|
+
/** Structure for a standalone component handler */
|
|
27
|
+
export type InteractionComponent = {
|
|
28
|
+
customId: string;
|
|
29
|
+
handler: (interaction: ComponentInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
30
|
+
};
|
|
31
|
+
/** Structure for a standalone modal handler */
|
|
32
|
+
export type InteractionModal = {
|
|
33
|
+
customId: string;
|
|
34
|
+
handler: (interaction: ModalSubmitInteraction) => Promise<APIInteractionResponse | void> | APIInteractionResponse | void;
|
|
35
|
+
};
|
|
22
36
|
/** Map of command names to their registered MiniInteraction command definitions. */
|
|
23
37
|
export type InteractionCommandsMap = Map<string, InteractionCommand>;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import type { APIComponentInActionRow, APIComponentInMessageActionRow } from "discord-api-types/v10";
|
|
1
|
+
import type { APIComponentInActionRow, APIComponentInMessageActionRow, APIModalInteractionResponseCallbackComponent } from "discord-api-types/v10";
|
|
2
|
+
import type { APIRadioComponent } from "./radio.js";
|
|
3
|
+
import type { APICheckboxComponent } from "./checkbox.js";
|
|
2
4
|
/** Defines a component structure for use in ActionRow builders. */
|
|
3
|
-
export type ActionRowComponent = APIComponentInActionRow;
|
|
5
|
+
export type ActionRowComponent = APIComponentInActionRow | APIRadioComponent | APICheckboxComponent;
|
|
4
6
|
/** Defines a message component structure for use in message builders. */
|
|
5
|
-
export type MessageActionRowComponent = APIComponentInMessageActionRow;
|
|
7
|
+
export type MessageActionRowComponent = APIComponentInMessageActionRow | APIRadioComponent | APICheckboxComponent;
|
|
8
|
+
/** Structure for an action row containing mini-interaction components. */
|
|
9
|
+
export interface MiniActionRow<T extends ActionRowComponent = ActionRowComponent> {
|
|
10
|
+
type: 1;
|
|
11
|
+
components: T[];
|
|
12
|
+
}
|
|
13
|
+
/** Structure for a message action row containing mini-interaction components. */
|
|
14
|
+
export interface MessageMiniActionRow<T extends MessageActionRowComponent = MessageActionRowComponent> {
|
|
15
|
+
type: 1;
|
|
16
|
+
components: T[];
|
|
17
|
+
}
|
|
18
|
+
/** Generic type for any supported interaction component data. */
|
|
19
|
+
export type InteractionComponentData = MessageActionRowComponent | APIModalInteractionResponseCallbackComponent;
|
|
@@ -3,7 +3,3 @@ export declare enum InteractionFlags {
|
|
|
3
3
|
IsComponentsV2 = 32768,
|
|
4
4
|
SuppressEmbeds = 4
|
|
5
5
|
}
|
|
6
|
-
/** @deprecated Use InteractionFlags instead. */
|
|
7
|
-
export { InteractionFlags as InteractionReplyFlags };
|
|
8
|
-
/** @deprecated Use InteractionFlags instead. */
|
|
9
|
-
export { InteractionFlags as InteractionFollowUpFlags };
|
|
@@ -4,7 +4,3 @@ export var InteractionFlags;
|
|
|
4
4
|
InteractionFlags[InteractionFlags["IsComponentsV2"] = 32768] = "IsComponentsV2";
|
|
5
5
|
InteractionFlags[InteractionFlags["SuppressEmbeds"] = 4] = "SuppressEmbeds";
|
|
6
6
|
})(InteractionFlags || (InteractionFlags = {}));
|
|
7
|
-
/** @deprecated Use InteractionFlags instead. */
|
|
8
|
-
export { InteractionFlags as InteractionReplyFlags };
|
|
9
|
-
/** @deprecated Use InteractionFlags instead. */
|
|
10
|
-
export { InteractionFlags as InteractionFollowUpFlags };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord API support for checkbox components may lag behind discord-api-types releases.
|
|
3
|
+
* These local contracts are runtime-validated and serialized as raw component payloads.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CHECKBOX_COMPONENT_TYPE: 2002;
|
|
6
|
+
export type APICheckboxOption = {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
emoji?: {
|
|
11
|
+
id?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
animated?: boolean;
|
|
14
|
+
};
|
|
15
|
+
default?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type APICheckboxComponent = {
|
|
18
|
+
type: typeof CHECKBOX_COMPONENT_TYPE;
|
|
19
|
+
custom_id: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
options: APICheckboxOption[];
|
|
23
|
+
};
|
|
@@ -138,6 +138,44 @@ export interface MentionableSelectInteraction extends Omit<APIMessageComponentIn
|
|
|
138
138
|
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
139
139
|
}
|
|
140
140
|
export declare const MentionableSelectInteraction: {};
|
|
141
|
+
/**
|
|
142
|
+
* Radio interaction with helper methods.
|
|
143
|
+
*/
|
|
144
|
+
export interface RadioInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
145
|
+
data: APIMessageStringSelectInteractionData;
|
|
146
|
+
values: string[];
|
|
147
|
+
getStringValues: () => string[];
|
|
148
|
+
getResponse: () => APIInteractionResponse | null;
|
|
149
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
150
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
151
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
152
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
153
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
154
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
155
|
+
}) => APIModalInteractionResponse;
|
|
156
|
+
canRespond?: (interactionId: string) => boolean;
|
|
157
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
158
|
+
}
|
|
159
|
+
export declare const RadioInteraction: {};
|
|
160
|
+
/**
|
|
161
|
+
* Checkbox interaction with helper methods.
|
|
162
|
+
*/
|
|
163
|
+
export interface CheckboxInteraction extends Omit<APIMessageComponentInteraction, "data"> {
|
|
164
|
+
data: APIMessageStringSelectInteractionData;
|
|
165
|
+
values: string[];
|
|
166
|
+
getStringValues: () => string[];
|
|
167
|
+
getResponse: () => APIInteractionResponse | null;
|
|
168
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
169
|
+
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
170
|
+
update: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
171
|
+
deferUpdate: () => APIInteractionResponseDeferredMessageUpdate;
|
|
172
|
+
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
173
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
174
|
+
}) => APIModalInteractionResponse;
|
|
175
|
+
canRespond?: (interactionId: string) => boolean;
|
|
176
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
177
|
+
}
|
|
178
|
+
export declare const CheckboxInteraction: {};
|
|
141
179
|
/**
|
|
142
180
|
* Represents a component interaction augmented with helper response methods.
|
|
143
181
|
*
|
|
@@ -8,6 +8,8 @@ export const RoleSelectInteraction = {};
|
|
|
8
8
|
export const UserSelectInteraction = {};
|
|
9
9
|
export const ChannelSelectInteraction = {};
|
|
10
10
|
export const MentionableSelectInteraction = {};
|
|
11
|
+
export const RadioInteraction = {};
|
|
12
|
+
export const CheckboxInteraction = {};
|
|
11
13
|
export const MessageComponentInteraction = {};
|
|
12
14
|
/**
|
|
13
15
|
* Wraps a raw component interaction with helper methods mirroring Discord's expected responses.
|
|
@@ -183,9 +183,12 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
183
183
|
const getChannel = (customId) => getChannels(customId)[0];
|
|
184
184
|
const getAttachment = (customId) => {
|
|
185
185
|
const value = getComponentValue(customId);
|
|
186
|
-
if (!value
|
|
186
|
+
if (!value)
|
|
187
187
|
return undefined;
|
|
188
|
-
|
|
188
|
+
const attachmentId = Array.isArray(value) ? value[0] : value;
|
|
189
|
+
if (!attachmentId)
|
|
190
|
+
return undefined;
|
|
191
|
+
return interaction.data.resolved?.attachments?.[attachmentId];
|
|
189
192
|
};
|
|
190
193
|
return Object.assign(interaction, {
|
|
191
194
|
reply,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { APIInteractionResponseCallbackData, MessageFlags } from "discord-api-types/v10";
|
|
2
|
-
import type {
|
|
2
|
+
import type { APIContainerComponent } from "discord-api-types/v10";
|
|
3
3
|
import type { JSONEncodable } from "../builders/shared.js";
|
|
4
4
|
import { InteractionFlags } from "../types/InteractionFlags.js";
|
|
5
|
+
import type { MessageMiniActionRow } from "../types/ComponentTypes.js";
|
|
5
6
|
/** Union of helper flag enums and raw Discord message flags. */
|
|
6
7
|
export type MessageFlagLike = MessageFlags | InteractionFlags;
|
|
7
8
|
/** Top-level components allowed in messages (ActionRows or Containers) */
|
|
8
|
-
export type TopLevelComponent =
|
|
9
|
+
export type TopLevelComponent = MessageMiniActionRow | APIContainerComponent;
|
|
9
10
|
/** Message payload accepted by helper reply/edit functions. */
|
|
10
11
|
export type InteractionMessageData = {
|
|
11
12
|
content?: string;
|
package/package.json
CHANGED