@constatic/base 0.0.10 → 0.1.0
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/dist/creators/index.d.ts +1 -0
- package/dist/creators/index.js +2 -0
- package/dist/creators/responders/emit.d.ts +12 -0
- package/dist/creators/responders/emit.js +10 -0
- package/dist/creators/responders/manager.d.ts +4 -3
- package/dist/creators/responders/manager.js +1 -1
- package/dist/creators/responders/responder.d.ts +9 -2
- package/dist/creators/responders/responder.js +3 -0
- package/package.json +1 -1
package/dist/creators/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { ResponderType, type Responder, type ResponderData, type ResponderInteraction } from "./responders/responder.js";
|
|
2
|
+
export { emitResponder } from "./responders/emit.js";
|
|
2
3
|
export { type Command, type CommandData } from "./commands/command.js";
|
|
3
4
|
export { type Event, type EventData, type EventPropData } from "./events/event.js";
|
|
4
5
|
export * from "./setup.js";
|
package/dist/creators/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GenericResponderInteraction } from "./manager.js";
|
|
2
|
+
export type WithCustomId<T> = T & {
|
|
3
|
+
customId: string;
|
|
4
|
+
};
|
|
5
|
+
type EmitResponderInteraction = Omit<GenericResponderInteraction, "customId">;
|
|
6
|
+
interface EmitResponderData {
|
|
7
|
+
customId: string;
|
|
8
|
+
interaction: EmitResponderInteraction;
|
|
9
|
+
}
|
|
10
|
+
export declare function emitResponder(customId: string, interaction: EmitResponderInteraction): void;
|
|
11
|
+
export declare function emitResponder(data: EmitResponderData): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/creators/responders/emit.ts
|
|
2
|
+
import { ConstaticApp } from "../../app.js";
|
|
3
|
+
function emitResponder(a, b) {
|
|
4
|
+
const { customId, interaction } = typeof a === "string" ? { customId: a, interaction: b } : a;
|
|
5
|
+
const app = ConstaticApp.getInstance();
|
|
6
|
+
app.responders.onResponder(Object.assign(interaction, { customId }));
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
emitResponder
|
|
10
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { CacheType, MessageComponentInteraction, ModalSubmitInteraction } from "discord.js";
|
|
1
|
+
import type { CacheType, ChatInputCommandInteraction, MessageComponentInteraction, MessageContextMenuCommandInteraction, ModalSubmitInteraction, UserContextMenuCommandInteraction } from "discord.js";
|
|
2
2
|
import { BaseManager } from "../manager.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { WithCustomId } from "./emit.js";
|
|
4
|
+
import { Responder, ResponderType } from "./responder.js";
|
|
4
5
|
export type GenericResponder = Responder<string, readonly ResponderType[], any, CacheType>;
|
|
5
|
-
export type GenericResponderInteraction = MessageComponentInteraction | ModalSubmitInteraction
|
|
6
|
+
export type GenericResponderInteraction = MessageComponentInteraction | ModalSubmitInteraction | WithCustomId<ChatInputCommandInteraction> | WithCustomId<UserContextMenuCommandInteraction> | WithCustomId<MessageContextMenuCommandInteraction>;
|
|
6
7
|
export declare class ResponderManager extends BaseManager {
|
|
7
8
|
private get config();
|
|
8
9
|
private readonly router;
|
|
@@ -25,7 +25,7 @@ class ResponderManager extends BaseManager {
|
|
|
25
25
|
return this.router.find(type, customId);
|
|
26
26
|
}
|
|
27
27
|
getType(interaction) {
|
|
28
|
-
return interaction.isButton() ? ResponderType.Button : interaction.isStringSelectMenu() ? ResponderType.StringSelect : interaction.isChannelSelectMenu() ? ResponderType.ChannelSelect : interaction.isRoleSelectMenu() ? ResponderType.RoleSelect : interaction.isUserSelectMenu() ? ResponderType.UserSelect : interaction.isMentionableSelectMenu() ? ResponderType.MentionableSelect : interaction.isModalSubmit() && interaction.isFromMessage() ? ResponderType.ModalComponent : interaction.isModalSubmit() ? ResponderType.Modal : undefined;
|
|
28
|
+
return interaction.isButton() ? ResponderType.Button : interaction.isChatInputCommand() ? ResponderType.ChatInput : interaction.isMessageContextMenuCommand() ? ResponderType.MessageContextMenu : interaction.isUserContextMenuCommand() ? ResponderType.UserContextMenu : interaction.isStringSelectMenu() ? ResponderType.StringSelect : interaction.isChannelSelectMenu() ? ResponderType.ChannelSelect : interaction.isRoleSelectMenu() ? ResponderType.RoleSelect : interaction.isUserSelectMenu() ? ResponderType.UserSelect : interaction.isMentionableSelectMenu() ? ResponderType.MentionableSelect : interaction.isModalSubmit() && interaction.isFromMessage() ? ResponderType.ModalComponent : interaction.isModalSubmit() ? ResponderType.Modal : undefined;
|
|
29
29
|
}
|
|
30
30
|
async onResponder(interaction) {
|
|
31
31
|
const { middleware, onError, onNotFound } = this.config;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ButtonInteraction, CacheType, ChannelSelectMenuInteraction, MentionableSelectMenuInteraction, ModalMessageModalSubmitInteraction, ModalSubmitInteraction, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction } from "discord.js";
|
|
1
|
+
import type { ButtonInteraction, CacheType, ChannelSelectMenuInteraction, ChatInputCommandInteraction, MentionableSelectMenuInteraction, MessageContextMenuCommandInteraction, ModalMessageModalSubmitInteraction, ModalSubmitInteraction, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserContextMenuCommandInteraction, UserSelectMenuInteraction } from "discord.js";
|
|
2
2
|
import { type InferRouteParams } from "rou3";
|
|
3
3
|
import type { NotEmptyArray, Prettify, UniqueArray } from "../../utils/types.js";
|
|
4
|
+
import type { WithCustomId } from "./emit.js";
|
|
4
5
|
export declare enum ResponderType {
|
|
5
6
|
Button = "button",
|
|
6
7
|
StringSelect = "select.string",
|
|
@@ -9,7 +10,10 @@ export declare enum ResponderType {
|
|
|
9
10
|
ChannelSelect = "select.channel",
|
|
10
11
|
MentionableSelect = "select.mentionable",
|
|
11
12
|
Modal = "modal",
|
|
12
|
-
ModalComponent = "modal.component"
|
|
13
|
+
ModalComponent = "modal.component",
|
|
14
|
+
ChatInput = "command.chat.input",
|
|
15
|
+
UserContextMenu = "command.context.user",
|
|
16
|
+
MessageContextMenu = "command.context.message"
|
|
13
17
|
}
|
|
14
18
|
export type ResponderInteraction<Type extends ResponderType, Cache extends CacheType> = {
|
|
15
19
|
[ResponderType.Button]: ButtonInteraction<Cache>;
|
|
@@ -20,6 +24,9 @@ export type ResponderInteraction<Type extends ResponderType, Cache extends Cache
|
|
|
20
24
|
[ResponderType.MentionableSelect]: MentionableSelectMenuInteraction<Cache>;
|
|
21
25
|
[ResponderType.Modal]: ModalSubmitInteraction<Cache>;
|
|
22
26
|
[ResponderType.ModalComponent]: ModalMessageModalSubmitInteraction<Cache>;
|
|
27
|
+
[ResponderType.ChatInput]: WithCustomId<ChatInputCommandInteraction<Cache>>;
|
|
28
|
+
[ResponderType.UserContextMenu]: WithCustomId<UserContextMenuCommandInteraction<Cache>>;
|
|
29
|
+
[ResponderType.MessageContextMenu]: WithCustomId<MessageContextMenuCommandInteraction<Cache>>;
|
|
23
30
|
}[Type];
|
|
24
31
|
type ResolveParams<Path extends string, Parsed> = Prettify<Parsed extends {
|
|
25
32
|
[x: string | number | symbol]: any;
|
|
@@ -9,6 +9,9 @@ var ResponderType;
|
|
|
9
9
|
ResponderType2["MentionableSelect"] = "select.mentionable";
|
|
10
10
|
ResponderType2["Modal"] = "modal";
|
|
11
11
|
ResponderType2["ModalComponent"] = "modal.component";
|
|
12
|
+
ResponderType2["ChatInput"] = "command.chat.input";
|
|
13
|
+
ResponderType2["UserContextMenu"] = "command.context.user";
|
|
14
|
+
ResponderType2["MessageContextMenu"] = "command.context.message";
|
|
12
15
|
})(ResponderType ||= {});
|
|
13
16
|
|
|
14
17
|
class Responder {
|