@constatic/base 0.0.10 → 0.1.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/dist/bootstrap.js +2 -2
- 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/dist/error.d.ts +5 -1
- package/dist/error.js +26 -25
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/bootstrap.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/bootstrap.ts
|
|
2
2
|
import { ConstaticApp } from "./app.js";
|
|
3
3
|
import { createClient } from "./client.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Errors } from "./error.js";
|
|
5
5
|
import { loadModules } from "./modules.js";
|
|
6
6
|
async function bootstrap(options) {
|
|
7
7
|
const token = options.token ?? options.env?.BOT_TOKEN ?? process.env?.BOT_TOKEN;
|
|
8
8
|
if (!token)
|
|
9
|
-
throw
|
|
9
|
+
throw Errors.tokenNotProvided();
|
|
10
10
|
const app = ConstaticApp.getInstance();
|
|
11
11
|
if (options.errorHandler) {
|
|
12
12
|
app.setErrorHandler(options.errorHandler);
|
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 {
|
package/dist/error.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Client } from "discord.js";
|
|
2
2
|
export declare class ConstaticError extends Error {
|
|
3
|
-
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class Errors {
|
|
7
|
+
static tokenNotProvided(): ConstaticError;
|
|
4
8
|
}
|
|
5
9
|
export declare class RunBlockError {
|
|
6
10
|
}
|
package/dist/error.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
|
-
import { codeBlock, TextDisplayBuilder, time,
|
|
2
|
+
import { codeBlock, TextDisplayBuilder, time, WebhookClient } from "discord.js";
|
|
3
3
|
import console from "node:console";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
|
|
6
6
|
class ConstaticError extends Error {
|
|
7
|
-
|
|
7
|
+
code;
|
|
8
|
+
constructor(code, message) {
|
|
8
9
|
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class Errors {
|
|
15
|
+
static tokenNotProvided() {
|
|
16
|
+
return new ConstaticError("TOKEN_NOT_PROVIDED", "The application token was not provided!");
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
19
|
|
|
@@ -31,32 +39,24 @@ async function baseErrorHandler(error, client) {
|
|
|
31
39
|
const url = process.env.WEBHOOK_LOGS_URL;
|
|
32
40
|
if (!url)
|
|
33
41
|
return;
|
|
34
|
-
const
|
|
35
|
-
if (!data)
|
|
36
|
-
return;
|
|
37
|
-
const rest = new REST;
|
|
38
|
-
if (process.env.BOT_TOKEN)
|
|
39
|
-
rest.setToken(process.env.BOT_TOKEN);
|
|
42
|
+
const username = client?.user?.username;
|
|
40
43
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
codeBlock("ansi", text.join(`
|
|
44
|
+
new WebhookClient({ url }).send({
|
|
45
|
+
flags: "IsComponentsV2",
|
|
46
|
+
withComponents: true,
|
|
47
|
+
components: [
|
|
48
|
+
new TextDisplayBuilder({
|
|
49
|
+
content: [
|
|
50
|
+
codeBlock("ansi", text.join(`
|
|
49
51
|
`)),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
time(new Date, "R")
|
|
53
|
+
].join(`
|
|
52
54
|
`)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}).catch(console.error);
|
|
55
|
+
})
|
|
56
|
+
],
|
|
57
|
+
avatarURL: client?.user?.displayAvatarURL({ size: 512 }),
|
|
58
|
+
username: username ? `${username} logs` : "Logs"
|
|
59
|
+
});
|
|
60
60
|
} catch {
|
|
61
61
|
console.log();
|
|
62
62
|
console.error("ENV VAR → %s Invalid webhook url", styleText(["bold", "underline"], "WEBHOOK_LOGS_URL"));
|
|
@@ -67,5 +67,6 @@ async function baseErrorHandler(error, client) {
|
|
|
67
67
|
export {
|
|
68
68
|
baseErrorHandler,
|
|
69
69
|
RunBlockError,
|
|
70
|
+
Errors,
|
|
70
71
|
ConstaticError
|
|
71
72
|
};
|
package/dist/version.js
CHANGED