@minesa-org/mini-interaction 0.4.0 → 0.4.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/README.md +130 -20
- package/dist/index.d.ts +1 -8
- package/dist/index.js +1 -4
- package/dist/types/InteractionFlags.d.ts +0 -4
- package/dist/types/InteractionFlags.js +0 -4
- package/dist/utils/ModalSubmitInteraction.js +5 -2
- 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)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
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 { InteractionFetchHandler, InteractionNodeHandler, InteractionHandlerResult, InteractionRequest, InteractionClientOptions, DiscordOAuthAuthorizeContext, DiscordOAuthCallbackOptions, DiscordOAuthCallbackTemplates, DiscordOAuthErrorTemplateContext, DiscordOAuthServerErrorTemplateContext, DiscordOAuthStateTemplateContext, DiscordOAuthSuccessTemplateContext, DiscordOAuthVerificationPageOptions, } from "./clients/MiniInteraction.js";
|
|
11
7
|
export type { InteractionCommand, SlashCommandHandler, UserCommandHandler, MessageCommandHandler, AppCommandHandler, CommandHandler, } from "./types/Commands.js";
|
|
12
|
-
export type { ComponentCommand, ButtonComponentHandler, StringSelectComponentHandler, RoleSelectComponentHandler, UserSelectComponentHandler, ChannelSelectComponentHandler, MentionableSelectComponentHandler, ComponentHandler, ModalCommand, ModalHandler, InteractionHandler, } from "./clients/MiniInteraction.js";
|
|
13
8
|
export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction, RoleSelectInteraction, UserSelectInteraction, ChannelSelectInteraction, MentionableSelectInteraction, 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";
|
|
@@ -35,8 +30,6 @@ 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";
|
|
42
35
|
export { ValidationError } from "./types/validation.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
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";
|
|
@@ -9,7 +7,7 @@ export { MessageComponentInteraction, ButtonInteraction, StringSelectInteraction
|
|
|
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,5 @@ 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";
|
|
30
27
|
export { ValidationError } from "./types/validation.js";
|
|
@@ -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 };
|
|
@@ -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,
|
package/package.json
CHANGED