@arox/framework 0.1.0-alpha.2 → 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 +4 -0
- package/dist/context.js +28 -0
- package/dist/events/interaction.d.ts +1 -0
- package/dist/events/interaction.js +38 -0
- package/dist/events/message.d.ts +1 -0
- package/dist/events/message.js +36 -0
- package/dist/events/ready.d.ts +1 -0
- package/dist/events/ready.js +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -1
- package/dist/structures/builder/Argument.d.ts +22 -0
- package/dist/structures/builder/Argument.js +42 -0
- package/dist/structures/builder/Command.d.ts +33 -0
- package/dist/structures/builder/Command.js +74 -0
- package/dist/structures/builder/Context.d.ts +36 -0
- package/dist/structures/builder/Context.js +67 -0
- package/dist/structures/builder/Event.d.ts +19 -0
- package/dist/structures/builder/Event.js +53 -0
- package/dist/structures/builder/index.d.ts +4 -0
- package/dist/structures/builder/index.js +9 -0
- package/dist/structures/core/Client.d.ts +20 -0
- package/dist/structures/core/Client.js +111 -0
- 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/Files.d.ts +2 -0
- package/dist/utils/Files.js +47 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/logger/ILogger.d.ts +76 -0
- package/dist/utils/logger/ILogger.js +37 -0
- package/dist/utils/logger/Logger.d.ts +151 -0
- package/dist/utils/logger/Logger.js +380 -0
- package/dist/utils/util.d.ts +4 -0
- package/dist/utils/util.js +35 -0
- package/package.json +22 -3
- package/types/client.d.ts +22 -0
- package/types/extra.d.ts +1 -0
package/dist/context.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "version", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return version;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
|
12
|
+
_export_star._(require("#structures"), exports);
|
|
13
|
+
_export_star._(require("./utils/logger/Logger"), exports);
|
|
14
|
+
_export_star._(require("#ctx"), exports);
|
|
15
|
+
const version = "v0.1.1";
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Message, User, ChatInputCommandInteraction, Locale } from "discord.js";
|
|
2
|
+
import { Client } from "#structures";
|
|
3
|
+
type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends ChatInputCommandInteraction ? {
|
|
4
|
+
interaction: T;
|
|
5
|
+
args?: string[];
|
|
6
|
+
} : {
|
|
7
|
+
message: T;
|
|
8
|
+
args?: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare class Context<T extends ChatInputCommandInteraction | Message> {
|
|
11
|
+
readonly client: Client;
|
|
12
|
+
readonly args: string[];
|
|
13
|
+
readonly data: T;
|
|
14
|
+
locale?: `${Locale}`;
|
|
15
|
+
constructor(client: Client, payload: ContextPayload<T>);
|
|
16
|
+
isInteraction(): this is Context<ChatInputCommandInteraction>;
|
|
17
|
+
isMessage(): this is Context<Message>;
|
|
18
|
+
get author(): User | null;
|
|
19
|
+
t(key: string, args?: Record<string, any>): string;
|
|
20
|
+
toJSON(): {
|
|
21
|
+
kind: "interaction";
|
|
22
|
+
interaction: T;
|
|
23
|
+
author: User | null;
|
|
24
|
+
t: any;
|
|
25
|
+
message?: undefined;
|
|
26
|
+
args?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "message";
|
|
29
|
+
message: Message;
|
|
30
|
+
args: string[];
|
|
31
|
+
author: User | null;
|
|
32
|
+
t: any;
|
|
33
|
+
interaction?: undefined;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClientEvents } from "discord.js";
|
|
2
|
+
import { MaybePromise } from "#types/extra.js";
|
|
3
|
+
import { Client } from "#structures";
|
|
4
|
+
import { Logger } from "#utils";
|
|
5
|
+
type EventArgs<K extends keyof ClientEvents> = ClientEvents[K];
|
|
6
|
+
type EventHandler<K extends keyof ClientEvents> = (context: EventBuilder<K>, ...args: EventArgs<K>) => MaybePromise<void>;
|
|
7
|
+
export declare class EventBuilder<K extends keyof ClientEvents> {
|
|
8
|
+
readonly name: K;
|
|
9
|
+
readonly once: boolean;
|
|
10
|
+
readonly client: Client;
|
|
11
|
+
readonly logger: Logger;
|
|
12
|
+
private handler?;
|
|
13
|
+
private bound;
|
|
14
|
+
private readonly listener;
|
|
15
|
+
constructor(name: K, once?: boolean, _handler?: EventHandler<K>);
|
|
16
|
+
private register;
|
|
17
|
+
onExecute(func: EventHandler<K>): this;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
}
|
|
@@ -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);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js";
|
|
2
|
+
import { CommandBuilder } from "#structures";
|
|
3
|
+
import { Logger } from "#utils";
|
|
4
|
+
import { FrameworkOptions } from "#types/client.js";
|
|
5
|
+
import { i18n } from "i18next";
|
|
6
|
+
export declare class Client<Ready extends boolean = boolean> extends DiscordClient<Ready> {
|
|
7
|
+
readonly logger: Logger;
|
|
8
|
+
commands: Collection<string, CommandBuilder>;
|
|
9
|
+
aliases: Collection<string, Set<string>>;
|
|
10
|
+
readonly prefix: string | false;
|
|
11
|
+
i18n: i18n | undefined;
|
|
12
|
+
options: Omit<FrameworkOptions, "intents"> & {
|
|
13
|
+
intents: IntentsBitField;
|
|
14
|
+
};
|
|
15
|
+
constructor(opts: FrameworkOptions);
|
|
16
|
+
login(token?: string): Promise<string>;
|
|
17
|
+
loadDir(dir: string): Promise<void>;
|
|
18
|
+
loadFile(file: string): Promise<void>;
|
|
19
|
+
registerCommands(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Client", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Client;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
+
const _discord = require("discord.js");
|
|
13
|
+
const _path = /*#__PURE__*/ _interop_require_default._(require("path"));
|
|
14
|
+
const _utils = require("#utils");
|
|
15
|
+
const _lodash = require("lodash");
|
|
16
|
+
const _ctx = require("#ctx");
|
|
17
|
+
const _fs = require("fs");
|
|
18
|
+
const defaultOpts = {
|
|
19
|
+
includePaths: [
|
|
20
|
+
"events",
|
|
21
|
+
"commands"
|
|
22
|
+
],
|
|
23
|
+
autoRegisterCommands: true
|
|
24
|
+
};
|
|
25
|
+
class Client extends _discord.Client {
|
|
26
|
+
logger;
|
|
27
|
+
commands;
|
|
28
|
+
aliases;
|
|
29
|
+
prefix;
|
|
30
|
+
i18n;
|
|
31
|
+
constructor(opts){
|
|
32
|
+
super((0, _lodash.merge)({}, defaultOpts, opts));
|
|
33
|
+
this.logger = new _utils.Logger(opts.logger);
|
|
34
|
+
this.commands = new _discord.Collection();
|
|
35
|
+
this.aliases = new _discord.Collection();
|
|
36
|
+
this.prefix = (0, _utils.getPrefix)(this.options.prefix ?? {
|
|
37
|
+
enabled: false
|
|
38
|
+
});
|
|
39
|
+
if (this.options.i18n) {
|
|
40
|
+
this.i18n = this.options.i18n;
|
|
41
|
+
this.i18n.use(new _utils.I18nLoggerAdapter(this.logger));
|
|
42
|
+
}
|
|
43
|
+
(0, _ctx.setClient)(this);
|
|
44
|
+
try {
|
|
45
|
+
require("../events/ready");
|
|
46
|
+
require("../events/interaction");
|
|
47
|
+
if (this.prefix) require("../events/message");
|
|
48
|
+
} finally{
|
|
49
|
+
(0, _ctx.clearClient)();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
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}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const files = (0, _utils.getFiles)(dir);
|
|
69
|
+
for (const file of files){
|
|
70
|
+
await this.loadFile(file);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async loadFile(file) {
|
|
74
|
+
try {
|
|
75
|
+
delete require.cache[require.resolve(file)];
|
|
76
|
+
(0, _ctx.setClient)(this);
|
|
77
|
+
require(file);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.logger.error(`Error loading file ${file}:`, error);
|
|
80
|
+
} finally{
|
|
81
|
+
(0, _ctx.clearClient)();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async registerCommands() {
|
|
85
|
+
if (!this.token) {
|
|
86
|
+
this.logger.warn("registerCommands skipped: client token is not set.");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!this.application) {
|
|
90
|
+
this.logger.warn("registerCommands skipped: client application is not ready.");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const slashCommands = this.commands.filter((cmd)=>cmd.supportsSlash).map((cmd)=>({
|
|
94
|
+
name: cmd.name,
|
|
95
|
+
description: cmd.description,
|
|
96
|
+
options: cmd.options
|
|
97
|
+
}));
|
|
98
|
+
const rest = new _discord.REST({
|
|
99
|
+
version: "10"
|
|
100
|
+
}).setToken(this.token);
|
|
101
|
+
try {
|
|
102
|
+
this.logger.debug(`Started refreshing ${slashCommands.length} application (/) commands.`);
|
|
103
|
+
await rest.put(_discord.Routes.applicationCommands(this.application.id), {
|
|
104
|
+
body: slashCommands
|
|
105
|
+
});
|
|
106
|
+
this.logger.info(`Loaded ${slashCommands.length} application (/) commands.`);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
this.logger.error("Failed to register commands:", error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Client";
|