@constatic/base 0.1.0 → 0.1.2
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 → build}/bootstrap.d.ts +7 -0
- package/{dist → build}/bootstrap.js +8 -3
- package/{dist → build}/client.js +4 -4
- package/{dist → build}/creators/commands/command.d.ts +9 -6
- package/{dist → build}/creators/commands/manager.js +7 -7
- package/build/creators/index.d.ts +6 -0
- package/{dist → build}/creators/index.js +2 -2
- package/{dist → build}/creators/responders/emit.d.ts +1 -1
- package/build/creators/responders/responder.js +26 -0
- package/{dist → build}/error.d.ts +5 -1
- package/{dist → build}/error.js +29 -28
- package/{dist → build}/modules.d.ts +1 -0
- package/build/modules.js +34 -0
- package/{dist → build}/version.js +1 -1
- package/package.json +8 -10
- package/tsconfig/base.json +2 -1
- package/dist/creators/index.d.ts +0 -5
- package/dist/creators/responders/responder.js +0 -26
- package/dist/modules.js +0 -18
- package/dist/register.d.ts +0 -1
- package/dist/register.js +0 -21
- package/dist/utils/schema.d.ts +0 -56
- package/dist/utils/schema.js +0 -0
- /package/{dist → build}/app.d.ts +0 -0
- /package/{dist → build}/app.js +0 -0
- /package/{dist → build}/client.d.ts +0 -0
- /package/{dist → build}/creators/commands/command.js +0 -0
- /package/{dist → build}/creators/commands/manager.d.ts +0 -0
- /package/{dist → build}/creators/events/event.d.ts +0 -0
- /package/{dist → build}/creators/events/event.js +0 -0
- /package/{dist → build}/creators/events/manager.d.ts +0 -0
- /package/{dist → build}/creators/events/manager.js +0 -0
- /package/{dist → build}/creators/manager.d.ts +0 -0
- /package/{dist → build}/creators/manager.js +0 -0
- /package/{dist → build}/creators/responders/emit.js +0 -0
- /package/{dist → build}/creators/responders/manager.d.ts +0 -0
- /package/{dist → build}/creators/responders/manager.js +0 -0
- /package/{dist → build}/creators/responders/responder.d.ts +0 -0
- /package/{dist → build}/creators/setup.d.ts +0 -0
- /package/{dist → build}/creators/setup.js +0 -0
- /package/{dist → build}/env.d.ts +0 -0
- /package/{dist → build}/env.js +0 -0
- /package/{dist → build}/index.d.ts +0 -0
- /package/{dist → build}/index.js +0 -0
- /package/{dist → build}/standard-schema.d.ts +0 -0
- /package/{dist → build}/standard-schema.js +0 -0
- /package/{dist → build}/utils/router.d.ts +0 -0
- /package/{dist → build}/utils/router.js +0 -0
- /package/{dist → build}/utils/types.d.ts +0 -0
- /package/{dist → build}/utils/types.js +0 -0
- /package/{dist → build}/version.d.ts +0 -0
|
@@ -45,6 +45,13 @@ export interface BootstrapOptions extends CustomClientOptions {
|
|
|
45
45
|
* values from `process.env`.
|
|
46
46
|
*/
|
|
47
47
|
env?: Record<string, any>;
|
|
48
|
+
/**
|
|
49
|
+
* Generates a file with only imports of the automatically loaded modules that are returned by the bootstrap function
|
|
50
|
+
*
|
|
51
|
+
* - Define `true` to generate the imports.ts file
|
|
52
|
+
* - Define a `string` path to activate and customize the file output
|
|
53
|
+
*/
|
|
54
|
+
generateImportsFile?: boolean | string;
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
57
|
*
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// src/bootstrap.ts
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { ConstaticApp } from "./app.js";
|
|
3
4
|
import { createClient } from "./client.js";
|
|
4
|
-
import {
|
|
5
|
-
import { loadModules } from "./modules.js";
|
|
5
|
+
import { Errors } from "./error.js";
|
|
6
|
+
import { generateImportsFile, loadModules } from "./modules.js";
|
|
6
7
|
async function bootstrap(options) {
|
|
7
8
|
const token = options.token ?? options.env?.BOT_TOKEN ?? process.env?.BOT_TOKEN;
|
|
8
9
|
if (!token)
|
|
9
|
-
throw
|
|
10
|
+
throw Errors.tokenNotProvided();
|
|
10
11
|
const app = ConstaticApp.getInstance();
|
|
11
12
|
if (options.errorHandler) {
|
|
12
13
|
app.setErrorHandler(options.errorHandler);
|
|
@@ -28,6 +29,10 @@ async function bootstrap(options) {
|
|
|
28
29
|
app.intro();
|
|
29
30
|
app.events.register(client);
|
|
30
31
|
client.login();
|
|
32
|
+
if (options.generateImportsFile) {
|
|
33
|
+
const outputPath = join(options.meta.dirname, typeof options.generateImportsFile === "string" ? options.generateImportsFile : "imports.ts");
|
|
34
|
+
await generateImportsFile(options.meta, outputPath, imports);
|
|
35
|
+
}
|
|
31
36
|
return { client, imports };
|
|
32
37
|
}
|
|
33
38
|
export {
|
package/{dist → build}/client.js
RENAMED
|
@@ -13,10 +13,10 @@ function createClient(token, options) {
|
|
|
13
13
|
failIfNotExists: options.failIfNotExists ?? false
|
|
14
14
|
});
|
|
15
15
|
client.token = token;
|
|
16
|
-
client.once("clientReady", async (
|
|
17
|
-
console.log("%s %s %s", styleText("green", "●"), styleText(["greenBright", "underline"],
|
|
18
|
-
await app.commands.register(
|
|
19
|
-
await app.events.runReady(
|
|
16
|
+
client.once("clientReady", async (client) => {
|
|
17
|
+
console.log("%s %s %s", styleText("green", "●"), styleText(["greenBright", "underline"], client.user.username), styleText("green", "application is ready!"));
|
|
18
|
+
await app.commands.register(client);
|
|
19
|
+
await app.events.runReady(client);
|
|
20
20
|
});
|
|
21
21
|
client.on("interactionCreate", async (interaction) => {
|
|
22
22
|
if (interaction.isAutocomplete()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplicationCommandOptionType, ApplicationCommandType, AutocompleteInteraction, ChatInputCommandInteraction, InteractionContextType, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, type ApplicationCommandOptionAllowedChannelTypes, type ApplicationCommandOptionChoiceData, type BaseApplicationCommandData, type CacheType, type LocalizationMap } from "discord.js";
|
|
1
|
+
import { ApplicationCommandOptionType, ApplicationCommandType, AutocompleteInteraction, ChatInputCommandInteraction, InteractionContextType, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, type ApplicationCommandOptionAllowedChannelTypes, type ApplicationCommandOptionChoiceData, type BaseApplicationCommandData, type CacheType, type FileUploadType, type LocalizationMap } from "discord.js";
|
|
2
2
|
import type { NotEmptyArray, UniqueArray } from "../../utils/types.js";
|
|
3
3
|
export type CommandType = ApplicationCommandType.ChatInput | ApplicationCommandType.Message | ApplicationCommandType.User;
|
|
4
4
|
type AutocompleData<Type> = Promise<readonly ApplicationCommandOptionChoiceData<Type extends (number | string) ? Type : (number | string)>[] | undefined | void>;
|
|
@@ -29,10 +29,14 @@ interface ChannelOptionData extends BaseOptionData {
|
|
|
29
29
|
type: ApplicationCommandOptionType.Channel;
|
|
30
30
|
channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[];
|
|
31
31
|
}
|
|
32
|
+
interface AttachmentOptionData extends BaseOptionData {
|
|
33
|
+
type: ApplicationCommandOptionType.Attachment;
|
|
34
|
+
fileTypes?: readonly FileUploadType[];
|
|
35
|
+
}
|
|
32
36
|
interface CommonOptionData extends BaseOptionData {
|
|
33
|
-
type: ApplicationCommandOptionType.
|
|
37
|
+
type: ApplicationCommandOptionType.Boolean | ApplicationCommandOptionType.Mentionable | ApplicationCommandOptionType.Role | ApplicationCommandOptionType.User;
|
|
34
38
|
}
|
|
35
|
-
export type SlashCommandPrimitiveOptionData<Contexts> = StringOptionData<Contexts> | NumberOptionData<Contexts> | CommonOptionData | ChannelOptionData;
|
|
39
|
+
export type SlashCommandPrimitiveOptionData<Contexts> = StringOptionData<Contexts> | NumberOptionData<Contexts> | AttachmentOptionData | CommonOptionData | ChannelOptionData;
|
|
36
40
|
export interface SubCommandOptionData<Contexts> extends Omit<BaseOptionData, "required"> {
|
|
37
41
|
type: ApplicationCommandOptionType.Subcommand;
|
|
38
42
|
options?: SlashCommandPrimitiveOptionData<Contexts>[];
|
|
@@ -52,15 +56,14 @@ interface CommandRunThis {
|
|
|
52
56
|
*/
|
|
53
57
|
block(): never;
|
|
54
58
|
}
|
|
55
|
-
type ResolveCommandModuleData<Return> = Return extends void ? undefined : Return;
|
|
56
59
|
export type SubCommandModuleData<Contexts, Return> = Omit<BaseOptionData, "required"> & {
|
|
57
60
|
group?: string;
|
|
58
|
-
run(this: CommandRunThis, interaction: ChatInputCommandInteraction<CacheMode<Contexts>>, data:
|
|
61
|
+
run(this: CommandRunThis, interaction: ChatInputCommandInteraction<CacheMode<Contexts>>, data: Return extends void ? undefined : Return): Promise<void>;
|
|
59
62
|
options?: SlashCommandPrimitiveOptionData<Contexts>[];
|
|
60
63
|
};
|
|
61
64
|
export type SubCommandGroupModuleData<Contexts, Return, T> = Omit<BaseOptionData, "required"> & {
|
|
62
65
|
options?: Omit<SubCommandOptionData<Contexts>, "type">[];
|
|
63
|
-
run?(this: CommandRunThis, interaction: ChatInputCommandInteraction<CacheMode<Contexts>>, data:
|
|
66
|
+
run?(this: CommandRunThis, interaction: ChatInputCommandInteraction<CacheMode<Contexts>>, data: Return extends void ? undefined : Return): Promise<T>;
|
|
64
67
|
};
|
|
65
68
|
type RunInteraction<T, Contexts> = T extends ApplicationCommandType.Message ? MessageContextMenuCommandInteraction<CacheMode<Contexts>> : T extends ApplicationCommandType.User ? UserContextMenuCommandInteraction<CacheMode<Contexts>> : ChatInputCommandInteraction<CacheMode<Contexts>>;
|
|
66
69
|
type BaseAppCommandData = Omit<BaseApplicationCommandData, "contexts"> & Pick<BaseOptionData, "descriptionLocalizations">;
|
|
@@ -81,12 +81,12 @@ class CommandManager extends BaseManager {
|
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
83
|
case ApplicationCommandOptionType.Subcommand: {
|
|
84
|
-
const { options
|
|
84
|
+
const { options, ...data } = option;
|
|
85
85
|
resolved.push({
|
|
86
86
|
...data,
|
|
87
87
|
description,
|
|
88
|
-
...
|
|
89
|
-
options: this.buildOptions(
|
|
88
|
+
...options?.length ? {
|
|
89
|
+
options: this.buildOptions(options, `${path}/${data.name}`)
|
|
90
90
|
} : {}
|
|
91
91
|
});
|
|
92
92
|
continue;
|
|
@@ -120,8 +120,8 @@ class CommandManager extends BaseManager {
|
|
|
120
120
|
if (groups.length >= 1) {
|
|
121
121
|
for (const group of groups) {
|
|
122
122
|
const data = [
|
|
123
|
-
...(group.options ?? []).map((
|
|
124
|
-
...
|
|
123
|
+
...(group.options ?? []).map((data) => ({
|
|
124
|
+
...data,
|
|
125
125
|
type: ApplicationCommandOptionType.Subcommand
|
|
126
126
|
})),
|
|
127
127
|
...subcommands.filter((sub) => sub.group === group.name)
|
|
@@ -197,8 +197,8 @@ class CommandManager extends BaseManager {
|
|
|
197
197
|
const promises = [];
|
|
198
198
|
const manager = client.application.commands;
|
|
199
199
|
const logs = [];
|
|
200
|
-
const setGlobal = async (
|
|
201
|
-
const data = await manager.set(
|
|
200
|
+
const setGlobal = async (commands) => {
|
|
201
|
+
const data = await manager.set(commands);
|
|
202
202
|
logs.push([data.size, `${client.user.username} application`]);
|
|
203
203
|
};
|
|
204
204
|
if (guildList.size) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ResponderType, type Responder, type ResponderData, type ResponderInteraction } from "./responders/responder.js";
|
|
2
|
+
export { emitResponder, type EmitResponderData } from "./responders/emit.js";
|
|
3
|
+
export type { GenericResponder, GenericResponderInteraction } from "./responders/manager.js";
|
|
4
|
+
export type { Command, CommandData } from "./commands/command.js";
|
|
5
|
+
export { type Event, type EventData, type EventPropData } from "./events/event.js";
|
|
6
|
+
export * from "./setup.js";
|
|
@@ -3,7 +3,7 @@ export type WithCustomId<T> = T & {
|
|
|
3
3
|
customId: string;
|
|
4
4
|
};
|
|
5
5
|
type EmitResponderInteraction = Omit<GenericResponderInteraction, "customId">;
|
|
6
|
-
interface EmitResponderData {
|
|
6
|
+
export interface EmitResponderData {
|
|
7
7
|
customId: string;
|
|
8
8
|
interaction: EmitResponderInteraction;
|
|
9
9
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/creators/responders/responder.ts
|
|
2
|
+
var ResponderType;
|
|
3
|
+
((ResponderType) => {
|
|
4
|
+
ResponderType["Button"] = "button";
|
|
5
|
+
ResponderType["StringSelect"] = "select.string";
|
|
6
|
+
ResponderType["UserSelect"] = "select.user";
|
|
7
|
+
ResponderType["RoleSelect"] = "select.role";
|
|
8
|
+
ResponderType["ChannelSelect"] = "select.channel";
|
|
9
|
+
ResponderType["MentionableSelect"] = "select.mentionable";
|
|
10
|
+
ResponderType["Modal"] = "modal";
|
|
11
|
+
ResponderType["ModalComponent"] = "modal.component";
|
|
12
|
+
ResponderType["ChatInput"] = "command.chat.input";
|
|
13
|
+
ResponderType["UserContextMenu"] = "command.context.user";
|
|
14
|
+
ResponderType["MessageContextMenu"] = "command.context.message";
|
|
15
|
+
})(ResponderType ||= {});
|
|
16
|
+
|
|
17
|
+
class Responder {
|
|
18
|
+
data;
|
|
19
|
+
constructor(data) {
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
Responder,
|
|
25
|
+
ResponderType
|
|
26
|
+
};
|
|
@@ -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 → build}/error.js
RENAMED
|
@@ -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
|
|
|
@@ -15,7 +23,7 @@ async function baseErrorHandler(error, client) {
|
|
|
15
23
|
if (client?.user)
|
|
16
24
|
console.log(client.user.displayName);
|
|
17
25
|
const text = [];
|
|
18
|
-
const hightlight = (
|
|
26
|
+
const hightlight = (text) => text.replace(/\(([^)]+)\)/g, (_, match) => [
|
|
19
27
|
styleText("gray", "("),
|
|
20
28
|
styleText("cyan", match),
|
|
21
29
|
styleText("gray", ")")
|
|
@@ -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"));
|
|
@@ -65,7 +65,8 @@ async function baseErrorHandler(error, client) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
export {
|
|
68
|
-
|
|
68
|
+
ConstaticError,
|
|
69
|
+
Errors,
|
|
69
70
|
RunBlockError,
|
|
70
|
-
|
|
71
|
+
baseErrorHandler
|
|
71
72
|
};
|
|
@@ -7,3 +7,4 @@ export interface ModuleImported {
|
|
|
7
7
|
* along with its file path.
|
|
8
8
|
*/
|
|
9
9
|
export declare function loadModules(meta: ImportMeta, modules?: string[]): Promise<ModuleImported[]>;
|
|
10
|
+
export declare function generateImportsFile(meta: ImportMeta, path: string, imports: ModuleImported[]): Promise<void>;
|
package/build/modules.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/modules.ts
|
|
2
|
+
import { glob, mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, extname, join, relative } from "node:path";
|
|
4
|
+
async function loadModules(meta, modules = []) {
|
|
5
|
+
const exclude = modules.filter((path) => path.charAt(0) == "!").map((path) => path.slice(1));
|
|
6
|
+
const filepaths = await Array.fromAsync(glob(modules, { cwd: meta.dirname, exclude }));
|
|
7
|
+
const loadedModules = [];
|
|
8
|
+
for (const path of filepaths) {
|
|
9
|
+
await import("file://" + join(meta.dirname, path)).then((imported) => loadedModules.push({
|
|
10
|
+
module: imported,
|
|
11
|
+
filepath: path
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
return loadedModules;
|
|
15
|
+
}
|
|
16
|
+
async function generateImportsFile(meta, path, imports) {
|
|
17
|
+
const dir = dirname(path);
|
|
18
|
+
const content = imports.map(({ filepath }) => {
|
|
19
|
+
const modulePath = join(meta.dirname, filepath);
|
|
20
|
+
let relativePath = relative(dir, modulePath);
|
|
21
|
+
if (!relativePath.startsWith(".")) {
|
|
22
|
+
relativePath = `./${relativePath}`;
|
|
23
|
+
}
|
|
24
|
+
relativePath = relativePath.replaceAll("\\", "/").replace(new RegExp(`${extname(relativePath)}$`), ".js");
|
|
25
|
+
return `import "${relativePath}";`;
|
|
26
|
+
}).join(`
|
|
27
|
+
`);
|
|
28
|
+
await mkdir(dir, { recursive: true });
|
|
29
|
+
await writeFile(path, content, "utf-8");
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
generateImportsFile,
|
|
33
|
+
loadModules
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constatic/base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Library with structures and functions for creating modern Discord applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,18 +42,18 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@constatic/config": "*",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"discord.js": "^14.28.1",
|
|
46
|
+
"typescript": "^7.0.2"
|
|
47
47
|
},
|
|
48
48
|
"exports": {
|
|
49
49
|
".": {
|
|
50
|
-
"import": "./
|
|
51
|
-
"types": "./
|
|
50
|
+
"import": "./build/index.js",
|
|
51
|
+
"types": "./build/index.d.ts"
|
|
52
52
|
},
|
|
53
53
|
"./tsconfig": "./tsconfig/base.json"
|
|
54
54
|
},
|
|
55
55
|
"files": [
|
|
56
|
-
"
|
|
56
|
+
"build",
|
|
57
57
|
"tsconfig"
|
|
58
58
|
],
|
|
59
59
|
"homepage": "https://constatic-docs.vercel.app",
|
|
@@ -63,17 +63,15 @@
|
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
|
-
"check": "tsc --noEmit",
|
|
67
66
|
"typegen": "tsc",
|
|
68
67
|
"build": "bun run ./build.ts",
|
|
69
68
|
"prepublish": "bun run build",
|
|
70
|
-
"dev": "bun run ./
|
|
69
|
+
"dev": "bun run ./demo/index.ts"
|
|
71
70
|
},
|
|
72
71
|
"peerDependencies": {
|
|
73
72
|
"discord.js": ">=14.25.0"
|
|
74
73
|
},
|
|
75
74
|
"dependencies": {
|
|
76
|
-
"rou3": "^0.
|
|
77
|
-
"tinyglobby": "^0.2.16"
|
|
75
|
+
"rou3": "^1.0.0"
|
|
78
76
|
}
|
|
79
77
|
}
|
package/tsconfig/base.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://www.schemastore.org/tsconfig",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"strict": true,
|
|
5
|
+
"verbatimModuleSyntax": true,
|
|
4
6
|
"esModuleInterop": true,
|
|
5
7
|
"forceConsistentCasingInFileNames": true,
|
|
6
8
|
"skipLibCheck": true,
|
|
7
9
|
"resolveJsonModule": true,
|
|
8
|
-
"strict": true,
|
|
9
10
|
|
|
10
11
|
"lib": ["ESNext"],
|
|
11
12
|
"target": "ESNext",
|
package/dist/creators/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { ResponderType, type Responder, type ResponderData, type ResponderInteraction } from "./responders/responder.js";
|
|
2
|
-
export { emitResponder } from "./responders/emit.js";
|
|
3
|
-
export { type Command, type CommandData } from "./commands/command.js";
|
|
4
|
-
export { type Event, type EventData, type EventPropData } from "./events/event.js";
|
|
5
|
-
export * from "./setup.js";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/creators/responders/responder.ts
|
|
2
|
-
var ResponderType;
|
|
3
|
-
((ResponderType2) => {
|
|
4
|
-
ResponderType2["Button"] = "button";
|
|
5
|
-
ResponderType2["StringSelect"] = "select.string";
|
|
6
|
-
ResponderType2["UserSelect"] = "select.user";
|
|
7
|
-
ResponderType2["RoleSelect"] = "select.role";
|
|
8
|
-
ResponderType2["ChannelSelect"] = "select.channel";
|
|
9
|
-
ResponderType2["MentionableSelect"] = "select.mentionable";
|
|
10
|
-
ResponderType2["Modal"] = "modal";
|
|
11
|
-
ResponderType2["ModalComponent"] = "modal.component";
|
|
12
|
-
ResponderType2["ChatInput"] = "command.chat.input";
|
|
13
|
-
ResponderType2["UserContextMenu"] = "command.context.user";
|
|
14
|
-
ResponderType2["MessageContextMenu"] = "command.context.message";
|
|
15
|
-
})(ResponderType ||= {});
|
|
16
|
-
|
|
17
|
-
class Responder {
|
|
18
|
-
data;
|
|
19
|
-
constructor(data) {
|
|
20
|
-
this.data = data;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export {
|
|
24
|
-
ResponderType,
|
|
25
|
-
Responder
|
|
26
|
-
};
|
package/dist/modules.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// src/modules.ts
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { glob } from "tinyglobby";
|
|
4
|
-
async function loadModules(meta, modules = []) {
|
|
5
|
-
const ignore = modules.filter((path) => path.charAt(0) == "!").map((path) => path.slice(1));
|
|
6
|
-
const filepaths = await glob(modules, { cwd: meta.dirname, ignore });
|
|
7
|
-
const loadedModules = [];
|
|
8
|
-
for (const path of filepaths) {
|
|
9
|
-
await import("file://" + join(meta.dirname, path)).then((imported) => loadedModules.push({
|
|
10
|
-
module: imported,
|
|
11
|
-
filepath: path
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
return loadedModules;
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
loadModules
|
|
18
|
-
};
|
package/dist/register.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/register.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// src/register.ts
|
|
2
|
-
import { ConstaticApp } from "./app.js";
|
|
3
|
-
async function registerCommands(client) {
|
|
4
|
-
const app = ConstaticApp.getInstance();
|
|
5
|
-
const guildList = new Set(app.config.commands.guilds);
|
|
6
|
-
const commands = app.commands.build();
|
|
7
|
-
const promises = [];
|
|
8
|
-
const manager = client.application.commands;
|
|
9
|
-
if (guildList.size >= 1) {
|
|
10
|
-
const globalCommands = commands.filter((c) => c.global);
|
|
11
|
-
const guildCommands = commands.filter((c) => !c.global);
|
|
12
|
-
for (const id of guildList.values()) {
|
|
13
|
-
promises.push(manager.set(guildCommands, id));
|
|
14
|
-
}
|
|
15
|
-
promises.push(manager.set(globalCommands));
|
|
16
|
-
}
|
|
17
|
-
await Promise.all(promises).then(console.log);
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
registerCommands
|
|
21
|
-
};
|
package/dist/utils/schema.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** The Standard Schema interface. */
|
|
2
|
-
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
|
-
/** The Standard Schema properties. */
|
|
4
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
-
}
|
|
6
|
-
export declare namespace StandardSchemaV1 {
|
|
7
|
-
/** The Standard Schema properties interface. */
|
|
8
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
9
|
-
/** The version number of the standard. */
|
|
10
|
-
readonly version: 1;
|
|
11
|
-
/** The vendor name of the schema library. */
|
|
12
|
-
readonly vendor: string;
|
|
13
|
-
/** Validates unknown input values. */
|
|
14
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
-
/** Inferred types associated with the schema. */
|
|
16
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
-
}
|
|
18
|
-
/** The result interface of the validate function. */
|
|
19
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
-
/** The result interface if validation succeeds. */
|
|
21
|
-
export interface SuccessResult<Output> {
|
|
22
|
-
/** The typed output value. */
|
|
23
|
-
readonly value: Output;
|
|
24
|
-
/** The non-existent issues. */
|
|
25
|
-
readonly issues?: undefined;
|
|
26
|
-
}
|
|
27
|
-
/** The result interface if validation fails. */
|
|
28
|
-
export interface FailureResult {
|
|
29
|
-
/** The issues of failed validation. */
|
|
30
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
31
|
-
}
|
|
32
|
-
/** The issue interface of the failure output. */
|
|
33
|
-
export interface Issue {
|
|
34
|
-
/** The error message of the issue. */
|
|
35
|
-
readonly message: string;
|
|
36
|
-
/** The path of the issue, if any. */
|
|
37
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
38
|
-
}
|
|
39
|
-
/** The path segment interface of the issue. */
|
|
40
|
-
export interface PathSegment {
|
|
41
|
-
/** The key representing a path segment. */
|
|
42
|
-
readonly key: PropertyKey;
|
|
43
|
-
}
|
|
44
|
-
/** The Standard Schema types interface. */
|
|
45
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
46
|
-
/** The input type of the schema. */
|
|
47
|
-
readonly input: Input;
|
|
48
|
-
/** The output type of the schema. */
|
|
49
|
-
readonly output: Output;
|
|
50
|
-
}
|
|
51
|
-
/** Infers the input type of a Standard Schema. */
|
|
52
|
-
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
53
|
-
/** Infers the output type of a Standard Schema. */
|
|
54
|
-
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
55
|
-
export {};
|
|
56
|
-
}
|
package/dist/utils/schema.js
DELETED
|
File without changes
|
/package/{dist → build}/app.d.ts
RENAMED
|
File without changes
|
/package/{dist → build}/app.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{dist → build}/env.d.ts
RENAMED
|
File without changes
|
/package/{dist → build}/env.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/{dist → build}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|