@arox/framework 0.1.0 → 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/context.d.ts +1 -1
- package/dist/events/interaction.js +8 -7
- package/dist/events/message.js +5 -6
- package/dist/events/ready.js +2 -2
- package/dist/index.d.ts +2 -6
- package/dist/index.js +3 -7
- package/dist/structures/{Argument.js → builder/Argument.js} +9 -0
- package/dist/structures/builder/Command.d.ts +33 -0
- package/dist/structures/{Command.js → builder/Command.js} +2 -2
- package/dist/structures/{Context.d.ts → builder/Context.d.ts} +6 -2
- package/dist/structures/{Context.js → builder/Context.js} +14 -3
- package/dist/structures/{Event.d.ts → builder/Event.d.ts} +2 -2
- package/dist/structures/{Event.js → builder/Event.js} +5 -5
- package/dist/structures/builder/index.d.ts +4 -0
- package/dist/structures/builder/index.js +9 -0
- package/dist/structures/{Client.d.ts → core/Client.d.ts} +6 -3
- package/dist/structures/{Client.js → core/Client.js} +32 -20
- package/dist/structures/core/index.d.ts +1 -0
- package/dist/structures/core/index.js +6 -0
- package/dist/structures/index.d.ts +2 -0
- package/dist/structures/index.js +7 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/logger/Logger.d.ts +9 -0
- package/dist/utils/logger/Logger.js +19 -0
- package/dist/utils/util.d.ts +1 -1
- package/dist/utils/util.js +3 -3
- package/package.json +9 -4
- package/types/client.d.ts +4 -1
- package/dist/structures/Command.d.ts +0 -31
- /package/dist/structures/{Argument.d.ts → builder/Argument.d.ts} +0 -0
package/dist/context.d.ts
CHANGED
|
@@ -3,34 +3,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _discord = require("discord.js");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
new _Event.EventBuilder(_discord.Events.InteractionCreate, false).onExecute(async function(context, interaction) {
|
|
6
|
+
const _structures = require("#structures");
|
|
7
|
+
new _structures.EventBuilder(_discord.Events.InteractionCreate, false).onExecute(async function(context, interaction) {
|
|
9
8
|
if (!interaction.isChatInputCommand()) return;
|
|
10
9
|
const command = context.client.commands.get(interaction.commandName);
|
|
11
10
|
if (!command || !command.supportsSlash) {
|
|
12
11
|
await interaction.reply({
|
|
13
12
|
content: "Command not found or disabled.",
|
|
14
|
-
|
|
13
|
+
flags: _discord.MessageFlags.Ephemeral
|
|
15
14
|
});
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
try {
|
|
19
|
-
const ctx = new
|
|
18
|
+
const ctx = new _structures.Context(context.client, {
|
|
20
19
|
interaction
|
|
21
20
|
});
|
|
21
|
+
ctx.locale = interaction.locale;
|
|
22
|
+
context.logger.debug(`${ctx.author?.tag ?? "Unknown"} used ${command.name}(interaction)`);
|
|
22
23
|
if (command._onInteraction) await command._onInteraction(ctx.toJSON());
|
|
23
24
|
} catch (error) {
|
|
24
25
|
context.client.logger.error(`Error executing command ${command.name}:`, error);
|
|
25
26
|
if (interaction.replied || interaction.deferred) {
|
|
26
27
|
await interaction.followUp({
|
|
27
28
|
content: "There was an error while executing this command!",
|
|
28
|
-
|
|
29
|
+
flags: _discord.MessageFlags.Ephemeral
|
|
29
30
|
});
|
|
30
31
|
} else {
|
|
31
32
|
await interaction.reply({
|
|
32
33
|
content: "There was an error while executing this command!",
|
|
33
|
-
|
|
34
|
+
flags: _discord.MessageFlags.Ephemeral
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
}
|
package/dist/events/message.js
CHANGED
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _discord = require("discord.js");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
new _Event.EventBuilder(_discord.Events.MessageCreate, false, async function(context, message) {
|
|
6
|
+
const _structures = require("#structures");
|
|
7
|
+
const _utils = require("#utils");
|
|
8
|
+
new _structures.EventBuilder(_discord.Events.MessageCreate, false, async function(context, message) {
|
|
10
9
|
if (message.author.bot) return;
|
|
11
10
|
const prefix = context.client.prefix;
|
|
12
11
|
if (typeof prefix !== "string" || prefix.length === 0 || !message.content.startsWith(prefix)) return;
|
|
@@ -21,11 +20,11 @@ new _Event.EventBuilder(_discord.Events.MessageCreate, false, async function(con
|
|
|
21
20
|
allowedMentions: {
|
|
22
21
|
repliedUser: false
|
|
23
22
|
}
|
|
24
|
-
}).then(
|
|
23
|
+
}).then(_utils.deleteMessageAfterSent);
|
|
25
24
|
return;
|
|
26
25
|
}
|
|
27
26
|
try {
|
|
28
|
-
const ctx = new
|
|
27
|
+
const ctx = new _structures.Context(context.client, {
|
|
29
28
|
message,
|
|
30
29
|
args
|
|
31
30
|
});
|
package/dist/events/ready.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _discord = require("discord.js");
|
|
6
|
-
const
|
|
7
|
-
new
|
|
6
|
+
const _structures = require("#structures");
|
|
7
|
+
new _structures.EventBuilder(_discord.Events.ClientReady).onExecute(async function(context) {
|
|
8
8
|
if (context.client.options.autoRegisterCommands) {
|
|
9
9
|
await context.client.registerCommands();
|
|
10
10
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./structures/Command";
|
|
3
|
-
export * from "./structures/Context";
|
|
4
|
-
export * from "./structures/Event";
|
|
5
|
-
export * from "./structures/Argument";
|
|
1
|
+
export * from "#structures";
|
|
6
2
|
export * from "./utils/logger/Logger";
|
|
7
|
-
export * from "
|
|
3
|
+
export * from "#ctx";
|
|
8
4
|
export declare const version = "[VI]{{version}}[/VI]";
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,7 @@ Object.defineProperty(exports, "version", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _export_star = require("@swc/helpers/_/_export_star");
|
|
12
|
-
_export_star._(require("
|
|
13
|
-
_export_star._(require("./structures/Command"), exports);
|
|
14
|
-
_export_star._(require("./structures/Context"), exports);
|
|
15
|
-
_export_star._(require("./structures/Event"), exports);
|
|
16
|
-
_export_star._(require("./structures/Argument"), exports);
|
|
12
|
+
_export_star._(require("#structures"), exports);
|
|
17
13
|
_export_star._(require("./utils/logger/Logger"), exports);
|
|
18
|
-
_export_star._(require("
|
|
19
|
-
const version = "v0.1.
|
|
14
|
+
_export_star._(require("#ctx"), exports);
|
|
15
|
+
const version = "v0.1.1";
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "Argument", {
|
|
|
8
8
|
return Argument;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _discord = require("discord.js");
|
|
11
12
|
class Argument {
|
|
12
13
|
name;
|
|
13
14
|
description;
|
|
@@ -22,6 +23,14 @@ class Argument {
|
|
|
22
23
|
this.choices = data.choices;
|
|
23
24
|
}
|
|
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
|
+
}
|
|
25
34
|
return {
|
|
26
35
|
name: this.name,
|
|
27
36
|
description: this.description,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ApplicationCommandOptionData, ChatInputCommandInteraction, Message } from "discord.js";
|
|
2
|
+
import { Context, Client } from "#structures";
|
|
3
|
+
import { Argument } from "./Argument";
|
|
4
|
+
import { MaybePromise } from "#types/extra.js";
|
|
5
|
+
import { Logger } from "#utils";
|
|
6
|
+
type MessageContext = NonNullable<ReturnType<Context<Message>["toJSON"]>>;
|
|
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
|
+
export declare class CommandBuilder {
|
|
17
|
+
readonly client: Client;
|
|
18
|
+
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
|
+
_onMessage?: (ctx: MessageContext) => MaybePromise<void>;
|
|
26
|
+
_onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
|
|
27
|
+
get supportsSlash(): false | ((ctx: InteractionContext) => MaybePromise<void>) | undefined;
|
|
28
|
+
get supportsPrefix(): false | ((ctx: MessageContext) => MaybePromise<void>) | undefined;
|
|
29
|
+
constructor(options: CommandOptions);
|
|
30
|
+
onMessage(func: (ctx: MessageContext) => MaybePromise<void>): this;
|
|
31
|
+
onInteraction(func: (ctx: InteractionContext) => MaybePromise<void>): this;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "CommandBuilder", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _Argument = require("./Argument");
|
|
12
|
-
const
|
|
12
|
+
const _ctx = require("#ctx");
|
|
13
13
|
class CommandBuilder {
|
|
14
14
|
client;
|
|
15
15
|
logger;
|
|
@@ -28,7 +28,7 @@ class CommandBuilder {
|
|
|
28
28
|
return this._supportsPrefix && this._onMessage;
|
|
29
29
|
}
|
|
30
30
|
constructor(options){
|
|
31
|
-
const client =
|
|
31
|
+
const client = _ctx.currentClient;
|
|
32
32
|
if (!client) throw new Error("Client is not defined");
|
|
33
33
|
this.client = client;
|
|
34
34
|
this.logger = client.logger;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message, User, ChatInputCommandInteraction } from "discord.js";
|
|
2
|
-
import { Client } from "
|
|
1
|
+
import { Message, User, ChatInputCommandInteraction, Locale } from "discord.js";
|
|
2
|
+
import { Client } from "#structures";
|
|
3
3
|
type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends ChatInputCommandInteraction ? {
|
|
4
4
|
interaction: T;
|
|
5
5
|
args?: string[];
|
|
@@ -11,14 +11,17 @@ export declare class Context<T extends ChatInputCommandInteraction | Message> {
|
|
|
11
11
|
readonly client: Client;
|
|
12
12
|
readonly args: string[];
|
|
13
13
|
readonly data: T;
|
|
14
|
+
locale?: `${Locale}`;
|
|
14
15
|
constructor(client: Client, payload: ContextPayload<T>);
|
|
15
16
|
isInteraction(): this is Context<ChatInputCommandInteraction>;
|
|
16
17
|
isMessage(): this is Context<Message>;
|
|
17
18
|
get author(): User | null;
|
|
19
|
+
t(key: string, args?: Record<string, any>): string;
|
|
18
20
|
toJSON(): {
|
|
19
21
|
kind: "interaction";
|
|
20
22
|
interaction: T;
|
|
21
23
|
author: User | null;
|
|
24
|
+
t: any;
|
|
22
25
|
message?: undefined;
|
|
23
26
|
args?: undefined;
|
|
24
27
|
} | {
|
|
@@ -26,6 +29,7 @@ export declare class Context<T extends ChatInputCommandInteraction | Message> {
|
|
|
26
29
|
message: Message;
|
|
27
30
|
args: string[];
|
|
28
31
|
author: User | null;
|
|
32
|
+
t: any;
|
|
29
33
|
interaction?: undefined;
|
|
30
34
|
};
|
|
31
35
|
}
|
|
@@ -13,6 +13,7 @@ class Context {
|
|
|
13
13
|
client;
|
|
14
14
|
args;
|
|
15
15
|
data;
|
|
16
|
+
locale;
|
|
16
17
|
constructor(client, payload){
|
|
17
18
|
this.client = client;
|
|
18
19
|
this.args = payload.args ?? [];
|
|
@@ -37,20 +38,30 @@ class Context {
|
|
|
37
38
|
}
|
|
38
39
|
return null;
|
|
39
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
|
+
}
|
|
40
49
|
toJSON() {
|
|
41
50
|
const { data, args, author } = this;
|
|
42
51
|
if (this.isInteraction()) {
|
|
43
52
|
return {
|
|
44
53
|
kind: "interaction",
|
|
45
54
|
interaction: data,
|
|
46
|
-
author
|
|
55
|
+
author,
|
|
56
|
+
t: this.t.bind(this)
|
|
47
57
|
};
|
|
48
58
|
}
|
|
49
59
|
return {
|
|
50
60
|
kind: "message",
|
|
51
61
|
message: data,
|
|
52
|
-
args
|
|
53
|
-
author
|
|
62
|
+
args,
|
|
63
|
+
author,
|
|
64
|
+
t: this.t.bind(this)
|
|
54
65
|
};
|
|
55
66
|
}
|
|
56
67
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
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 "#structures";
|
|
4
|
+
import { Logger } from "#utils";
|
|
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,7 +8,7 @@ Object.defineProperty(exports, "EventBuilder", {
|
|
|
8
8
|
return EventBuilder;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _ctx = require("#ctx");
|
|
12
12
|
class EventBuilder {
|
|
13
13
|
name;
|
|
14
14
|
once;
|
|
@@ -27,14 +27,13 @@ class EventBuilder {
|
|
|
27
27
|
constructor(name, once = false, _handler){
|
|
28
28
|
this.name = name;
|
|
29
29
|
this.once = once;
|
|
30
|
-
if (!
|
|
31
|
-
this.client =
|
|
32
|
-
this.logger =
|
|
30
|
+
if (!_ctx.currentClient) throw new Error("Client is not defined");
|
|
31
|
+
this.client = _ctx.currentClient;
|
|
32
|
+
this.logger = _ctx.currentClient.logger;
|
|
33
33
|
if (_handler) {
|
|
34
34
|
this.handler = _handler;
|
|
35
35
|
this.register();
|
|
36
36
|
}
|
|
37
|
-
this.logger.debug(`Loaded Event ${String(this.name)}`);
|
|
38
37
|
}
|
|
39
38
|
register() {
|
|
40
39
|
if (this.bound || !this.handler) return;
|
|
@@ -44,6 +43,7 @@ class EventBuilder {
|
|
|
44
43
|
this.client.on(this.name, this.listener);
|
|
45
44
|
}
|
|
46
45
|
this.bound = true;
|
|
46
|
+
this.logger.debug(`Loaded Event ${String(this.name)}`);
|
|
47
47
|
}
|
|
48
48
|
onExecute(func) {
|
|
49
49
|
this.handler = func;
|
|
@@ -0,0 +1,9 @@
|
|
|
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);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js";
|
|
2
|
-
import { CommandBuilder } from "
|
|
2
|
+
import { CommandBuilder } from "#structures";
|
|
3
|
+
import { Logger } from "#utils";
|
|
3
4
|
import { FrameworkOptions } from "#types/client.js";
|
|
4
|
-
import {
|
|
5
|
+
import { i18n } from "i18next";
|
|
5
6
|
export declare class Client<Ready extends boolean = boolean> extends DiscordClient<Ready> {
|
|
6
7
|
readonly logger: Logger;
|
|
7
8
|
commands: Collection<string, CommandBuilder>;
|
|
8
9
|
aliases: Collection<string, Set<string>>;
|
|
9
10
|
readonly prefix: string | false;
|
|
11
|
+
i18n: i18n | undefined;
|
|
10
12
|
options: Omit<FrameworkOptions, "intents"> & {
|
|
11
13
|
intents: IntentsBitField;
|
|
12
14
|
};
|
|
13
15
|
constructor(opts: FrameworkOptions);
|
|
14
|
-
|
|
16
|
+
login(token?: string): Promise<string>;
|
|
17
|
+
loadDir(dir: string): Promise<void>;
|
|
15
18
|
loadFile(file: string): Promise<void>;
|
|
16
19
|
registerCommands(): Promise<void>;
|
|
17
20
|
}
|
|
@@ -11,16 +11,15 @@ Object.defineProperty(exports, "Client", {
|
|
|
11
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
12
|
const _discord = require("discord.js");
|
|
13
13
|
const _path = /*#__PURE__*/ _interop_require_default._(require("path"));
|
|
14
|
-
const
|
|
14
|
+
const _utils = require("#utils");
|
|
15
15
|
const _lodash = require("lodash");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const _Logger = require("../utils/logger/Logger");
|
|
16
|
+
const _ctx = require("#ctx");
|
|
17
|
+
const _fs = require("fs");
|
|
19
18
|
const defaultOpts = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
includePaths: [
|
|
20
|
+
"events",
|
|
21
|
+
"commands"
|
|
22
|
+
],
|
|
24
23
|
autoRegisterCommands: true
|
|
25
24
|
};
|
|
26
25
|
class Client extends _discord.Client {
|
|
@@ -28,32 +27,45 @@ class Client extends _discord.Client {
|
|
|
28
27
|
commands;
|
|
29
28
|
aliases;
|
|
30
29
|
prefix;
|
|
30
|
+
i18n;
|
|
31
31
|
constructor(opts){
|
|
32
32
|
super((0, _lodash.merge)({}, defaultOpts, opts));
|
|
33
|
-
this.logger = new
|
|
33
|
+
this.logger = new _utils.Logger(opts.logger);
|
|
34
34
|
this.commands = new _discord.Collection();
|
|
35
35
|
this.aliases = new _discord.Collection();
|
|
36
|
-
this.prefix = (0,
|
|
36
|
+
this.prefix = (0, _utils.getPrefix)(this.options.prefix ?? {
|
|
37
37
|
enabled: false
|
|
38
38
|
});
|
|
39
|
-
if (this.options.
|
|
40
|
-
this.
|
|
39
|
+
if (this.options.i18n) {
|
|
40
|
+
this.i18n = this.options.i18n;
|
|
41
|
+
this.i18n.use(new _utils.I18nLoggerAdapter(this.logger));
|
|
41
42
|
}
|
|
42
|
-
(0,
|
|
43
|
+
(0, _ctx.setClient)(this);
|
|
43
44
|
try {
|
|
44
45
|
require("../events/ready");
|
|
45
46
|
require("../events/interaction");
|
|
46
47
|
if (this.prefix) require("../events/message");
|
|
47
48
|
} finally{
|
|
48
|
-
(0,
|
|
49
|
+
(0, _ctx.clearClient)();
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
async
|
|
52
|
-
if (
|
|
53
|
-
|
|
52
|
+
async login(token) {
|
|
53
|
+
if (this.options.includePaths) {
|
|
54
|
+
for (const p of this.options.includePaths){
|
|
55
|
+
this.loadDir(_path.default.join((0, _utils.getProjectRoot)(), p)).catch((error)=>this.logger.error("Error loading events:", error));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (this.i18n && !this.i18n.isInitialized) {
|
|
59
|
+
await this.i18n.init();
|
|
60
|
+
}
|
|
61
|
+
return super.login(token);
|
|
62
|
+
}
|
|
63
|
+
async loadDir(dir) {
|
|
64
|
+
if (!(0, _fs.existsSync)(dir)) {
|
|
65
|
+
this.logger.debug(`Directory not found: ${dir}`);
|
|
54
66
|
return;
|
|
55
67
|
}
|
|
56
|
-
const files = (0,
|
|
68
|
+
const files = (0, _utils.getFiles)(dir);
|
|
57
69
|
for (const file of files){
|
|
58
70
|
await this.loadFile(file);
|
|
59
71
|
}
|
|
@@ -61,12 +73,12 @@ class Client extends _discord.Client {
|
|
|
61
73
|
async loadFile(file) {
|
|
62
74
|
try {
|
|
63
75
|
delete require.cache[require.resolve(file)];
|
|
64
|
-
(0,
|
|
76
|
+
(0, _ctx.setClient)(this);
|
|
65
77
|
require(file);
|
|
66
78
|
} catch (error) {
|
|
67
79
|
this.logger.error(`Error loading file ${file}:`, error);
|
|
68
80
|
} finally{
|
|
69
|
-
(0,
|
|
81
|
+
(0, _ctx.clearClient)();
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
async registerCommands() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Client";
|
|
@@ -0,0 +1,8 @@
|
|
|
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("./util"), exports);
|
|
7
|
+
_export_star._(require("./Files"), exports);
|
|
8
|
+
_export_star._(require("./logger/Logger"), exports);
|
|
@@ -3,6 +3,7 @@ import type { Color } from "colorette";
|
|
|
3
3
|
import { Timestamp } from "@sapphire/timestamp";
|
|
4
4
|
import type { ILogger } from "./ILogger";
|
|
5
5
|
import { LogLevel } from "./ILogger";
|
|
6
|
+
import { LoggerModule } from "i18next";
|
|
6
7
|
export declare class Logger implements ILogger {
|
|
7
8
|
level: LogLevel;
|
|
8
9
|
readonly formats: Map<LogLevel, LoggerLevel>;
|
|
@@ -140,3 +141,11 @@ export declare enum LoggerStyleBackground {
|
|
|
140
141
|
CyanBright = "bgCyanBright",
|
|
141
142
|
WhiteBright = "bgWhiteBright"
|
|
142
143
|
}
|
|
144
|
+
export declare class I18nLoggerAdapter implements LoggerModule {
|
|
145
|
+
private readonly logger;
|
|
146
|
+
readonly type = "logger";
|
|
147
|
+
constructor(logger: Logger);
|
|
148
|
+
log(...args: unknown[]): void;
|
|
149
|
+
warn(...args: unknown[]): void;
|
|
150
|
+
error(...args: unknown[]): void;
|
|
151
|
+
}
|
|
@@ -10,6 +10,9 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
+
get I18nLoggerAdapter () {
|
|
14
|
+
return I18nLoggerAdapter;
|
|
15
|
+
},
|
|
13
16
|
get Logger () {
|
|
14
17
|
return Logger;
|
|
15
18
|
},
|
|
@@ -359,3 +362,19 @@ var LoggerStyleBackground = /*#__PURE__*/ function(LoggerStyleBackground) {
|
|
|
359
362
|
LoggerStyleBackground["WhiteBright"] = "bgWhiteBright";
|
|
360
363
|
return LoggerStyleBackground;
|
|
361
364
|
}({});
|
|
365
|
+
class I18nLoggerAdapter {
|
|
366
|
+
logger;
|
|
367
|
+
type = "logger";
|
|
368
|
+
constructor(logger){
|
|
369
|
+
this.logger = logger;
|
|
370
|
+
}
|
|
371
|
+
log(...args) {
|
|
372
|
+
this.logger.debug("[i18next]", ...args);
|
|
373
|
+
}
|
|
374
|
+
warn(...args) {
|
|
375
|
+
this.logger.warn("[i18next]", ...args);
|
|
376
|
+
}
|
|
377
|
+
error(...args) {
|
|
378
|
+
this.logger.error("[i18next]", ...args);
|
|
379
|
+
}
|
|
380
|
+
}
|
package/dist/utils/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PrefixOptions } from "#types/client.js";
|
|
2
2
|
import { InteractionResponse, Message } from "discord.js";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function deleteMessageAfterSent(message: Message | InteractionResponse, time?: number): Promise<void>;
|
|
4
4
|
export declare function getPrefix(opts: PrefixOptions): string | false;
|
package/dist/utils/util.js
CHANGED
|
@@ -9,14 +9,14 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
get
|
|
13
|
-
return
|
|
12
|
+
get deleteMessageAfterSent () {
|
|
13
|
+
return deleteMessageAfterSent;
|
|
14
14
|
},
|
|
15
15
|
get getPrefix () {
|
|
16
16
|
return getPrefix;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
function
|
|
19
|
+
function deleteMessageAfterSent(message, time = 15_000) {
|
|
20
20
|
return new Promise((r)=>{
|
|
21
21
|
setTimeout(()=>{
|
|
22
22
|
message.delete().catch(()=>{});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arox/framework",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord.js",
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
22
|
"imports": {
|
|
23
|
-
"#types/*": "./types/*"
|
|
23
|
+
"#types/*": "./types/*",
|
|
24
|
+
"#utils": "./src/utils/index.ts",
|
|
25
|
+
"#structures": "./src/structures/index.ts",
|
|
26
|
+
"#ctx": "./src/context.ts"
|
|
24
27
|
},
|
|
25
28
|
"scripts": {
|
|
26
29
|
"prepare": "node scripts/prepareHusky.js",
|
|
@@ -38,15 +41,17 @@
|
|
|
38
41
|
"@swc/helpers": "^0.5.18",
|
|
39
42
|
"colorette": "^2.0.20",
|
|
40
43
|
"fast-glob": "^3.3.3",
|
|
44
|
+
"i18next": "^25.8.0",
|
|
45
|
+
"i18next-fs-backend": "^2.6.1",
|
|
41
46
|
"lodash": "^4.17.21"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {
|
|
44
49
|
"@swc/cli": "^0.7.10",
|
|
45
50
|
"@types/lodash": "^4.17.23",
|
|
46
|
-
"@types/node": "^25.0.
|
|
51
|
+
"@types/node": "^25.0.9",
|
|
47
52
|
"husky": "^9.1.7",
|
|
48
53
|
"libnpmpack": "^9.0.12",
|
|
49
|
-
"oxfmt": "^0.
|
|
54
|
+
"oxfmt": "^0.26.0",
|
|
50
55
|
"oxlint": "^1.39.0",
|
|
51
56
|
"oxlint-tsgolint": "^0.11.0",
|
|
52
57
|
"typescript": "^5.9.3"
|
package/types/client.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ClientOptions } from "discord.js";
|
|
2
2
|
import { LoggerOptions } from "../src/utils/logger/Logger";
|
|
3
|
+
import { i18n } from "i18next";
|
|
3
4
|
|
|
4
5
|
export interface FrameworkPaths {
|
|
5
6
|
events?: string;
|
|
6
7
|
commands?: string;
|
|
8
|
+
locales?: string;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export type PrefixOptions =
|
|
@@ -14,6 +16,7 @@ export type PrefixOptions =
|
|
|
14
16
|
export interface FrameworkOptions extends ClientOptions {
|
|
15
17
|
logger?: LoggerOptions;
|
|
16
18
|
prefix?: PrefixOptions;
|
|
17
|
-
paths?: FrameworkPaths;
|
|
18
19
|
autoRegisterCommands?: boolean;
|
|
20
|
+
includePaths: string[];
|
|
21
|
+
i18n?: i18n;
|
|
19
22
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ApplicationCommandOptionData, ChatInputCommandInteraction, Message } from "discord.js";
|
|
2
|
-
import { Context } from "./Context";
|
|
3
|
-
import { Client } from "./Client";
|
|
4
|
-
import { Argument } from "./Argument";
|
|
5
|
-
import { MaybePromise } from "#types/extra.js";
|
|
6
|
-
import { Logger } from "../utils/logger/Logger";
|
|
7
|
-
export interface CommandOptions {
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
aliases?: string[];
|
|
11
|
-
options?: (ApplicationCommandOptionData | Argument)[];
|
|
12
|
-
slash?: boolean;
|
|
13
|
-
prefix?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class CommandBuilder {
|
|
16
|
-
readonly client: Client;
|
|
17
|
-
readonly logger: Logger;
|
|
18
|
-
readonly name: string;
|
|
19
|
-
readonly description: string;
|
|
20
|
-
readonly aliases: string[];
|
|
21
|
-
readonly options: ApplicationCommandOptionData[];
|
|
22
|
-
private _supportsSlash;
|
|
23
|
-
private _supportsPrefix;
|
|
24
|
-
_onMessage?: (ctx: NonNullable<ReturnType<Context<Message>["toJSON"]>>) => MaybePromise<void>;
|
|
25
|
-
_onInteraction?: (ctx: NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>) => MaybePromise<void>;
|
|
26
|
-
get supportsSlash(): false | ((ctx: NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>) => MaybePromise<void>) | undefined;
|
|
27
|
-
get supportsPrefix(): false | ((ctx: NonNullable<ReturnType<Context<Message>["toJSON"]>>) => MaybePromise<void>) | undefined;
|
|
28
|
-
constructor(options: CommandOptions);
|
|
29
|
-
onMessage(func: (ctx: NonNullable<ReturnType<Context<Message>["toJSON"]>>) => MaybePromise<void>): this;
|
|
30
|
-
onInteraction(func: (ctx: NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>) => MaybePromise<void>): this;
|
|
31
|
-
}
|
|
File without changes
|