trivious 2.2.4 → 2.3.0
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.js +0 -2
- package/dist/features/client/client.types.js.map +1 -1
- package/dist/features/client/deploy.client.d.ts +1 -1
- package/dist/features/client/deploy.client.js +8 -9
- package/dist/features/client/deploy.client.js.map +1 -1
- package/dist/features/client/trivious.client.d.ts +1 -1
- package/dist/features/client/trivious.client.js +8 -9
- package/dist/features/client/trivious.client.js.map +1 -1
- package/dist/features/commands/builders.commands.d.ts +5 -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 +1 -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 +1 -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 +1 -1
- package/dist/features/commands/registry.commands.js +92 -79
- package/dist/features/commands/registry.commands.js.map +1 -1
- package/dist/features/components/builders.components.d.ts +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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.d.ts +1 -3
- 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 +1 -1
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/{modules.types-lYoNHt-m.d.ts → modules.types-STECtgbF.d.ts} +12 -6
- package/dist/shared/registries.d.ts +1 -1
- package/dist/shared/registries.js +7 -8
- package/dist/shared/registries.js.map +1 -1
- package/dist/shared/typings.d.ts +1 -1
- package/dist/shared/typings.js +11 -9
- package/dist/shared/typings.js.map +1 -1
- package/dist/utility/errors.d.ts +1 -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 +9 -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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -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":[]}
|
|
@@ -1,9 +1,8 @@
|
|
|
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";
|
|
7
6
|
class TriviousClient extends Client {
|
|
8
7
|
trivious;
|
|
9
8
|
stores;
|
|
@@ -55,7 +54,7 @@ class TriviousClient extends Client {
|
|
|
55
54
|
await commandDeploy(this);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
export {
|
|
58
|
+
TriviousClient as default
|
|
59
|
+
};
|
|
61
60
|
//# 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\";\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\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\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;AAE1B,MAAO,uBAAqC,OAAO;AAAA,EAClD;AAAA,EACS;AAAA,EAUT,YAAY,SAAgC;AAC3C,UAAM,OAAO;AACb,SAAK,WAAW;AAEhB,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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as ContextCommandData, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData } from '../../modules.types-STECtgbF.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
@@ -7,13 +7,13 @@ declare function createSlashCommand(data: Omit<SlashCommandData, "context" | "co
|
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated Use createSlashSubcommand instead
|
|
9
9
|
*/
|
|
10
|
-
declare function createSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType"
|
|
11
|
-
declare function createSlashSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType"
|
|
10
|
+
declare function createSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType">): SlashSubcommandData;
|
|
11
|
+
declare function createSlashSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType">): SlashSubcommandData;
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated Use createSlashSubcommandGroup instead
|
|
14
14
|
*/
|
|
15
|
-
declare function createSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "
|
|
16
|
-
declare function createSlashSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "
|
|
15
|
+
declare function createSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "subcommands">): SlashSubcommandGroupData;
|
|
16
|
+
declare function createSlashSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "subcommands">): SlashSubcommandGroupData;
|
|
17
17
|
declare function createMessageContextCommand(data: Omit<ContextCommandData<"Message">, "commandType">): ContextCommandData<"Message">;
|
|
18
18
|
declare function createUserContextCommand(data: Omit<ContextCommandData<"User">, "commandType">): ContextCommandData<"User">;
|
|
19
19
|
|
|
@@ -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,4 @@
|
|
|
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-STECtgbF.js';
|
|
3
3
|
import '../permissions/permissions.types.js';
|
|
4
4
|
import '../client/client.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
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-STECtgbF.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
5
|
|
|
@@ -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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C7D,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,105 +1,118 @@
|
|
|
1
|
-
import { TriviousError } from
|
|
2
|
-
import { importFile } from
|
|
3
|
-
import { Collection
|
|
4
|
-
import { existsSync, promises } from
|
|
5
|
-
import path
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
if (typeof input !== "string") {
|
|
8
|
+
if (expects && !expects(input)) return null;
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
if (!existsSync(input)) return null;
|
|
12
|
+
const base = await importFile(input);
|
|
13
|
+
if (!base) return null;
|
|
14
|
+
if (expects && !expects(base)) return null;
|
|
15
|
+
return base;
|
|
11
16
|
}
|
|
12
|
-
async function
|
|
13
|
-
const
|
|
14
|
-
if (!("addSubcommand" in data.data)) return subcommands;
|
|
15
|
-
const files = promises.glob(join(directory, "./*.js"));
|
|
17
|
+
async function parseDirectory(data, directory) {
|
|
18
|
+
const files = fs.glob(path.join(directory, "*.{js,ts}"));
|
|
16
19
|
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);
|
|
20
|
+
const base = await parseBase(
|
|
21
|
+
file,
|
|
22
|
+
(base2) => "context" in base2 && !!base2.context
|
|
23
|
+
);
|
|
24
|
+
if (!base) continue;
|
|
25
|
+
const targetSet = data[base.context];
|
|
26
|
+
if (targetSet) targetSet.add([base, directory]);
|
|
27
27
|
}
|
|
28
|
-
if (subcommands.size > 0) data.subcommands = subcommands;
|
|
29
|
-
return subcommands;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
29
|
+
function isSubdirectoryOf(directory, subdirectory) {
|
|
30
|
+
const relative = path.relative(path.resolve(directory), path.resolve(subdirectory));
|
|
31
|
+
return !!relative && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
32
|
+
}
|
|
33
|
+
function getDataFromCommandSet(set, options) {
|
|
34
|
+
const { matchData, matchParentDirectory } = options;
|
|
35
|
+
if (!matchData && !matchParentDirectory) return void 0;
|
|
36
|
+
const array = Array.from(set.entries());
|
|
37
|
+
let bestMatch;
|
|
38
|
+
let bestDepth = -1;
|
|
39
|
+
for (const entry of array) {
|
|
40
|
+
const [key, [data, directory]] = entry;
|
|
41
|
+
if (matchData && data === matchData) return key[0];
|
|
42
|
+
if (!matchParentDirectory) continue;
|
|
43
|
+
const isExact = directory === matchParentDirectory;
|
|
44
|
+
const isParent = isSubdirectoryOf(directory, matchParentDirectory);
|
|
45
|
+
if (isExact || isParent) {
|
|
46
|
+
const depth = directory.split(/\\|\//).length;
|
|
47
|
+
if (depth > bestDepth) {
|
|
48
|
+
bestDepth = depth;
|
|
49
|
+
bestMatch = entry[0];
|
|
50
|
+
}
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
return
|
|
53
|
+
return bestMatch?.[0];
|
|
56
54
|
}
|
|
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
|
-
))
|
|
55
|
+
async function setChildrenToParents(data) {
|
|
56
|
+
for (const [group, directory] of data.SlashSubcommandGroup) {
|
|
57
|
+
const slashCommand = group.parent || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
58
|
+
if (!slashCommand || !("addSubcommandGroup" in slashCommand.data)) {
|
|
59
|
+
console.warn("[Trivious] Could not find parent for subcommand group", group.data.name);
|
|
66
60
|
continue;
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
}
|
|
62
|
+
if (!slashCommand.subcommandGroups) slashCommand.subcommandGroups = new Collection();
|
|
63
|
+
if (slashCommand.subcommandGroups.has(group.data.name))
|
|
64
|
+
console.warn(
|
|
65
|
+
`[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${slashCommand.data.name}' has been overridden by a group with the same name`
|
|
66
|
+
);
|
|
67
|
+
group.parent = slashCommand;
|
|
68
|
+
slashCommand.subcommandGroups.set(group.data.name, group);
|
|
69
|
+
slashCommand.data.addSubcommandGroup(group.data);
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (client.stores.commands.chatInput.has(slashCommand.data.name))
|
|
71
|
+
for (const [subcommand, directory] of data.SlashSubcommand) {
|
|
72
|
+
const parent = subcommand.parent || getDataFromCommandSet(data.SlashSubcommandGroup, { matchParentDirectory: directory }) || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
73
|
+
if (!parent || !("addSubcommand" in parent.data)) {
|
|
74
|
+
console.warn("[Trivious] Could not find parent for subcommand", subcommand.data.name);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (!parent.subcommands) parent.subcommands = new Collection();
|
|
78
|
+
if (parent.subcommands.has(subcommand.data.name))
|
|
79
79
|
console.warn(
|
|
80
|
-
`[Trivious] SlashCommand '${
|
|
80
|
+
`[Trivious] Subcommand '${subcommand.data.name}' under SlashCommand/SubcommandGroup '${parent.data.name}' has been overridden by a subcommand with the same name`
|
|
81
81
|
);
|
|
82
|
-
|
|
82
|
+
subcommand.parent = parent;
|
|
83
|
+
parent.subcommands.set(subcommand.data.name, subcommand);
|
|
84
|
+
parent.data.addSubcommand(subcommand.data);
|
|
83
85
|
}
|
|
84
|
-
const contextCommands = await parseContextCommands(parentDir);
|
|
85
|
-
contextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));
|
|
86
86
|
}
|
|
87
87
|
async function registerCommands(client, directory) {
|
|
88
88
|
if (!existsSync(directory))
|
|
89
89
|
throw new TriviousError(
|
|
90
|
-
`Could not
|
|
90
|
+
`Could not regsiter commands; passed directory ${directory} does not exist`,
|
|
91
91
|
"Nonexistant directory passed"
|
|
92
92
|
);
|
|
93
93
|
const processedDirectories = /* @__PURE__ */ new Set();
|
|
94
|
-
const files =
|
|
94
|
+
const files = fs.glob(path.join(directory, "**/*.{js,ts}"));
|
|
95
|
+
const data = {
|
|
96
|
+
SlashCommand: /* @__PURE__ */ new Set(),
|
|
97
|
+
SlashSubcommand: /* @__PURE__ */ new Set(),
|
|
98
|
+
SlashSubcommandGroup: /* @__PURE__ */ new Set()
|
|
99
|
+
};
|
|
95
100
|
for await (const file of files) {
|
|
96
101
|
const parentDir = path.dirname(file);
|
|
97
102
|
if (processedDirectories.has(parentDir)) continue;
|
|
98
103
|
processedDirectories.add(parentDir);
|
|
99
|
-
await
|
|
104
|
+
await parseDirectory(data, parentDir);
|
|
105
|
+
}
|
|
106
|
+
await setChildrenToParents(data);
|
|
107
|
+
for (const [slashCommand] of data.SlashCommand) {
|
|
108
|
+
if (client.stores.commands.chatInput.get(slashCommand.data.name))
|
|
109
|
+
console.warn(
|
|
110
|
+
`[Trivious] Command '${slashCommand.data.name}' has been overridden by a command with the same name`
|
|
111
|
+
);
|
|
112
|
+
client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
export {
|
|
116
|
+
registerCommands as default
|
|
117
|
+
};
|
|
105
118
|
//# sourceMappingURL=registry.commands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"names":["fs"],"mappings":";;;;;;AAcA,SAAS,eAAA,CACR,SACA,OAAA,EACU;AACV,EAAA,IAAI,EAAE,QAAA,IAAY,OAAA,IAAW,aAAA,IAAiB,UAAU,OAAO,KAAA;AAC/D,EAAA,IAAI,CAAC,OAAA,CAAQ,M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,SAAS,CAAA;AAElC,IAAA,MAAM,iBAAA,CAAkB,QAAQ,SAAS,CAAA;AAAA,EAC1C;AACD","file":"registry.commands.js","sourcesContent":["import {\n\tBaseChatInputCommandData,\n\tContextCommandData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n\tTriviousClient,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport { importFile } from \"#utility/functions.js\";\nimport { ApplicationCommandType, Collection } from \"discord.js\";\nimport { Dirent, existsSync, promises as fs } from \"fs\";\nimport path, { join } from \"path\";\n\nfunction validateCommand<T extends BaseChatInputCommandData | ContextCommandData>(\n\tcommand: T,\n\texpects: (command: Partial<T>) => boolean\n): boolean {\n\tif (!(\"active\" in command && \"commandType\" in command)) return false;\n\tif (!command.active) return false;\n\treturn expects(command);\n}\n\nasync function parseSlashSubcommands(\n\tdirectory: string,\n\tdata: SlashCommandData | SlashSubcommandGroupData<boolean>\n) {\n\tconst _parentType = \"context\" in data ? \"command\" : \"group\";\n\tconst subcommands = new Collection<string, SlashSubcommandData<typeof _parentType, true>>();\n\n\tif (!(\"addSubcommand\" in data.data)) return subcommands;\n\n\tconst files = fs.glob(join(directory, \"./*.js\"));\n\tfor await (const file of files) {\n\t\tconst subcommand = await importFile<SlashSubcommandData<typeof _parentType, true>>(file);\n\t\tif (\n\t\t\t!subcommand ||\n\t\t\t!validateCommand(subcommand, (subcmd) => subcmd.context === \"SlashSubcommand\")\n\t\t)\n\t\t\tcontinue;\n\n\t\tsubcommand.parent = data;\n\t\tdata.data.addSubcommand(subcommand.data);\n\n\t\tif (subcommands.has(subcommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Subcommand '${subcommand.data.name}' under ${data.context} '${data.data.name}' has a duplicate and has been overridden`\n\t\t\t);\n\t\tsubcommands.set(subcommand.data.name, subcommand);\n\t}\n\n\tif (subcommands.size > 0) data.subcommands = subcommands;\n\treturn subcommands;\n}\n\nasync function parseSlashCommand(\n\tfile: string,\n\tparentDir: string,\n\tsubdirectories: Dirent<string>[]\n) {\n\tif (!existsSync(file)) return;\n\n\tconst command = await importFile<SlashCommandData>(file);\n\tif (\n\t\t!command ||\n\t\t!validateCommand(command, (cmd) => cmd.context === \"SlashCommand\") ||\n\t\t!(\"addSubcommand\" in command.data)\n\t)\n\t\treturn;\n\n\tawait parseSlashSubcommands(parentDir, command);\n\n\tfor (const subdir of subdirectories) {\n\t\tconst indexFile = path.resolve(subdir.parentPath, subdir.name, \"index.js\");\n\t\tif (!existsSync(indexFile)) continue;\n\n\t\tconst group = await importFile<SlashSubcommandGroupData<true>>(indexFile);\n\t\tif (\n\t\t\t!group ||\n\t\t\t!(\"context\" in group && \"addSubcommandGroup\" in command.data) ||\n\t\t\tgroup.context !== \"SlashSubcommandGroup\"\n\t\t)\n\t\t\tcontinue;\n\n\t\tgroup.parent = command;\n\t\tif (!command.subcommandGroups) command.subcommandGroups = new Collection();\n\t\tawait parseSlashSubcommands(join(subdir.parentPath, subdir.name), group);\n\n\t\tif (group.subcommands.size > 0) {\n\t\t\tif (command.subcommandGroups.has(group.data.name))\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${command.data.name}' has a duplicate and has been overridden`\n\t\t\t\t);\n\n\t\t\tcommand.data.addSubcommandGroup(group.data);\n\t\t\tcommand.subcommandGroups.set(group.data.name, group);\n\t\t}\n\t}\n\n\treturn command;\n}\n\nasync function parseContextCommands(parentDir: string) {\n\tconst collection = new Collection<string, ContextCommandData>();\n\tconst files = fs.glob(join(parentDir, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst contextCommand = await importFile<ContextCommandData>(file);\n\t\tif (\n\t\t\t!contextCommand ||\n\t\t\t!validateCommand(\n\t\t\t\tcontextCommand,\n\t\t\t\t(cmd) =>\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.Message ||\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.User\n\t\t\t)\n\t\t)\n\t\t\tcontinue;\n\n\t\tcontextCommand.data.setType(contextCommand.commandType);\n\t\tcollection.set(contextCommand.data.name, contextCommand);\n\t}\n\n\treturn collection;\n}\n\nasync function registerDirectory(client: TriviousClient, parentDir: string) {\n\tconst entries = await fs.readdir(parentDir, { withFileTypes: true });\n\tconst subdirectories = entries.filter((entry) => entry.isDirectory());\n\n\tconst indexFile = path.resolve(parentDir, \"index.js\");\n\tconst slashCommand = await parseSlashCommand(indexFile, parentDir, subdirectories);\n\tif (slashCommand) {\n\t\tif (client.stores.commands.chatInput.has(slashCommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] SlashCommand '${slashCommand.data.name}' has a duplicate and has been overridden`\n\t\t\t);\n\n\t\tclient.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\t}\n\n\tconst contextCommands = await parseContextCommands(parentDir);\n\tcontextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));\n}\n\nexport default async function registerCommands(client: TriviousClient, directory: string) {\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register commands; passed directory '${directory}' does not exist!`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\n\tconst processedDirectories = new Set<string>();\n\n\tconst files = fs.glob(join(directory, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst parentDir = path.dirname(file);\n\n\t\tif (processedDirectories.has(parentDir)) continue;\n\t\tprocessedDirectories.add(parentDir);\n\n\t\tawait registerDirectory(client, parentDir);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"sourcesContent":["import {\n\tCollatedCommandData,\n\tCommandSetData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n\tTriviousClient,\n} from \"@typings\";\nimport { TriviousError } from \"@utility/errors.js\";\nimport { importFile } from \"@utility/functions.js\";\nimport { Collection } from \"discord.js\";\nimport { existsSync, promises as fs } from \"fs\";\nimport path from \"path\";\n\nasync function parseBase<T>(input: string | T, expects?: (base: Partial<T>) => boolean) {\n\tif (typeof input !== \"string\") {\n\t\tif (expects && !expects(input)) return null;\n\t\treturn input;\n\t}\n\tif (!existsSync(input)) return null;\n\tconst base = await importFile<T>(input);\n\tif (!base) return null;\n\tif (expects && !expects(base)) return null;\n\treturn base;\n}\n\nasync function parseDirectory(data: CollatedCommandData, directory: string): Promise<void> {\n\tconst files = fs.glob(path.join(directory, \"*.{js,ts}\"));\n\tfor await (const file of files) {\n\t\tconst base = await parseBase<SlashCommandData | SlashSubcommandData | SlashSubcommandGroupData>(\n\t\t\tfile,\n\t\t\t(base) => \"context\" in base && !!base.context\n\t\t);\n\t\tif (!base) continue;\n\t\tconst targetSet = data[base.context];\n\t\tif (targetSet) (targetSet as Set<[typeof base, string]>).add([base, directory]);\n\t}\n}\n\nfunction isSubdirectoryOf(directory: string, subdirectory: string) {\n\tconst relative = path.relative(path.resolve(directory), path.resolve(subdirectory));\n\treturn !!relative && !relative.startsWith(\"..\") && !path.isAbsolute(relative);\n}\n\nfunction getDataFromCommandSet<Data>(\n\tset: Set<CommandSetData<Data>>,\n\toptions: { matchParentDirectory?: string; matchData?: Partial<Data> }\n) {\n\tconst { matchData, matchParentDirectory } = options;\n\tif (!matchData && !matchParentDirectory) return undefined;\n\tconst array = Array.from(set.entries());\n\tlet bestMatch: CommandSetData<Data> | undefined;\n\tlet bestDepth = -1;\n\n\tfor (const entry of array) {\n\t\tconst [key, [data, directory]] = entry;\n\t\tif (matchData && data === matchData) return key[0];\n\t\tif (!matchParentDirectory) continue;\n\t\tconst isExact = directory === matchParentDirectory;\n\t\tconst isParent = isSubdirectoryOf(directory, matchParentDirectory);\n\t\tif (isExact || isParent) {\n\t\t\tconst depth = directory.split(/\\\\|\\//).length;\n\t\t\tif (depth > bestDepth) {\n\t\t\t\tbestDepth = depth;\n\t\t\t\tbestMatch = entry[0];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn bestMatch?.[0];\n}\n\nasync function setChildrenToParents(data: CollatedCommandData) {\n\tfor (const [group, directory] of data.SlashSubcommandGroup) {\n\t\tconst slashCommand =\n\t\t\tgroup.parent || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });\n\n\t\tif (!slashCommand || !(\"addSubcommandGroup\" in slashCommand.data)) {\n\t\t\tconsole.warn(\"[Trivious] Could not find parent for subcommand group\", group.data.name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!slashCommand.subcommandGroups) slashCommand.subcommandGroups = new Collection();\n\t\tif (slashCommand.subcommandGroups.has(group.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${slashCommand.data.name}' has been overridden by a group with the same name`\n\t\t\t);\n\t\tgroup.parent = slashCommand;\n\t\tslashCommand.subcommandGroups.set(group.data.name, group);\n\t\tslashCommand.data.addSubcommandGroup(group.data);\n\t}\n\n\tfor (const [subcommand, directory] of data.SlashSubcommand) {\n\t\tconst parent =\n\t\t\tsubcommand.parent ||\n\t\t\tgetDataFromCommandSet(data.SlashSubcommandGroup, { matchParentDirectory: directory }) ||\n\t\t\tgetDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });\n\n\t\tif (!parent || !(\"addSubcommand\" in parent.data)) {\n\t\t\tconsole.warn(\"[Trivious] Could not find parent for subcommand\", subcommand.data.name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!parent.subcommands) parent.subcommands = new Collection();\n\t\tif (parent.subcommands.has(subcommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Subcommand '${subcommand.data.name}' under SlashCommand/SubcommandGroup '${parent.data.name}' has been overridden by a subcommand with the same name`\n\t\t\t);\n\t\tsubcommand.parent = parent;\n\t\tparent.subcommands.set(subcommand.data.name, subcommand);\n\t\tparent.data.addSubcommand(subcommand.data);\n\t}\n}\n\nexport default async function registerCommands(client: TriviousClient, directory: string) {\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not regsiter commands; passed directory ${directory} does not exist`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\tconst processedDirectories = new Set<string>();\n\tconst files = fs.glob(path.join(directory, \"**/*.{js,ts}\"));\n\tconst data: CollatedCommandData = {\n\t\tSlashCommand: new Set<CommandSetData<SlashCommandData>>(),\n\t\tSlashSubcommand: new Set<CommandSetData<SlashSubcommandData>>(),\n\t\tSlashSubcommandGroup: new Set<CommandSetData<SlashSubcommandGroupData>>(),\n\t};\n\tfor await (const file of files) {\n\t\tconst parentDir = path.dirname(file);\n\t\tif (processedDirectories.has(parentDir)) continue;\n\t\tprocessedDirectories.add(parentDir);\n\t\tawait parseDirectory(data, parentDir);\n\t}\n\tawait setChildrenToParents(data);\n\tfor (const [slashCommand] of data.SlashCommand) {\n\t\tif (client.stores.commands.chatInput.get(slashCommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Command '${slashCommand.data.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tclient.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\t}\n}\n"],"mappings":"AAQA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,YAAY,YAAY,UAAU;AAC3C,OAAO,UAAU;AAEjB,eAAe,UAAa,OAAmB,SAAyC;AACvF,MAAI,OAAO,UAAU,UAAU;AAC9B,QAAI,WAAW,CAAC,QAAQ,KAAK,EAAG,QAAO;AACvC,WAAO;AAAA,EACR;AACA,MAAI,CAAC,WAAW,KAAK,EAAG,QAAO;AAC/B,QAAM,OAAO,MAAM,WAAc,KAAK;AACtC,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI,WAAW,CAAC,QAAQ,IAAI,EAAG,QAAO;AACtC,SAAO;AACR;AAEA,eAAe,eAAe,MAA2B,WAAkC;AAC1F,QAAM,QAAQ,GAAG,KAAK,KAAK,KAAK,WAAW,WAAW,CAAC;AACvD,mBAAiB,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AK,KAAK,KAAK,WAAW,cAAc,CAAC;AAC1D,QAAM,OAA4B;AAAA,IACjC,cAAc,oBAAI,IAAsC;AAAA,IACxD,iBAAiB,oBAAI,IAAyC;AAAA,IAC9D,sBAAsB,oBAAI,IAA8C;AAAA,EACzE;AACA,mBAAiB,QAAQ,OAAO;AAC/B,UAAM,YAAY,KAAK,QAAQ,IAAI;AACnC,QAAI,qBAAqB,IAAI,SAAS,EAAG;AACzC,yBAAqB,IAAI,SAAS;AAClC,UAAM,eAAe,MAAM,SAAS;AAAA,EACrC;AACA,QAAM,qBAAqB,IAAI;AAC/B,aAAW,CAAC,YAAY,KAAK,KAAK,cAAc;AAC/C,QAAI,OAAO,OAAO,SAAS,UAAU,IAAI,aAAa,KAAK,IAAI;AAC9D,cAAQ;AAAA,QACP,uBAAuB,aAAa,KAAK,IAAI;AAAA,MAC9C;AACD,WAAO,OAAO,SAAS,UAAU,IAAI,aAAa,KAAK,MAAM,YAAY;AAAA,EAC1E;AACD;","names":["base"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as Component, g as ComponentContext } from '../../modules.types-STECtgbF.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ComponentContext } from
|
|
2
|
-
|
|
1
|
+
import { ComponentContext } from "../../shared/typings.js";
|
|
3
2
|
function createComponent(data) {
|
|
4
3
|
return data;
|
|
5
4
|
}
|
|
@@ -21,7 +20,10 @@ function createModalComponent(data) {
|
|
|
21
20
|
...data
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export {
|
|
24
|
+
createButtonComponent,
|
|
25
|
+
createComponent,
|
|
26
|
+
createModalComponent,
|
|
27
|
+
createSelectMenuComponent
|
|
28
|
+
};
|
|
27
29
|
//# sourceMappingURL=builders.components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/components/builders.components.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/components/builders.components.ts"],"sourcesContent":["import { Component, ComponentContext } from \"@typings\";\n\n/**\n * Create component handler\n * @param data Component data\n * @returns Component\n */\nexport function createComponent<Context extends ComponentContext = ComponentContext>(\n\tdata: Component<Context>\n): Component<Context> {\n\treturn data;\n}\n\n/**\n * Create a button component handler\n * @param data Component data\n * @returns Button Component\n */\nexport function createButtonComponent(\n\tdata: Omit<Component<ComponentContext.Button>, \"context\" | \"component\">\n): Component<ComponentContext.Button> {\n\treturn {\n\t\tcontext: ComponentContext.Button,\n\t\t...data,\n\t};\n}\n\n/**\n * Create a select menu component handler\n * @param data Component data\n * @returns AnySelectMenu Component\n */\nexport function createSelectMenuComponent(\n\tdata: Omit<Component<ComponentContext.SelectMenu>, \"context\" | \"component\">\n): Component<ComponentContext.SelectMenu> {\n\treturn {\n\t\tcontext: ComponentContext.SelectMenu,\n\t\t...data,\n\t};\n}\n\n/**\n * Create a modal component handler\n * @param data Component data\n * @returns Modal Component\n */\nexport function createModalComponent(\n\tdata: Omit<Component<ComponentContext.Modal>, \"context\" | \"component\">\n): Component<ComponentContext.Modal> {\n\treturn {\n\t\tcontext: ComponentContext.Modal,\n\t\t...data,\n\t};\n}\n"],"mappings":"AAAA,SAAoB,wBAAwB;AAOrC,SAAS,gBACf,MACqB;AACrB,SAAO;AACR;AAOO,SAAS,sBACf,MACqC;AACrC,SAAO;AAAA,IACN,SAAS,iBAAiB;AAAA,IAC1B,GAAG;AAAA,EACJ;AACD;AAOO,SAAS,0BACf,MACyC;AACzC,SAAO;AAAA,IACN,SAAS,iBAAiB;AAAA,IAC1B,GAAG;AAAA,EACJ;AACD;AAOO,SAAS,qBACf,MACoC;AACpC,SAAO;AAAA,IACN,SAAS,iBAAiB;AAAA,IAC1B,GAAG;AAAA,EACJ;AACD;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export {
|
|
2
|
+
export { f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction } from '../../modules.types-STECtgbF.js';
|
|
3
3
|
import '../permissions/permissions.types.js';
|
|
4
4
|
import '../client/client.types.js';
|