@arox/framework 0.1.1 → 0.1.2-beta.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/context.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1193 -14
- package/dist/structures/builder/Builder.d.ts +19 -0
- package/dist/structures/builder/Command.d.ts +7 -19
- package/dist/structures/builder/Context.d.ts +5 -2
- package/dist/structures/builder/Event.d.ts +3 -6
- package/dist/structures/builder/index.d.ts +1 -1
- package/dist/structures/core/Client.d.ts +3 -4
- package/dist/utils/logger/Logger.d.ts +1 -0
- package/dist/utils/normalizeArray.d.ts +15 -0
- package/package.json +1 -62
- package/cliff.toml +0 -48
- package/dist/context.js +0 -28
- package/dist/events/interaction.js +0 -38
- package/dist/events/message.js +0 -36
- package/dist/events/ready.js +0 -11
- package/dist/structures/builder/Argument.d.ts +0 -22
- package/dist/structures/builder/Argument.js +0 -42
- package/dist/structures/builder/Command.js +0 -74
- package/dist/structures/builder/Context.js +0 -67
- package/dist/structures/builder/Event.js +0 -53
- package/dist/structures/builder/index.js +0 -9
- package/dist/structures/core/Client.js +0 -111
- package/dist/structures/core/index.js +0 -6
- package/dist/structures/index.js +0 -7
- package/dist/utils/Files.js +0 -47
- package/dist/utils/index.js +0 -8
- package/dist/utils/logger/ILogger.js +0 -37
- package/dist/utils/logger/Logger.js +0 -380
- package/dist/utils/util.js +0 -35
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SlashCommandBuilder, RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js";
|
|
2
|
+
import { Client } from "../core";
|
|
3
|
+
export interface ApplicationJSONBody extends RESTPostAPIChatInputApplicationCommandsJSONBody {
|
|
4
|
+
prefix_support: boolean;
|
|
5
|
+
slash_support: boolean;
|
|
6
|
+
aliases: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare class ApplicationCommandBuilder extends SlashCommandBuilder {
|
|
9
|
+
constructor();
|
|
10
|
+
protected prefix_support: boolean;
|
|
11
|
+
protected slash_support: boolean;
|
|
12
|
+
protected aliases: string[];
|
|
13
|
+
setAliases(...alias: string[]): this;
|
|
14
|
+
addAliases(...alias: string[]): this;
|
|
15
|
+
setPrefixSupport(support: boolean): this;
|
|
16
|
+
setSlashSupport(support: boolean): this;
|
|
17
|
+
toJSON(): ApplicationJSONBody;
|
|
18
|
+
toClientJSON(_client: Client): ReturnType<ApplicationCommandBuilder["toJSON"]>;
|
|
19
|
+
}
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context, Client } from "
|
|
3
|
-
import { Argument } from "./Argument";
|
|
1
|
+
import { ChatInputCommandInteraction, Message } from "discord.js";
|
|
2
|
+
import { Context, Client } from "../index";
|
|
4
3
|
import { MaybePromise } from "#types/extra.js";
|
|
5
|
-
import { Logger } from "
|
|
4
|
+
import { Logger } from "../../utils/index";
|
|
5
|
+
import { ApplicationCommandBuilder } from "./Builder";
|
|
6
6
|
type MessageContext = NonNullable<ReturnType<Context<Message>["toJSON"]>>;
|
|
7
7
|
type InteractionContext = NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>;
|
|
8
|
-
export interface CommandOptions {
|
|
9
|
-
name: string;
|
|
10
|
-
description: string;
|
|
11
|
-
aliases?: string[];
|
|
12
|
-
options?: (ApplicationCommandOptionData | Argument)[];
|
|
13
|
-
slash?: boolean;
|
|
14
|
-
prefix?: boolean;
|
|
15
|
-
}
|
|
16
8
|
export declare class CommandBuilder {
|
|
9
|
+
#private;
|
|
10
|
+
readonly data: ApplicationCommandBuilder;
|
|
17
11
|
readonly client: Client;
|
|
18
12
|
readonly logger: Logger;
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly description: string;
|
|
21
|
-
readonly aliases: string[];
|
|
22
|
-
readonly options: ApplicationCommandOptionData[];
|
|
23
|
-
private _supportsSlash;
|
|
24
|
-
private _supportsPrefix;
|
|
25
13
|
_onMessage?: (ctx: MessageContext) => MaybePromise<void>;
|
|
26
14
|
_onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
|
|
27
15
|
get supportsSlash(): false | ((ctx: InteractionContext) => MaybePromise<void>) | undefined;
|
|
28
16
|
get supportsPrefix(): false | ((ctx: MessageContext) => MaybePromise<void>) | undefined;
|
|
29
|
-
constructor(
|
|
17
|
+
constructor(data: ApplicationCommandBuilder);
|
|
30
18
|
onMessage(func: (ctx: MessageContext) => MaybePromise<void>): this;
|
|
31
19
|
onInteraction(func: (ctx: InteractionContext) => MaybePromise<void>): this;
|
|
32
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Message, User, ChatInputCommandInteraction, Locale } from "discord.js";
|
|
2
|
-
import { Client } from "
|
|
2
|
+
import { Client } from "../index";
|
|
3
|
+
import { TOptions } from "i18next";
|
|
3
4
|
type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends ChatInputCommandInteraction ? {
|
|
4
5
|
interaction: T;
|
|
5
6
|
args?: string[];
|
|
@@ -16,7 +17,9 @@ export declare class Context<T extends ChatInputCommandInteraction | Message> {
|
|
|
16
17
|
isInteraction(): this is Context<ChatInputCommandInteraction>;
|
|
17
18
|
isMessage(): this is Context<Message>;
|
|
18
19
|
get author(): User | null;
|
|
19
|
-
t(key: string,
|
|
20
|
+
t(key: string, options?: TOptions & {
|
|
21
|
+
defaultValue?: string;
|
|
22
|
+
}): string;
|
|
20
23
|
toJSON(): {
|
|
21
24
|
kind: "interaction";
|
|
22
25
|
interaction: T;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { ClientEvents } from "discord.js";
|
|
2
2
|
import { MaybePromise } from "#types/extra.js";
|
|
3
|
-
import { Client } from "
|
|
4
|
-
import { Logger } from "
|
|
3
|
+
import { Client } from "../index";
|
|
4
|
+
import { Logger } from "../../utils/index";
|
|
5
5
|
type EventArgs<K extends keyof ClientEvents> = ClientEvents[K];
|
|
6
6
|
type EventHandler<K extends keyof ClientEvents> = (context: EventBuilder<K>, ...args: EventArgs<K>) => MaybePromise<void>;
|
|
7
7
|
export declare class EventBuilder<K extends keyof ClientEvents> {
|
|
8
|
+
#private;
|
|
8
9
|
readonly name: K;
|
|
9
10
|
readonly once: boolean;
|
|
10
11
|
readonly client: Client;
|
|
11
12
|
readonly logger: Logger;
|
|
12
|
-
private handler?;
|
|
13
|
-
private bound;
|
|
14
|
-
private readonly listener;
|
|
15
13
|
constructor(name: K, once?: boolean, _handler?: EventHandler<K>);
|
|
16
|
-
private register;
|
|
17
14
|
onExecute(func: EventHandler<K>): this;
|
|
18
15
|
}
|
|
19
16
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js";
|
|
2
|
-
import { CommandBuilder } from "
|
|
3
|
-
import { Logger } from "
|
|
2
|
+
import { CommandBuilder } from "../index";
|
|
3
|
+
import { Logger } from "../../utils";
|
|
4
4
|
import { FrameworkOptions } from "#types/client.js";
|
|
5
5
|
import { i18n } from "i18next";
|
|
6
6
|
export declare class Client<Ready extends boolean = boolean> extends DiscordClient<Ready> {
|
|
7
|
+
#private;
|
|
7
8
|
readonly logger: Logger;
|
|
8
9
|
commands: Collection<string, CommandBuilder>;
|
|
9
10
|
aliases: Collection<string, Set<string>>;
|
|
@@ -14,7 +15,5 @@ export declare class Client<Ready extends boolean = boolean> extends DiscordClie
|
|
|
14
15
|
};
|
|
15
16
|
constructor(opts: FrameworkOptions);
|
|
16
17
|
login(token?: string): Promise<string>;
|
|
17
|
-
loadDir(dir: string): Promise<void>;
|
|
18
|
-
loadFile(file: string): Promise<void>;
|
|
19
18
|
registerCommands(): Promise<void>;
|
|
20
19
|
}
|
|
@@ -4,6 +4,7 @@ import { Timestamp } from "@sapphire/timestamp";
|
|
|
4
4
|
import type { ILogger } from "./ILogger";
|
|
5
5
|
import { LogLevel } from "./ILogger";
|
|
6
6
|
import { LoggerModule } from "i18next";
|
|
7
|
+
export { LogLevel } from "./ILogger";
|
|
7
8
|
export declare class Logger implements ILogger {
|
|
8
9
|
level: LogLevel;
|
|
9
10
|
readonly formats: Map<LogLevel, LoggerLevel>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes data that is a rest parameter or an array into an array with a depth of 1.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam ItemType - The data that must satisfy {@link RestOrArray}.
|
|
5
|
+
* @param arr - The (possibly variadic) data to normalize
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[];
|
|
8
|
+
/**
|
|
9
|
+
* Represents data that may be an array or came from a rest parameter.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This type is used throughout builders to ensure both an array and variadic arguments
|
|
13
|
+
* may be used. It is normalized with {@link normalizeArray}.
|
|
14
|
+
*/
|
|
15
|
+
export type RestOrArray<Type> = Type[] | [Type[]];
|
package/package.json
CHANGED
|
@@ -1,62 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@arox/framework",
|
|
3
|
-
"version": "0.1.1",
|
|
4
|
-
"description": "",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"discord.js",
|
|
7
|
-
"framework"
|
|
8
|
-
],
|
|
9
|
-
"homepage": "https://github.com/AroxBot/framework#readme",
|
|
10
|
-
"bugs": {
|
|
11
|
-
"url": "https://github.com/AroxBot/framework/issues"
|
|
12
|
-
},
|
|
13
|
-
"license": "Apache-2.0",
|
|
14
|
-
"author": "vrdons",
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/AroxBot/framework.git"
|
|
18
|
-
},
|
|
19
|
-
"type": "commonjs",
|
|
20
|
-
"main": "dist/index.js",
|
|
21
|
-
"types": "dist/index.d.ts",
|
|
22
|
-
"imports": {
|
|
23
|
-
"#types/*": "./types/*",
|
|
24
|
-
"#utils": "./src/utils/index.ts",
|
|
25
|
-
"#structures": "./src/structures/index.ts",
|
|
26
|
-
"#ctx": "./src/context.ts"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"prepare": "node scripts/prepareHusky.js",
|
|
30
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
31
|
-
"check": "oxfmt --check && oxlint --type-aware --type-check",
|
|
32
|
-
"format": "oxfmt",
|
|
33
|
-
"build:js": "swc src -d dist --strip-leading-paths --copy-files",
|
|
34
|
-
"build:dts": "tsc --emitDeclarationOnly",
|
|
35
|
-
"build": "npm run build:js && node ./scripts/actions/patch.js && npm run build:dts",
|
|
36
|
-
"release:git": "node scripts/actions/github.js",
|
|
37
|
-
"release:npm": "node scripts/actions/npm.js"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@sapphire/timestamp": "^1.0.5",
|
|
41
|
-
"@swc/helpers": "^0.5.18",
|
|
42
|
-
"colorette": "^2.0.20",
|
|
43
|
-
"fast-glob": "^3.3.3",
|
|
44
|
-
"i18next": "^25.8.0",
|
|
45
|
-
"i18next-fs-backend": "^2.6.1",
|
|
46
|
-
"lodash": "^4.17.21"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@swc/cli": "^0.7.10",
|
|
50
|
-
"@types/lodash": "^4.17.23",
|
|
51
|
-
"@types/node": "^25.0.9",
|
|
52
|
-
"husky": "^9.1.7",
|
|
53
|
-
"libnpmpack": "^9.0.12",
|
|
54
|
-
"oxfmt": "^0.26.0",
|
|
55
|
-
"oxlint": "^1.39.0",
|
|
56
|
-
"oxlint-tsgolint": "^0.11.0",
|
|
57
|
-
"typescript": "^5.9.3"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"discord.js": ">=14.25.1"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
{"name":"@arox/framework","version":"0.1.2-beta.1","description":"","keywords":["arox","discord.js","framework"],"homepage":"https://github.com/AroxBot/framework#readme","bugs":{"url":"https://github.com/AroxBot/framework/issues"},"license":"Apache-2.0","author":"vrdons","contributors":["fhyrox"],"repository":{"type":"git","url":"git+https://github.com/AroxBot/framework.git"},"type":"commonjs","main":"dist/index.js","types":"dist/index.d.ts","imports":{"#types/*":"./types/*"},"dependencies":{"@sapphire/timestamp":"^1.0.5","colorette":"^2.0.20","fast-glob":"^3.3.3","i18next":"^25.8.0"},"peerDependencies":{"discord.js":">=14.25.1"}}
|
package/cliff.toml
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
[changelog]
|
|
2
|
-
header = """
|
|
3
|
-
# Changelog\n
|
|
4
|
-
All notable changes to this project will be documented in this file.\n
|
|
5
|
-
"""
|
|
6
|
-
body = """
|
|
7
|
-
{% if version %}
|
|
8
|
-
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}\
|
|
9
|
-
{% else %}\
|
|
10
|
-
## Unreleased\
|
|
11
|
-
{% endif %}
|
|
12
|
-
|
|
13
|
-
{% for group, commits in commits | group_by(attribute="group") %}\
|
|
14
|
-
### {{ group | upper_first }}
|
|
15
|
-
{% for commit in commits %}
|
|
16
|
-
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }} {% if commit.author.username %}by [@{{ commit.author.username }}](https://github.com/{{ commit.author.username }}){% else %}by {{ commit.author.name }}{% endif %} {% if commit.url %}([{{ commit.id | truncate(length=7, end="") }}]({{ commit.url }})){% else %}({{ commit.id | truncate(length=7, end="") }}){% endif %}\
|
|
17
|
-
{% endfor %}\n
|
|
18
|
-
{% endfor %}
|
|
19
|
-
"""
|
|
20
|
-
trim = true
|
|
21
|
-
footer = """
|
|
22
|
-
<!-- generated by git-cliff -->
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
[git]
|
|
26
|
-
conventional_commits = true
|
|
27
|
-
filter_unconventional = true
|
|
28
|
-
split_commits = false
|
|
29
|
-
commit_preprocessors = [
|
|
30
|
-
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/vrdons/zKitap2Pdf/pull/${2}))" },
|
|
31
|
-
]
|
|
32
|
-
commit_parsers = [
|
|
33
|
-
{ message = "^feat", group = "Features" },
|
|
34
|
-
{ message = "^fix", group = "Bug Fixes" },
|
|
35
|
-
{ message = "^doc", group = "Documentation" },
|
|
36
|
-
{ message = "^perf", group = "Performance" },
|
|
37
|
-
{ message = "^refactor", group = "Refactor" },
|
|
38
|
-
{ message = "^style", group = "Styling" },
|
|
39
|
-
{ message = "^test", group = "Testing" },
|
|
40
|
-
{ message = "^chore\\(release\\): prepare for", skip = true },
|
|
41
|
-
{ message = "^chore", group = "Miscellaneous Tasks" },
|
|
42
|
-
{ body = ".*security", group = "Security" },
|
|
43
|
-
|
|
44
|
-
{ message = "^deps|^build", group = "Dependencies" },
|
|
45
|
-
{ message = "^Merge pull request", group = "Pull Requests" },
|
|
46
|
-
{ message = "^Merge branch", group = "Merges" },
|
|
47
|
-
{ message = "^Revert", group = "Reverts" },
|
|
48
|
-
]
|
package/dist/context.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get clearClient () {
|
|
13
|
-
return clearClient;
|
|
14
|
-
},
|
|
15
|
-
get currentClient () {
|
|
16
|
-
return currentClient;
|
|
17
|
-
},
|
|
18
|
-
get setClient () {
|
|
19
|
-
return setClient;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
let currentClient = null;
|
|
23
|
-
function setClient(client) {
|
|
24
|
-
currentClient = client;
|
|
25
|
-
}
|
|
26
|
-
function clearClient() {
|
|
27
|
-
currentClient = null;
|
|
28
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _discord = require("discord.js");
|
|
6
|
-
const _structures = require("#structures");
|
|
7
|
-
new _structures.EventBuilder(_discord.Events.InteractionCreate, false).onExecute(async function(context, interaction) {
|
|
8
|
-
if (!interaction.isChatInputCommand()) return;
|
|
9
|
-
const command = context.client.commands.get(interaction.commandName);
|
|
10
|
-
if (!command || !command.supportsSlash) {
|
|
11
|
-
await interaction.reply({
|
|
12
|
-
content: "Command not found or disabled.",
|
|
13
|
-
flags: _discord.MessageFlags.Ephemeral
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const ctx = new _structures.Context(context.client, {
|
|
19
|
-
interaction
|
|
20
|
-
});
|
|
21
|
-
ctx.locale = interaction.locale;
|
|
22
|
-
context.logger.debug(`${ctx.author?.tag ?? "Unknown"} used ${command.name}(interaction)`);
|
|
23
|
-
if (command._onInteraction) await command._onInteraction(ctx.toJSON());
|
|
24
|
-
} catch (error) {
|
|
25
|
-
context.client.logger.error(`Error executing command ${command.name}:`, error);
|
|
26
|
-
if (interaction.replied || interaction.deferred) {
|
|
27
|
-
await interaction.followUp({
|
|
28
|
-
content: "There was an error while executing this command!",
|
|
29
|
-
flags: _discord.MessageFlags.Ephemeral
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
await interaction.reply({
|
|
33
|
-
content: "There was an error while executing this command!",
|
|
34
|
-
flags: _discord.MessageFlags.Ephemeral
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
package/dist/events/message.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _discord = require("discord.js");
|
|
6
|
-
const _structures = require("#structures");
|
|
7
|
-
const _utils = require("#utils");
|
|
8
|
-
new _structures.EventBuilder(_discord.Events.MessageCreate, false, async function(context, message) {
|
|
9
|
-
if (message.author.bot) return;
|
|
10
|
-
const prefix = context.client.prefix;
|
|
11
|
-
if (typeof prefix !== "string" || prefix.length === 0 || !message.content.startsWith(prefix)) return;
|
|
12
|
-
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
|
13
|
-
const commandName = args.shift()?.toLowerCase();
|
|
14
|
-
if (!commandName) return;
|
|
15
|
-
const commandAlias = context.client.aliases.findKey((cmd)=>cmd.has(commandName));
|
|
16
|
-
let command = context.client.commands.get(commandAlias ?? commandName);
|
|
17
|
-
if (!command || !command.supportsPrefix) {
|
|
18
|
-
await message.reply({
|
|
19
|
-
content: "Command not found or disabled.",
|
|
20
|
-
allowedMentions: {
|
|
21
|
-
repliedUser: false
|
|
22
|
-
}
|
|
23
|
-
}).then(_utils.deleteMessageAfterSent);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const ctx = new _structures.Context(context.client, {
|
|
28
|
-
message,
|
|
29
|
-
args
|
|
30
|
-
});
|
|
31
|
-
context.logger.debug(`${ctx.author?.tag ?? "Unknown"} used ${command.name}(message)`);
|
|
32
|
-
if (command._onMessage) await command._onMessage(ctx.toJSON());
|
|
33
|
-
} catch (error) {
|
|
34
|
-
context.client.logger.error(`Error executing command ${command.name}:`, error);
|
|
35
|
-
}
|
|
36
|
-
});
|
package/dist/events/ready.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _discord = require("discord.js");
|
|
6
|
-
const _structures = require("#structures");
|
|
7
|
-
new _structures.EventBuilder(_discord.Events.ClientReady).onExecute(async function(context) {
|
|
8
|
-
if (context.client.options.autoRegisterCommands) {
|
|
9
|
-
await context.client.registerCommands();
|
|
10
|
-
}
|
|
11
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ApplicationCommandOptionData, ApplicationCommandOptionType } from "discord.js";
|
|
2
|
-
export declare class Argument {
|
|
3
|
-
readonly name: string;
|
|
4
|
-
readonly description: string;
|
|
5
|
-
readonly type: ApplicationCommandOptionType;
|
|
6
|
-
readonly required: boolean;
|
|
7
|
-
readonly choices?: {
|
|
8
|
-
name: string;
|
|
9
|
-
value: string | number;
|
|
10
|
-
}[];
|
|
11
|
-
constructor(data: {
|
|
12
|
-
name: string;
|
|
13
|
-
description: string;
|
|
14
|
-
type: ApplicationCommandOptionType;
|
|
15
|
-
required?: boolean;
|
|
16
|
-
choices?: {
|
|
17
|
-
name: string;
|
|
18
|
-
value: string | number;
|
|
19
|
-
}[];
|
|
20
|
-
});
|
|
21
|
-
toJSON(): ApplicationCommandOptionData;
|
|
22
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Argument", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Argument;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _discord = require("discord.js");
|
|
12
|
-
class Argument {
|
|
13
|
-
name;
|
|
14
|
-
description;
|
|
15
|
-
type;
|
|
16
|
-
required;
|
|
17
|
-
choices;
|
|
18
|
-
constructor(data){
|
|
19
|
-
this.name = data.name;
|
|
20
|
-
this.description = data.description;
|
|
21
|
-
this.type = data.type;
|
|
22
|
-
this.required = data.required ?? false;
|
|
23
|
-
this.choices = data.choices;
|
|
24
|
-
}
|
|
25
|
-
toJSON() {
|
|
26
|
-
const choicesAllowedTypes = [
|
|
27
|
-
_discord.ApplicationCommandOptionType.String,
|
|
28
|
-
_discord.ApplicationCommandOptionType.Integer,
|
|
29
|
-
_discord.ApplicationCommandOptionType.Number
|
|
30
|
-
];
|
|
31
|
-
if (this.choices && !choicesAllowedTypes.includes(this.type)) {
|
|
32
|
-
throw new Error(`Choices are not allowed for option type ${_discord.ApplicationCommandOptionType[this.type]} (${this.type})`);
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
name: this.name,
|
|
36
|
-
description: this.description,
|
|
37
|
-
type: this.type,
|
|
38
|
-
required: this.required,
|
|
39
|
-
choices: this.choices
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "CommandBuilder", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return CommandBuilder;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _Argument = require("./Argument");
|
|
12
|
-
const _ctx = require("#ctx");
|
|
13
|
-
class CommandBuilder {
|
|
14
|
-
client;
|
|
15
|
-
logger;
|
|
16
|
-
name;
|
|
17
|
-
description;
|
|
18
|
-
aliases;
|
|
19
|
-
options;
|
|
20
|
-
_supportsSlash;
|
|
21
|
-
_supportsPrefix;
|
|
22
|
-
_onMessage;
|
|
23
|
-
_onInteraction;
|
|
24
|
-
get supportsSlash() {
|
|
25
|
-
return this._supportsSlash && this._onInteraction;
|
|
26
|
-
}
|
|
27
|
-
get supportsPrefix() {
|
|
28
|
-
return this._supportsPrefix && this._onMessage;
|
|
29
|
-
}
|
|
30
|
-
constructor(options){
|
|
31
|
-
const client = _ctx.currentClient;
|
|
32
|
-
if (!client) throw new Error("Client is not defined");
|
|
33
|
-
this.client = client;
|
|
34
|
-
this.logger = client.logger;
|
|
35
|
-
this.name = options.name;
|
|
36
|
-
this.description = options.description;
|
|
37
|
-
this.aliases = options.aliases ?? [];
|
|
38
|
-
this.options = (options.options ?? []).map((opt)=>{
|
|
39
|
-
return opt instanceof _Argument.Argument ? opt.toJSON() : opt;
|
|
40
|
-
});
|
|
41
|
-
this._supportsPrefix = options.prefix ?? false;
|
|
42
|
-
this._supportsSlash = options.slash ?? false;
|
|
43
|
-
if (!this._supportsPrefix && !this._supportsSlash) {
|
|
44
|
-
throw new Error(`Command ${this.name} must support either slash or prefix commands.`);
|
|
45
|
-
}
|
|
46
|
-
if (this.client.commands.has(this.name)) throw new Error(`Command name "${this.name}" is already registered.`);
|
|
47
|
-
const existingAliasOwner = this.client.aliases.findKey((aliases)=>aliases.has(this.name));
|
|
48
|
-
if (existingAliasOwner) {
|
|
49
|
-
throw new Error(`Command name "${this.name}" is already registered as an alias for command "${existingAliasOwner}".`);
|
|
50
|
-
}
|
|
51
|
-
for (const alias of this.aliases){
|
|
52
|
-
if (this.client.commands.has(alias)) {
|
|
53
|
-
throw new Error(`Alias "${alias}" is already registered as a command name.`);
|
|
54
|
-
}
|
|
55
|
-
const conflictingCommand = this.client.aliases.findKey((aliases)=>aliases.has(alias));
|
|
56
|
-
if (conflictingCommand) {
|
|
57
|
-
throw new Error(`Alias "${alias}" is already registered as an alias for command "${conflictingCommand}".`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
this.client.commands.set(this.name, this);
|
|
61
|
-
if (this.aliases.length > 0) {
|
|
62
|
-
this.client.aliases.set(this.name, new Set(this.aliases));
|
|
63
|
-
}
|
|
64
|
-
this.logger.debug(`Loaded Command ${this.name}`);
|
|
65
|
-
}
|
|
66
|
-
onMessage(func) {
|
|
67
|
-
this._onMessage = func;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
onInteraction(func) {
|
|
71
|
-
this._onInteraction = func;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Context", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Context;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _discord = require("discord.js");
|
|
12
|
-
class Context {
|
|
13
|
-
client;
|
|
14
|
-
args;
|
|
15
|
-
data;
|
|
16
|
-
locale;
|
|
17
|
-
constructor(client, payload){
|
|
18
|
-
this.client = client;
|
|
19
|
-
this.args = payload.args ?? [];
|
|
20
|
-
if ("interaction" in payload) {
|
|
21
|
-
this.data = payload.interaction;
|
|
22
|
-
} else {
|
|
23
|
-
this.data = payload.message;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
isInteraction() {
|
|
27
|
-
return this.data instanceof _discord.ChatInputCommandInteraction;
|
|
28
|
-
}
|
|
29
|
-
isMessage() {
|
|
30
|
-
return this.data instanceof _discord.Message;
|
|
31
|
-
}
|
|
32
|
-
get author() {
|
|
33
|
-
if (this.isInteraction()) {
|
|
34
|
-
return this.data.user;
|
|
35
|
-
}
|
|
36
|
-
if (this.isMessage()) {
|
|
37
|
-
return this.data.author;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
t(key, args) {
|
|
42
|
-
if (!this.client.i18n) {
|
|
43
|
-
throw new Error("i18n is not initialized");
|
|
44
|
-
}
|
|
45
|
-
let locale = this.locale ?? (Array.isArray(this.client.i18n.options.fallbackLng) ? this.client.i18n.options.fallbackLng[0] : this.client.i18n.options.fallbackLng) ?? "en";
|
|
46
|
-
const t = this.client.i18n.getFixedT(locale);
|
|
47
|
-
return t(key, args);
|
|
48
|
-
}
|
|
49
|
-
toJSON() {
|
|
50
|
-
const { data, args, author } = this;
|
|
51
|
-
if (this.isInteraction()) {
|
|
52
|
-
return {
|
|
53
|
-
kind: "interaction",
|
|
54
|
-
interaction: data,
|
|
55
|
-
author,
|
|
56
|
-
t: this.t.bind(this)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
kind: "message",
|
|
61
|
-
message: data,
|
|
62
|
-
args,
|
|
63
|
-
author,
|
|
64
|
-
t: this.t.bind(this)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "EventBuilder", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return EventBuilder;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _ctx = require("#ctx");
|
|
12
|
-
class EventBuilder {
|
|
13
|
-
name;
|
|
14
|
-
once;
|
|
15
|
-
client;
|
|
16
|
-
logger;
|
|
17
|
-
handler;
|
|
18
|
-
bound = false;
|
|
19
|
-
listener = async (...args)=>{
|
|
20
|
-
if (!this.handler) return;
|
|
21
|
-
try {
|
|
22
|
-
await this.handler(this, ...args);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
this.client.logger.error(`Error executing event ${this.name} (${this.constructor.name}):`, error);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
constructor(name, once = false, _handler){
|
|
28
|
-
this.name = name;
|
|
29
|
-
this.once = once;
|
|
30
|
-
if (!_ctx.currentClient) throw new Error("Client is not defined");
|
|
31
|
-
this.client = _ctx.currentClient;
|
|
32
|
-
this.logger = _ctx.currentClient.logger;
|
|
33
|
-
if (_handler) {
|
|
34
|
-
this.handler = _handler;
|
|
35
|
-
this.register();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
register() {
|
|
39
|
-
if (this.bound || !this.handler) return;
|
|
40
|
-
if (this.once) {
|
|
41
|
-
this.client.once(this.name, this.listener);
|
|
42
|
-
} else {
|
|
43
|
-
this.client.on(this.name, this.listener);
|
|
44
|
-
}
|
|
45
|
-
this.bound = true;
|
|
46
|
-
this.logger.debug(`Loaded Event ${String(this.name)}`);
|
|
47
|
-
}
|
|
48
|
-
onExecute(func) {
|
|
49
|
-
this.handler = func;
|
|
50
|
-
this.register();
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _export_star = require("@swc/helpers/_/_export_star");
|
|
6
|
-
_export_star._(require("./Argument"), exports);
|
|
7
|
-
_export_star._(require("./Command"), exports);
|
|
8
|
-
_export_star._(require("./Context"), exports);
|
|
9
|
-
_export_star._(require("./Event"), exports);
|