trivious 2.2.5 → 2.3.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/features/builders/utility.builders.js +8 -5
- package/dist/features/builders/utility.builders.js.map +1 -1
- package/dist/features/client/client.types.d.ts +1 -0
- package/dist/features/client/client.types.js +0 -2
- package/dist/features/client/client.types.js.map +1 -1
- package/dist/features/client/deploy.client.d.ts +2 -1
- package/dist/features/client/deploy.client.js +8 -9
- package/dist/features/client/deploy.client.js.map +1 -1
- package/dist/features/client/logger.d.ts +11 -0
- package/dist/features/client/logger.js +24 -0
- package/dist/features/client/logger.js.map +1 -0
- package/dist/features/client/trivious.client.d.ts +2 -1
- package/dist/features/client/trivious.client.js +11 -9
- package/dist/features/client/trivious.client.js.map +1 -1
- package/dist/features/commands/builders.commands.d.ts +6 -5
- package/dist/features/commands/builders.commands.js +10 -5
- package/dist/features/commands/builders.commands.js.map +1 -1
- package/dist/features/commands/commands.types.d.ts +2 -1
- package/dist/features/commands/commands.types.js +0 -2
- package/dist/features/commands/commands.types.js.map +1 -1
- package/dist/features/commands/methods.commands.d.ts +2 -1
- package/dist/features/commands/methods.commands.js +4 -3
- package/dist/features/commands/methods.commands.js.map +1 -1
- package/dist/features/commands/registry.commands.d.ts +2 -1
- package/dist/features/commands/registry.commands.js +91 -79
- package/dist/features/commands/registry.commands.js.map +1 -1
- package/dist/features/components/builders.components.d.ts +2 -1
- package/dist/features/components/builders.components.js +7 -5
- package/dist/features/components/builders.components.js.map +1 -1
- package/dist/features/components/components.types.d.ts +2 -1
- package/dist/features/components/components.types.js +3 -3
- package/dist/features/components/components.types.js.map +1 -1
- package/dist/features/components/registry.components.d.ts +2 -1
- package/dist/features/components/registry.components.js +9 -10
- package/dist/features/components/registry.components.js.map +1 -1
- package/dist/features/customId/customid.types.d.ts +2 -1
- package/dist/features/customId/customid.types.js +0 -2
- package/dist/features/customId/customid.types.js.map +1 -1
- package/dist/features/customId/methods.customid.d.ts +2 -1
- package/dist/features/customId/methods.customid.js +4 -5
- package/dist/features/customId/methods.customid.js.map +1 -1
- package/dist/features/events/builders.events.d.ts +2 -1
- package/dist/features/events/builders.events.js +4 -3
- package/dist/features/events/builders.events.js.map +1 -1
- package/dist/features/events/events.types.d.ts +2 -1
- package/dist/features/events/events.types.js +0 -2
- package/dist/features/events/events.types.js.map +1 -1
- package/dist/features/events/presets/clientReady.d.ts +2 -1
- package/dist/features/events/presets/clientReady.js +3 -3
- package/dist/features/events/presets/clientReady.js.map +1 -1
- package/dist/features/events/presets/interactionCreate.d.ts +2 -1
- package/dist/features/events/presets/interactionCreate.js +14 -9
- package/dist/features/events/presets/interactionCreate.js.map +1 -1
- package/dist/features/events/registry.events.d.ts +2 -1
- package/dist/features/events/registry.events.js +10 -10
- package/dist/features/events/registry.events.js.map +1 -1
- package/dist/features/modules/builders.modules.d.ts +2 -1
- package/dist/features/modules/builders.modules.js +3 -3
- package/dist/features/modules/builders.modules.js.map +1 -1
- package/dist/features/modules/modules.types.d.ts +2 -1
- package/dist/features/modules/modules.types.js +0 -2
- package/dist/features/modules/modules.types.js.map +1 -1
- package/dist/features/modules/registry.modules.d.ts +2 -1
- package/dist/features/modules/registry.modules.js +9 -9
- package/dist/features/modules/registry.modules.js.map +1 -1
- package/dist/features/permissions/methods.permissions.d.ts +2 -1
- package/dist/features/permissions/methods.permissions.js +4 -3
- package/dist/features/permissions/methods.permissions.js.map +1 -1
- package/dist/features/permissions/permissions.types.js +0 -2
- package/dist/features/permissions/permissions.types.js.map +1 -1
- package/dist/features/structure/index.structure.js +11 -12
- package/dist/features/structure/index.structure.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/{modules.types-lYoNHt-m.d.ts → modules.types-hjAYMYut.d.ts} +14 -6
- package/dist/shared/registries.d.ts +2 -1
- package/dist/shared/registries.js +7 -8
- package/dist/shared/registries.js.map +1 -1
- package/dist/shared/typings.d.ts +2 -1
- package/dist/shared/typings.js +11 -9
- package/dist/shared/typings.js.map +1 -1
- package/dist/utility/errors.d.ts +2 -1
- package/dist/utility/errors.js +4 -3
- package/dist/utility/errors.js.map +1 -1
- package/dist/utility/functions.js +7 -7
- package/dist/utility/functions.js.map +1 -1
- package/package.json +10 -5
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ActionRowBuilder,
|
|
3
|
+
EmbedBuilder
|
|
4
|
+
} from "discord.js";
|
|
3
5
|
function createActionRow(...builders) {
|
|
4
6
|
return new ActionRowBuilder().setComponents(...builders);
|
|
5
7
|
}
|
|
6
8
|
function createEmbed(data) {
|
|
7
9
|
return new EmbedBuilder(data);
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
export {
|
|
12
|
+
createActionRow,
|
|
13
|
+
createEmbed
|
|
14
|
+
};
|
|
12
15
|
//# sourceMappingURL=utility.builders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/builders/utility.builders.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/builders/utility.builders.ts"],"sourcesContent":["import {\n\tActionRowBuilder,\n\tAPIEmbed,\n\tEmbedBuilder,\n\tEmbedData,\n\tMessageActionRowComponentBuilder,\n} from \"discord.js\";\n\n/**\n * Utility action row builder\n */\nexport function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]) {\n\treturn new ActionRowBuilder<T>().setComponents(...builders);\n}\n\n/**\n * Utility embed builder\n */\nexport function createEmbed(data?: EmbedData | APIEmbed) {\n\treturn new EmbedBuilder(data);\n}\n"],"mappings":"AAAA;AAAA,EACC;AAAA,EAEA;AAAA,OAGM;AAKA,SAAS,mBAA+D,UAAe;AAC7F,SAAO,IAAI,iBAAoB,EAAE,cAAc,GAAG,QAAQ;AAC3D;AAKO,SAAS,YAAY,MAA6B;AACxD,SAAO,IAAI,aAAa,IAAI;AAC7B;","names":[]}
|
|
@@ -80,6 +80,7 @@ interface TriviousClientOptions extends ClientOptions {
|
|
|
80
80
|
corePath: string;
|
|
81
81
|
ownerUserIds?: string[];
|
|
82
82
|
commandHashConfig?: CommandHashConfiguration;
|
|
83
|
+
debug?: boolean;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
export type { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-hjAYMYut.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import './client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
|
+
import './logger.js';
|
|
5
6
|
|
|
6
7
|
declare function commandDeploy(client: TriviousClient): Promise<void>;
|
|
7
8
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { TriviousError } from "../../utility/errors.js";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { REST, Routes } from "discord.js";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { dirname, join } from "path";
|
|
7
6
|
async function commandDeploy(client) {
|
|
8
7
|
const { commandHashConfig } = client.trivious;
|
|
9
8
|
const clientId = process.env[client.trivious.credentials.clientIdReference];
|
|
@@ -35,7 +34,7 @@ async function commandDeploy(client) {
|
|
|
35
34
|
await rest.put(Routes.applicationCommands(clientId), { body });
|
|
36
35
|
console.debug(`[Trivious] Deployed ${body.length} commands`);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
export {
|
|
38
|
+
commandDeploy as default
|
|
39
|
+
};
|
|
41
40
|
//# sourceMappingURL=deploy.client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"sourcesContent":["import { TriviousError } from \"@utility/errors.js\";\nimport { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) => command.data.toJSON()),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,MAAM,cAAc;AAC7B,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAG9B,eAAO,cAAqC,QAAwB;AACnE,QAAM,EAAE,kBAAkB,IAAI,OAAO;AAErC,QAAM,WAAW,QAAQ,IAAI,OAAO,SAAS,YAAY,iBAAiB;AAC1E,QAAM,QAAQ,QAAQ,IAAI,OAAO,SAAS,YAAY,cAAc;AACpE,MAAI,CAAC,YAAY,CAAC;AACjB,UAAM,IAAI,cAAc,gDAAgD;AAEzE,QAAM,WAAW,OAAO,OAAO;AAC/B,QAAM,OAAO;AAAA,IACZ,GAAG,SAAS,UAAU,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC5D,GAAG,SAAS,QAAQ,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC3D;AAEA,MAAI,qBAAqB,kBAAkB,SAAS;AACnD,UAAM,WAAW,KAAK,kBAAkB,sBAAsB,QAAQ,eAAe;AACrF,UAAM,UAAU,WAAW,QAAQ,EACjC,OAAO,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EACnF,OAAO,KAAK;AAEd,QAAI,UAAU;AACd,QAAI,WAAW,QAAQ,EAAG,WAAU,aAAa,UAAU,OAAO;AAElE,QAAI,YAAY,SAAS;AACxB,cAAQ,MAAM,+DAA+D;AAC7E;AAAA,IACD;AAEA,UAAM,gBAAgB,QAAQ,QAAQ;AACtC,QAAI,CAAC,WAAW,aAAa,GAAG;AAC/B,gBAAU,eAAe,EAAE,WAAW,KAAK,CAAC;AAAA,IAC7C;AAEA,kBAAc,UAAU,SAAS,EAAE,UAAU,QAAQ,CAAC;AACtD,YAAQ,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACjE;AAEA,QAAM,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC,EAAE,SAAS,KAAK;AACvD,QAAM,KAAK,IAAI,OAAO,oBAAoB,QAAQ,GAAG,EAAE,KAAK,CAAC;AAC7D,UAAQ,MAAM,uBAAuB,KAAK,MAAM,WAAW;AAC5D;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class Logger {
|
|
2
|
+
private prefix;
|
|
3
|
+
private debugActive;
|
|
4
|
+
constructor(prefix?: string, debugActive?: boolean);
|
|
5
|
+
debug(...args: any[]): void;
|
|
6
|
+
info(...args: any[]): void;
|
|
7
|
+
warn(...args: any[]): void;
|
|
8
|
+
error(...args: any[]): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { Logger };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
class Logger {
|
|
3
|
+
constructor(prefix = "Trivious", debugActive = false) {
|
|
4
|
+
this.prefix = prefix;
|
|
5
|
+
this.debugActive = debugActive;
|
|
6
|
+
}
|
|
7
|
+
debug(...args) {
|
|
8
|
+
if (!this.debugActive) return;
|
|
9
|
+
console.log(chalk.gray(`[${this.prefix}] [DEBUG]`), ...args);
|
|
10
|
+
}
|
|
11
|
+
info(...args) {
|
|
12
|
+
console.log(chalk.cyan([`${this.prefix}`]), ...args);
|
|
13
|
+
}
|
|
14
|
+
warn(...args) {
|
|
15
|
+
console.log(chalk.yellow([`${this.prefix} [WARN]`]), ...args);
|
|
16
|
+
}
|
|
17
|
+
error(...args) {
|
|
18
|
+
console.log(chalk.red([`${this.prefix} [ERROR]`]), ...args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
Logger
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/logger.ts"],"sourcesContent":["import chalk from \"chalk\";\n\nexport class Logger {\n\tconstructor(\n\t\tprivate prefix = \"Trivious\",\n\t\tprivate debugActive = false\n\t) {}\n\n\tdebug(...args: any[]) {\n\t\tif (!this.debugActive) return;\n\t\tconsole.log(chalk.gray(`[${this.prefix}] [DEBUG]`), ...args);\n\t}\n\n\tinfo(...args: any[]) {\n\t\tconsole.log(chalk.cyan([`${this.prefix}`]), ...args);\n\t}\n\n\twarn(...args: any[]) {\n\t\tconsole.log(chalk.yellow([`${this.prefix} [WARN]`]), ...args);\n\t}\n\n\terror(...args: any[]) {\n\t\tconsole.log(chalk.red([`${this.prefix} [ERROR]`]), ...args);\n\t}\n}\n"],"mappings":"AAAA,OAAO,WAAW;AAEX,MAAM,OAAO;AAAA,EACnB,YACS,SAAS,YACT,cAAc,OACrB;AAFO;AACA;AAAA,EACN;AAAA,EAEH,SAAS,MAAa;AACrB,QAAI,CAAC,KAAK,YAAa;AACvB,YAAQ,IAAI,MAAM,KAAK,IAAI,KAAK,MAAM,WAAW,GAAG,GAAG,IAAI;AAAA,EAC5D;AAAA,EAEA,QAAQ,MAAa;AACpB,YAAQ,IAAI,MAAM,KAAK,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI;AAAA,EACpD;AAAA,EAEA,QAAQ,MAAa;AACpB,YAAQ,IAAI,MAAM,OAAO,CAAC,GAAG,KAAK,MAAM,SAAS,CAAC,GAAG,GAAG,IAAI;AAAA,EAC7D;AAAA,EAEA,SAAS,MAAa;AACrB,YAAQ,IAAI,MAAM,IAAI,CAAC,GAAG,KAAK,MAAM,UAAU,CAAC,GAAG,GAAG,IAAI;AAAA,EAC3D;AACD;","names":[]}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import structure from
|
|
4
|
-
import { TriviousError } from
|
|
5
|
-
import commandDeploy from
|
|
6
|
-
|
|
1
|
+
import registries from "../../shared/registries.js";
|
|
2
|
+
import { Client, Collection } from "discord.js";
|
|
3
|
+
import structure from "../structure/index.structure.js";
|
|
4
|
+
import { TriviousError } from "../../utility/errors.js";
|
|
5
|
+
import commandDeploy from "./deploy.client.js";
|
|
6
|
+
import { Logger } from "./logger.js";
|
|
7
7
|
class TriviousClient extends Client {
|
|
8
8
|
trivious;
|
|
9
9
|
stores;
|
|
10
|
+
logger;
|
|
10
11
|
constructor(options) {
|
|
11
12
|
super(options);
|
|
12
13
|
this.trivious = options;
|
|
14
|
+
this.logger = new Logger("Trivious", !!options.debug);
|
|
13
15
|
this.stores = {
|
|
14
16
|
commands: {
|
|
15
17
|
chatInput: new Collection(),
|
|
@@ -55,7 +57,7 @@ class TriviousClient extends Client {
|
|
|
55
57
|
await commandDeploy(this);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
export {
|
|
61
|
+
TriviousClient as default
|
|
62
|
+
};
|
|
61
63
|
//# sourceMappingURL=trivious.client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"sourcesContent":["import registries from \"@shared/registries.js\";\nimport { Client, Collection } from \"discord.js\";\nimport structure from \"../structure/index.structure.js\";\n\nimport {\n\tComponent,\n\tContextCommandData,\n\tEvent,\n\tModule,\n\tSlashCommandData,\n\tTriviousClientOptions,\n} from \"@typings\";\nimport { TriviousError } from \"@utility/errors.js\";\nimport commandDeploy from \"./deploy.client.js\";\nimport { Logger } from \"./logger.js\";\n\nexport default class TriviousClient extends Client {\n\ttrivious: TriviousClientOptions;\n\treadonly stores: {\n\t\tcommands: {\n\t\t\tchatInput: Collection<string, SlashCommandData>;\n\t\t\tcontext: Collection<string, ContextCommandData>;\n\t\t};\n\t\tcomponents: Collection<string, Component>;\n\t\tevents: Collection<string, Event>;\n\t\tmodules: Collection<string, Module>;\n\t};\n\tlogger: Logger;\n\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\n\t\tthis.logger = new Logger(\"Trivious\", !!options.debug);\n\n\t\tthis.stores = {\n\t\t\tcommands: {\n\t\t\t\tchatInput: new Collection(),\n\t\t\t\tcontext: new Collection(),\n\t\t\t},\n\t\t\tcomponents: new Collection(),\n\t\t\tevents: new Collection(),\n\t\t\tmodules: new Collection(),\n\t\t};\n\t}\n\n\t/**\n\t * Register, deploy and log into the bot.\n\t *\n\t * @throws {TriviousError} If invalid bot token\n\t */\n\tasync start() {\n\t\tconst token = process.env[this.trivious.credentials.tokenReference];\n\t\tif (!token) {\n\t\t\tthrow new TriviousError(\n\t\t\t\t`Bot token environment variable '${this.trivious.credentials.tokenReference}' does not exist!`,\n\t\t\t\t\"Null environment variable\"\n\t\t\t);\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\ttry {\n\t\t\tawait registries.events.bind(this);\n\t\t\tawait registries.modules.bind(this);\n\t\t} catch (err: any) {\n\t\t\tconst error = new TriviousError(err.message, \"Error during events and modules binds\");\n\t\t\tconsole.error(error);\n\t\t}\n\n\t\tawait this.login(token);\n\t}\n\n\tasync register() {\n\t\tconst dir = structure.resolveRelativePath(this.trivious.corePath);\n\n\t\tawait registries.events.register(this, dir);\n\t\tawait registries.modules.register(this, dir);\n\t\tawait registries.commands.register(this, dir);\n\t\tawait registries.components.register(this, dir);\n\t}\n\n\tasync deploy() {\n\t\tawait commandDeploy(this);\n\t}\n}\n"],"mappings":"AAAA,OAAO,gBAAgB;AACvB,SAAS,QAAQ,kBAAkB;AACnC,OAAO,eAAe;AAUtB,SAAS,qBAAqB;AAC9B,OAAO,mBAAmB;AAC1B,SAAS,cAAc;AAEvB,MAAO,uBAAqC,OAAO;AAAA,EAClD;AAAA,EACS;AAAA,EAST;AAAA,EAEA,YAAY,SAAgC;AAC3C,UAAM,OAAO;AACb,SAAK,WAAW;AAChB,SAAK,SAAS,IAAI,OAAO,YAAY,CAAC,CAAC,QAAQ,KAAK;AAEpD,SAAK,SAAS;AAAA,MACb,UAAU;AAAA,QACT,WAAW,IAAI,WAAW;AAAA,QAC1B,SAAS,IAAI,WAAW;AAAA,MACzB;AAAA,MACA,YAAY,IAAI,WAAW;AAAA,MAC3B,QAAQ,IAAI,WAAW;AAAA,MACvB,SAAS,IAAI,WAAW;AAAA,IACzB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,QAAQ;AACb,UAAM,QAAQ,QAAQ,IAAI,KAAK,SAAS,YAAY,cAAc;AAClE,QAAI,CAAC,OAAO;AACX,YAAM,IAAI;AAAA,QACT,mCAAmC,KAAK,SAAS,YAAY,cAAc;AAAA,QAC3E;AAAA,MACD;AAAA,IACD;AAEA,UAAM,KAAK,SAAS;AACpB,UAAM,KAAK,OAAO;AAElB,QAAI;AACH,YAAM,WAAW,OAAO,KAAK,IAAI;AACjC,YAAM,WAAW,QAAQ,KAAK,IAAI;AAAA,IACnC,SAAS,KAAU;AAClB,YAAM,QAAQ,IAAI,cAAc,IAAI,SAAS,uCAAuC;AACpF,cAAQ,MAAM,KAAK;AAAA,IACpB;AAEA,UAAM,KAAK,MAAM,KAAK;AAAA,EACvB;AAAA,EAEA,MAAM,WAAW;AAChB,UAAM,MAAM,UAAU,oBAAoB,KAAK,SAAS,QAAQ;AAEhE,UAAM,WAAW,OAAO,SAAS,MAAM,GAAG;AAC1C,UAAM,WAAW,QAAQ,SAAS,MAAM,GAAG;AAC3C,UAAM,WAAW,SAAS,SAAS,MAAM,GAAG;AAC5C,UAAM,WAAW,WAAW,SAAS,MAAM,GAAG;AAAA,EAC/C;AAAA,EAEA,MAAM,SAAS;AACd,UAAM,cAAc,IAAI;AAAA,EACzB;AACD;","names":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as ContextCommandData, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData } from '../../modules.types-hjAYMYut.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
|
+
import '../client/logger.js';
|
|
5
6
|
|
|
6
7
|
declare function createSlashCommand(data: Omit<SlashCommandData, "context" | "commandType" | "subcommands" | "subcommandGroups">): SlashCommandData;
|
|
7
8
|
/**
|
|
8
9
|
* @deprecated Use createSlashSubcommand instead
|
|
9
10
|
*/
|
|
10
|
-
declare function createSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType"
|
|
11
|
-
declare function createSlashSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType"
|
|
11
|
+
declare function createSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType">): SlashSubcommandData;
|
|
12
|
+
declare function createSlashSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType">): SlashSubcommandData;
|
|
12
13
|
/**
|
|
13
14
|
* @deprecated Use createSlashSubcommandGroup instead
|
|
14
15
|
*/
|
|
15
|
-
declare function createSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "
|
|
16
|
-
declare function createSlashSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "
|
|
16
|
+
declare function createSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "subcommands">): SlashSubcommandGroupData;
|
|
17
|
+
declare function createSlashSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "subcommands">): SlashSubcommandGroupData;
|
|
17
18
|
declare function createMessageContextCommand(data: Omit<ContextCommandData<"Message">, "commandType">): ContextCommandData<"Message">;
|
|
18
19
|
declare function createUserContextCommand(data: Omit<ContextCommandData<"User">, "commandType">): ContextCommandData<"User">;
|
|
19
20
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ApplicationCommandType, Collection } from
|
|
2
|
-
|
|
1
|
+
import { ApplicationCommandType, Collection } from "discord.js";
|
|
3
2
|
function createSlashCommand(data) {
|
|
4
3
|
return {
|
|
5
4
|
...data,
|
|
@@ -47,7 +46,13 @@ function createUserContextCommand(data) {
|
|
|
47
46
|
commandType: ApplicationCommandType.User
|
|
48
47
|
};
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
export {
|
|
50
|
+
createMessageContextCommand,
|
|
51
|
+
createSlashCommand,
|
|
52
|
+
createSlashSubcommand,
|
|
53
|
+
createSlashSubcommandGroup,
|
|
54
|
+
createSubcommand,
|
|
55
|
+
createSubcommandGroup,
|
|
56
|
+
createUserContextCommand
|
|
57
|
+
};
|
|
53
58
|
//# sourceMappingURL=builders.commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/commands/builders.commands.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/builders.commands.ts"],"sourcesContent":["import {\n\tContextCommandData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n} from \"@typings\";\nimport { ApplicationCommandType, Collection } from \"discord.js\";\n\nexport function createSlashCommand(\n\tdata: Omit<SlashCommandData, \"context\" | \"commandType\" | \"subcommands\" | \"subcommandGroups\">\n): SlashCommandData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashCommand\",\n\t\tcommandType: ApplicationCommandType.ChatInput,\n\t} satisfies SlashCommandData;\n}\n\n/**\n * @deprecated Use createSlashSubcommand instead\n */\nexport function createSubcommand(\n\tdata: Omit<SlashSubcommandData, \"context\" | \"commandType\">\n): SlashSubcommandData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommand\",\n\t\tcommandType: ApplicationCommandType.ChatInput,\n\t} satisfies SlashSubcommandData;\n}\n\nexport function createSlashSubcommand(\n\tdata: Omit<SlashSubcommandData, \"context\" | \"commandType\">\n): SlashSubcommandData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommand\",\n\t\tcommandType: ApplicationCommandType.ChatInput,\n\t} satisfies SlashSubcommandData;\n}\n\n/**\n * @deprecated Use createSlashSubcommandGroup instead\n */\nexport function createSubcommandGroup(\n\tdata: Omit<SlashSubcommandGroupData, \"context\" | \"subcommands\">\n): SlashSubcommandGroupData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommandGroup\",\n\t\tsubcommands: new Collection(),\n\t} satisfies SlashSubcommandGroupData;\n}\n\nexport function createSlashSubcommandGroup(\n\tdata: Omit<SlashSubcommandGroupData, \"context\" | \"subcommands\">\n): SlashSubcommandGroupData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommandGroup\",\n\t\tsubcommands: new Collection(),\n\t} satisfies SlashSubcommandGroupData;\n}\n\nexport function createMessageContextCommand(\n\tdata: Omit<ContextCommandData<\"Message\">, \"commandType\">\n): ContextCommandData<\"Message\"> {\n\treturn {\n\t\t...data,\n\t\tcommandType: ApplicationCommandType.Message,\n\t} satisfies ContextCommandData<\"Message\">;\n}\n\nexport function createUserContextCommand(\n\tdata: Omit<ContextCommandData<\"User\">, \"commandType\">\n): ContextCommandData<\"User\"> {\n\treturn {\n\t\t...data,\n\t\tcommandType: ApplicationCommandType.User,\n\t} satisfies ContextCommandData<\"User\">;\n}\n"],"mappings":"AAMA,SAAS,wBAAwB,kBAAkB;AAE5C,SAAS,mBACf,MACmB;AACnB,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS;AAAA,IACT,aAAa,uBAAuB;AAAA,EACrC;AACD;AAKO,SAAS,iBACf,MACsB;AACtB,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS;AAAA,IACT,aAAa,uBAAuB;AAAA,EACrC;AACD;AAEO,SAAS,sBACf,MACsB;AACtB,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS;AAAA,IACT,aAAa,uBAAuB;AAAA,EACrC;AACD;AAKO,SAAS,sBACf,MAC2B;AAC3B,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS;AAAA,IACT,aAAa,IAAI,WAAW;AAAA,EAC7B;AACD;AAEO,SAAS,2BACf,MAC2B;AAC3B,SAAO;AAAA,IACN,GAAG;AAAA,IACH,SAAS;AAAA,IACT,aAAa,IAAI,WAAW;AAAA,EAC7B;AACD;AAEO,SAAS,4BACf,MACgC;AAChC,SAAO;AAAA,IACN,GAAG;AAAA,IACH,aAAa,uBAAuB;AAAA,EACrC;AACD;AAEO,SAAS,yBACf,MAC6B;AAC7B,SAAO;AAAA,IACN,GAAG;AAAA,IACH,aAAa,uBAAuB;AAAA,EACrC;AACD;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as
|
|
2
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CollatedCommandData, c as CommandFlags, d as CommandFunction, e as CommandSetData, j as ContextCommandData, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData } from '../../modules.types-hjAYMYut.js';
|
|
3
3
|
import '../permissions/permissions.types.js';
|
|
4
4
|
import '../client/client.types.js';
|
|
5
|
+
import '../client/logger.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ChatInputCommandInteraction, Interaction, CacheType, InteractionReplyOptions, InteractionResponse, InteractionEditReplyOptions, Message, MessagePayload } from 'discord.js';
|
|
2
|
-
import { T as TriviousClient, S as SlashCommandData,
|
|
2
|
+
import { T as TriviousClient, S as SlashCommandData, c as CommandFlags } from '../../modules.types-hjAYMYut.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
|
+
import '../client/logger.js';
|
|
5
6
|
|
|
6
7
|
declare function interactionReply(options: {
|
|
7
8
|
interaction: Interaction<CacheType>;
|
|
@@ -78,7 +78,8 @@ async function handleSlashCommand(client, command, interaction) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
export {
|
|
82
|
+
handleSlashCommand,
|
|
83
|
+
interactionReply
|
|
84
|
+
};
|
|
84
85
|
//# sourceMappingURL=methods.commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/commands/methods.commands.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/methods.commands.ts"],"sourcesContent":["import { CommandFlags, SlashCommandData, TriviousClient } from \"@typings\";\nimport {\n\tCacheType,\n\tChatInputCommandInteraction,\n\tInteraction,\n\tInteractionEditReplyOptions,\n\tInteractionReplyOptions,\n\tInteractionResponse,\n\tMessage,\n\tMessagePayload,\n} from \"discord.js\";\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: InteractionReplyOptions;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}): Promise<InteractionResponse<boolean>>;\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: InteractionEditReplyOptions;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}): Promise<Message<boolean>>;\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: MessagePayload;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}): Promise<InteractionResponse<boolean> | Message<boolean>>;\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: InteractionReplyOptions | InteractionEditReplyOptions | MessagePayload;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}) {\n\tconst { interaction, replyPayload, flags } = options;\n\tif (!(\"reply\" in interaction)) return;\n\n\tconst payload = replyPayload as InteractionReplyOptions;\n\tif (flags?.includes(\"EphemeralReply\")) payload.flags = [\"Ephemeral\"];\n\n\tif (interaction.deferred || interaction.replied) {\n\t\tif (flags?.includes(\"FollowUp\")) return await interaction.followUp(payload);\n\t\treturn await interaction.editReply(payload as InteractionEditReplyOptions);\n\t}\n\n\treturn await interaction.reply(payload);\n}\n\nasync function handleFlags(interaction: ChatInputCommandInteraction, flags?: CommandFlags[]) {\n\tif (flags?.includes(\"Cached\") && !interaction.inCachedGuild()) return;\n\tif (flags?.includes(\"ExpectModal\")) return;\n\tif (flags?.includes(\"DeferReply\")) {\n\t\tawait interactionReply({\n\t\t\tinteraction,\n\t\t\tflags: flags,\n\t\t\treplyPayload: { content: \"Processing command...\" },\n\t\t});\n\t}\n}\n\nexport async function handleSlashCommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData,\n\tinteraction: ChatInputCommandInteraction\n) {\n\tconst { options } = interaction;\n\n\tconst subcommandGroup = options.getSubcommandGroup(false);\n\tconst subcommand = options.getSubcommand(false);\n\n\tif (!subcommandGroup && !subcommand) {\n\t\tawait handleFlags(interaction, command.flags);\n\n\t\tif (\"run\" in command && command.run) {\n\t\t\ttry {\n\t\t\t\tawait command.run(client, interaction);\n\t\t\t} catch (err: any) {\n\t\t\t\tconsole.error(err);\n\t\t\t}\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (subcommandGroup && command.subcommandGroups && subcommand) {\n\t\tconst foundGroup = command.subcommandGroups.get(subcommandGroup);\n\t\tif (!foundGroup) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: {\n\t\t\t\t\tcontent: \"Subcommand group is outdated, inactive, or does not have a handler!\",\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst foundSubcommand = foundGroup.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tawait handleFlags(interaction, foundSubcommand.flags || command.flags);\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t} else if (subcommand && command.subcommands) {\n\t\tconst foundSubcommand = command.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tawait handleFlags(interaction, foundSubcommand.flags || command.flags);\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t} else {\n\t\tawait interactionReply({\n\t\t\tinteraction,\n\t\t\tflags: [\"EphemeralReply\"],\n\t\t\treplyPayload: { content: \"Command is outdated, inactive, or does not have a handler!\" },\n\t\t});\n\t}\n}\n"],"mappings":"AA8BA,eAAsB,iBAAiB,SAIpC;AACF,QAAM,EAAE,aAAa,cAAc,MAAM,IAAI;AAC7C,MAAI,EAAE,WAAW,aAAc;AAE/B,QAAM,UAAU;AAChB,MAAI,OAAO,SAAS,gBAAgB,EAAG,SAAQ,QAAQ,CAAC,WAAW;AAEnE,MAAI,YAAY,YAAY,YAAY,SAAS;AAChD,QAAI,OAAO,SAAS,UAAU,EAAG,QAAO,MAAM,YAAY,SAAS,OAAO;AAC1E,WAAO,MAAM,YAAY,UAAU,OAAsC;AAAA,EAC1E;AAEA,SAAO,MAAM,YAAY,MAAM,OAAO;AACvC;AAEA,eAAe,YAAY,aAA0C,OAAwB;AAC5F,MAAI,OAAO,SAAS,QAAQ,KAAK,CAAC,YAAY,cAAc,EAAG;AAC/D,MAAI,OAAO,SAAS,aAAa,EAAG;AACpC,MAAI,OAAO,SAAS,YAAY,GAAG;AAClC,UAAM,iBAAiB;AAAA,MACtB;AAAA,MACA;AAAA,MACA,cAAc,EAAE,SAAS,wBAAwB;AAAA,IAClD,CAAC;AAAA,EACF;AACD;AAEA,eAAsB,mBACrB,QACA,SACA,aACC;AACD,QAAM,EAAE,QAAQ,IAAI;AAEpB,QAAM,kBAAkB,QAAQ,mBAAmB,KAAK;AACxD,QAAM,aAAa,QAAQ,cAAc,KAAK;AAE9C,MAAI,CAAC,mBAAmB,CAAC,YAAY;AACpC,UAAM,YAAY,aAAa,QAAQ,KAAK;AAE5C,QAAI,SAAS,WAAW,QAAQ,KAAK;AACpC,UAAI;AACH,cAAM,QAAQ,IAAI,QAAQ,WAAW;AAAA,MACtC,SAAS,KAAU;AAClB,gBAAQ,MAAM,GAAG;AAAA,MAClB;AAAA,IACD;AAEA;AAAA,EACD;AAEA,MAAI,mBAAmB,QAAQ,oBAAoB,YAAY;AAC9D,UAAM,aAAa,QAAQ,iBAAiB,IAAI,eAAe;AAC/D,QAAI,CAAC,YAAY;AAChB,YAAM,iBAAiB;AAAA,QACtB;AAAA,QACA,OAAO,CAAC,gBAAgB;AAAA,QACxB,cAAc;AAAA,UACb,SAAS;AAAA,QACV;AAAA,MACD,CAAC;AACD;AAAA,IACD;AAEA,UAAM,kBAAkB,WAAW,YAAY,IAAI,UAAU;AAC7D,QAAI,CAAC,iBAAiB;AACrB,YAAM,iBAAiB;AAAA,QACtB;AAAA,QACA,OAAO,CAAC,gBAAgB;AAAA,QACxB,cAAc,EAAE,SAAS,gEAAgE;AAAA,MAC1F,CAAC;AACD;AAAA,IACD;AAEA,UAAM,YAAY,aAAa,gBAAgB,SAAS,QAAQ,KAAK;AACrE,WAAO,MAAM,gBAAgB,QAAQ,QAAQ,WAAW;AAAA,EACzD,WAAW,cAAc,QAAQ,aAAa;AAC7C,UAAM,kBAAkB,QAAQ,YAAY,IAAI,UAAU;AAC1D,QAAI,CAAC,iBAAiB;AACrB,YAAM,iBAAiB;AAAA,QACtB;AAAA,QACA,OAAO,CAAC,gBAAgB;AAAA,QACxB,cAAc,EAAE,SAAS,gEAAgE;AAAA,MAC1F,CAAC;AACD;AAAA,IACD;AAEA,UAAM,YAAY,aAAa,gBAAgB,SAAS,QAAQ,KAAK;AACrE,WAAO,MAAM,gBAAgB,QAAQ,QAAQ,WAAW;AAAA,EACzD,OAAO;AACN,UAAM,iBAAiB;AAAA,MACtB;AAAA,MACA,OAAO,CAAC,gBAAgB;AAAA,MACxB,cAAc,EAAE,SAAS,6DAA6D;AAAA,IACvF,CAAC;AAAA,EACF;AACD;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-hjAYMYut.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
|
+
import '../client/logger.js';
|
|
5
6
|
|
|
6
7
|
declare function registerCommands(client: TriviousClient, directory: string): Promise<void>;
|
|
7
8
|
|
|
@@ -1,105 +1,117 @@
|
|
|
1
|
-
import { TriviousError } from
|
|
2
|
-
import { importFile } from
|
|
3
|
-
import { Collection
|
|
4
|
-
import { existsSync, promises } from
|
|
5
|
-
import path
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { TriviousError } from "../../utility/errors.js";
|
|
2
|
+
import { importFile } from "../../utility/functions.js";
|
|
3
|
+
import { Collection } from "discord.js";
|
|
4
|
+
import { existsSync, promises as fs } from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
async function parseBase(input, expects) {
|
|
7
|
+
let base = null;
|
|
8
|
+
if (typeof input === "string") {
|
|
9
|
+
base = await importFile(input);
|
|
10
|
+
} else base = input;
|
|
11
|
+
if (!base) return null;
|
|
12
|
+
if (expects && !expects(base)) return null;
|
|
13
|
+
return base;
|
|
11
14
|
}
|
|
12
|
-
async function
|
|
13
|
-
const
|
|
14
|
-
if (!("addSubcommand" in data.data)) return subcommands;
|
|
15
|
-
const files = promises.glob(join(directory, "./*.js"));
|
|
15
|
+
async function parseDirectory(data, directory) {
|
|
16
|
+
const files = fs.glob(path.join(directory, "*.{js,ts}"));
|
|
16
17
|
for await (const file of files) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
`[Trivious] Subcommand '${subcommand.data.name}' under ${data.context} '${data.data.name}' has a duplicate and has been overridden`
|
|
25
|
-
);
|
|
26
|
-
subcommands.set(subcommand.data.name, subcommand);
|
|
18
|
+
const base = await parseBase(
|
|
19
|
+
file,
|
|
20
|
+
(base2) => "context" in base2 && !!base2.context
|
|
21
|
+
);
|
|
22
|
+
if (!base) continue;
|
|
23
|
+
const targetSet = data[base.context];
|
|
24
|
+
if (targetSet) targetSet.add([base, directory]);
|
|
27
25
|
}
|
|
28
|
-
if (subcommands.size > 0) data.subcommands = subcommands;
|
|
29
|
-
return subcommands;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
function isSubdirectoryOf(directory, subdirectory) {
|
|
28
|
+
const relative = path.relative(path.resolve(directory), path.resolve(subdirectory));
|
|
29
|
+
return !!relative && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
30
|
+
}
|
|
31
|
+
function getDataFromCommandSet(set, options) {
|
|
32
|
+
const { matchData, matchParentDirectory } = options;
|
|
33
|
+
if (!matchData && !matchParentDirectory) return void 0;
|
|
34
|
+
const array = Array.from(set.entries());
|
|
35
|
+
let bestMatch;
|
|
36
|
+
let bestDepth = -1;
|
|
37
|
+
for (const entry of array) {
|
|
38
|
+
const [key, [data, directory]] = entry;
|
|
39
|
+
if (matchData && data === matchData) return key[0];
|
|
40
|
+
if (!matchParentDirectory) continue;
|
|
41
|
+
const isExact = directory === matchParentDirectory;
|
|
42
|
+
const isParent = isSubdirectoryOf(directory, matchParentDirectory);
|
|
43
|
+
if (isExact || isParent) {
|
|
44
|
+
const depth = directory.split(/\\|\//).length;
|
|
45
|
+
if (depth > bestDepth) {
|
|
46
|
+
bestDepth = depth;
|
|
47
|
+
bestMatch = entry[0];
|
|
48
|
+
}
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
|
-
return
|
|
51
|
+
return bestMatch?.[0];
|
|
56
52
|
}
|
|
57
|
-
async function
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!contextCommand || !validateCommand(
|
|
63
|
-
contextCommand,
|
|
64
|
-
(cmd) => cmd.commandType === ApplicationCommandType.Message || cmd.commandType === ApplicationCommandType.User
|
|
65
|
-
))
|
|
53
|
+
async function setChildrenToParents(data) {
|
|
54
|
+
for (const [group, directory] of data.SlashSubcommandGroup) {
|
|
55
|
+
const slashCommand = group.parent || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
56
|
+
if (!slashCommand || !("addSubcommandGroup" in slashCommand.data)) {
|
|
57
|
+
console.warn("[Trivious] Could not find parent for subcommand group", group.data.name);
|
|
66
58
|
continue;
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
}
|
|
60
|
+
if (!slashCommand.subcommandGroups) slashCommand.subcommandGroups = new Collection();
|
|
61
|
+
if (slashCommand.subcommandGroups.has(group.data.name))
|
|
62
|
+
console.warn(
|
|
63
|
+
`[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${slashCommand.data.name}' has been overridden by a group with the same name`
|
|
64
|
+
);
|
|
65
|
+
group.parent = slashCommand;
|
|
66
|
+
slashCommand.subcommandGroups.set(group.data.name, group);
|
|
67
|
+
slashCommand.data.addSubcommandGroup(group.data);
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (client.stores.commands.chatInput.has(slashCommand.data.name))
|
|
69
|
+
for (const [subcommand, directory] of data.SlashSubcommand) {
|
|
70
|
+
const parent = subcommand.parent || getDataFromCommandSet(data.SlashSubcommandGroup, { matchParentDirectory: directory }) || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
71
|
+
if (!parent || !("addSubcommand" in parent.data)) {
|
|
72
|
+
console.warn("[Trivious] Could not find parent for subcommand", subcommand.data.name);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!parent.subcommands) parent.subcommands = new Collection();
|
|
76
|
+
if (parent.subcommands.has(subcommand.data.name))
|
|
79
77
|
console.warn(
|
|
80
|
-
`[Trivious] SlashCommand '${
|
|
78
|
+
`[Trivious] Subcommand '${subcommand.data.name}' under SlashCommand/SubcommandGroup '${parent.data.name}' has been overridden by a subcommand with the same name`
|
|
81
79
|
);
|
|
82
|
-
|
|
80
|
+
subcommand.parent = parent;
|
|
81
|
+
parent.subcommands.set(subcommand.data.name, subcommand);
|
|
82
|
+
parent.data.addSubcommand(subcommand.data);
|
|
83
83
|
}
|
|
84
|
-
const contextCommands = await parseContextCommands(parentDir);
|
|
85
|
-
contextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));
|
|
86
84
|
}
|
|
87
85
|
async function registerCommands(client, directory) {
|
|
88
86
|
if (!existsSync(directory))
|
|
89
87
|
throw new TriviousError(
|
|
90
|
-
`Could not
|
|
88
|
+
`Could not regsiter commands; passed directory ${directory} does not exist`,
|
|
91
89
|
"Nonexistant directory passed"
|
|
92
90
|
);
|
|
93
91
|
const processedDirectories = /* @__PURE__ */ new Set();
|
|
94
|
-
const files =
|
|
92
|
+
const files = fs.glob(path.join(directory, "**/*.{js,ts}"));
|
|
93
|
+
const data = {
|
|
94
|
+
SlashCommand: /* @__PURE__ */ new Set(),
|
|
95
|
+
SlashSubcommand: /* @__PURE__ */ new Set(),
|
|
96
|
+
SlashSubcommandGroup: /* @__PURE__ */ new Set()
|
|
97
|
+
};
|
|
98
|
+
client.logger.debug("Starting command registration in:", directory);
|
|
95
99
|
for await (const file of files) {
|
|
96
100
|
const parentDir = path.dirname(file);
|
|
97
101
|
if (processedDirectories.has(parentDir)) continue;
|
|
98
102
|
processedDirectories.add(parentDir);
|
|
99
|
-
await
|
|
103
|
+
await parseDirectory(data, parentDir);
|
|
104
|
+
}
|
|
105
|
+
await setChildrenToParents(data);
|
|
106
|
+
for (const [slashCommand] of data.SlashCommand) {
|
|
107
|
+
if (client.stores.commands.chatInput.get(slashCommand.data.name))
|
|
108
|
+
client.logger.warn(
|
|
109
|
+
`Command '${slashCommand.data.name}' has been overridden by a command with the same name`
|
|
110
|
+
);
|
|
111
|
+
client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
114
|
+
export {
|
|
115
|
+
registerCommands as default
|
|
116
|
+
};
|
|
105
117
|
//# sourceMappingURL=registry.commands.js.map
|