trivious 1.5.12 → 1.6.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/core/builders/util.builders.js.map +1 -1
- package/dist/core/client/trivious.client.d.ts +4 -1
- package/dist/core/client/trivious.client.js +8 -3
- package/dist/core/client/trivious.client.js.map +1 -1
- package/dist/core/commands/methods.command.d.ts +45 -0
- package/dist/core/commands/methods.command.js +51 -0
- package/dist/core/commands/methods.command.js.map +1 -0
- package/dist/core/components/component.base.d.ts +7 -2
- package/dist/core/events/clientReady.d.ts +4 -1
- package/dist/core/events/interactionCreate.d.ts +6 -2
- package/dist/core/events/interactionCreate.js +21 -11
- package/dist/core/events/interactionCreate.js.map +1 -1
- package/dist/core/registry/command.registry.d.ts +4 -1
- package/dist/core/registry/command.registry.js +4 -4
- package/dist/core/registry/command.registry.js.map +1 -1
- package/dist/core/registry/component.registry.d.ts +4 -1
- package/dist/core/registry/component.registry.js.map +1 -1
- package/dist/core/registry/event.registry.d.ts +4 -1
- package/dist/core/registry/index.d.ts +5 -2
- package/dist/core/registry/module.registry.d.ts +4 -1
- package/dist/index-BqxT-x7T.d.ts +341 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +0 -2
- package/dist/shared/typings/client.d.ts +74 -4
- package/dist/shared/typings/commands.d.ts +4 -1
- package/dist/shared/typings/components.d.ts +40 -4
- package/dist/shared/typings/components.js +1 -14
- package/dist/shared/typings/components.js.map +1 -1
- package/dist/shared/typings/events.d.ts +4 -1
- package/dist/shared/typings/index.d.ts +4 -1
- package/dist/shared/typings/module.d.ts +4 -1
- package/dist/shared/typings/permissions.d.ts +16 -4
- package/dist/shared/typings/permissions.js +1 -7
- package/dist/shared/typings/permissions.js.map +1 -1
- package/dist/shared/utility/components.utility.d.ts +19 -0
- package/dist/shared/utility/components.utility.js +17 -0
- package/dist/shared/utility/components.utility.js.map +1 -0
- package/dist/shared/utility/functions.d.ts +4 -1
- package/dist/shared/utility/functions.js +2 -1
- package/dist/shared/utility/functions.js.map +1 -1
- package/dist/shared/utility/permissions.utility.d.ts +17 -0
- package/dist/shared/utility/permissions.utility.js +12 -0
- package/dist/shared/utility/permissions.utility.js.map +1 -0
- package/package.json +1 -1
- package/dist/core/builders/util.builders.cjs +0 -15
- package/dist/core/builders/util.builders.cjs.map +0 -1
- package/dist/core/builders/util.builders.d.cts +0 -21
- package/dist/core/client/trivious.client.cjs +0 -114
- package/dist/core/client/trivious.client.cjs.map +0 -1
- package/dist/core/client/trivious.client.d.cts +0 -4
- package/dist/core/commands/command.base.cjs +0 -352
- package/dist/core/commands/command.base.cjs.map +0 -1
- package/dist/core/commands/command.base.d.cts +0 -4
- package/dist/core/commands/command.base.d.ts +0 -4
- package/dist/core/commands/command.base.js +0 -344
- package/dist/core/commands/command.base.js.map +0 -1
- package/dist/core/commands/subcommand.base.cjs +0 -139
- package/dist/core/commands/subcommand.base.cjs.map +0 -1
- package/dist/core/commands/subcommand.base.d.cts +0 -4
- package/dist/core/commands/subcommand.base.d.ts +0 -4
- package/dist/core/commands/subcommand.base.js +0 -134
- package/dist/core/commands/subcommand.base.js.map +0 -1
- package/dist/core/components/component.base.cjs +0 -4
- package/dist/core/components/component.base.cjs.map +0 -1
- package/dist/core/components/component.base.d.cts +0 -2
- package/dist/core/events/clientReady.cjs +0 -12
- package/dist/core/events/clientReady.cjs.map +0 -1
- package/dist/core/events/clientReady.d.cts +0 -11
- package/dist/core/events/interactionCreate.cjs +0 -80
- package/dist/core/events/interactionCreate.cjs.map +0 -1
- package/dist/core/events/interactionCreate.d.cts +0 -11
- package/dist/core/registry/command.registry.cjs +0 -60
- package/dist/core/registry/command.registry.cjs.map +0 -1
- package/dist/core/registry/command.registry.d.cts +0 -4
- package/dist/core/registry/component.registry.cjs +0 -47
- package/dist/core/registry/component.registry.cjs.map +0 -1
- package/dist/core/registry/component.registry.d.cts +0 -4
- package/dist/core/registry/event.registry.cjs +0 -77
- package/dist/core/registry/event.registry.cjs.map +0 -1
- package/dist/core/registry/event.registry.d.cts +0 -4
- package/dist/core/registry/index.cjs +0 -49
- package/dist/core/registry/index.cjs.map +0 -1
- package/dist/core/registry/index.d.cts +0 -20
- package/dist/core/registry/module.registry.cjs +0 -61
- package/dist/core/registry/module.registry.cjs.map +0 -1
- package/dist/core/registry/module.registry.d.cts +0 -4
- package/dist/index-6Un9NsKu.d.ts +0 -897
- package/dist/index-CYy6VZT0.d.cts +0 -897
- package/dist/index.cjs +0 -78
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/shared/typings/client.cjs +0 -4
- package/dist/shared/typings/client.cjs.map +0 -1
- package/dist/shared/typings/client.d.cts +0 -4
- package/dist/shared/typings/commands.cjs +0 -4
- package/dist/shared/typings/commands.cjs.map +0 -1
- package/dist/shared/typings/commands.d.cts +0 -4
- package/dist/shared/typings/components.cjs +0 -27
- package/dist/shared/typings/components.cjs.map +0 -1
- package/dist/shared/typings/components.d.cts +0 -4
- package/dist/shared/typings/events.cjs +0 -4
- package/dist/shared/typings/events.cjs.map +0 -1
- package/dist/shared/typings/events.d.cts +0 -4
- package/dist/shared/typings/index.cjs +0 -56
- package/dist/shared/typings/index.cjs.map +0 -1
- package/dist/shared/typings/index.d.cts +0 -4
- package/dist/shared/typings/module.cjs +0 -4
- package/dist/shared/typings/module.cjs.map +0 -1
- package/dist/shared/typings/module.d.cts +0 -4
- package/dist/shared/typings/permissions.cjs +0 -22
- package/dist/shared/typings/permissions.cjs.map +0 -1
- package/dist/shared/typings/permissions.d.cts +0 -4
- package/dist/shared/typings/registry.cjs +0 -63
- package/dist/shared/typings/registry.cjs.map +0 -1
- package/dist/shared/typings/registry.d.cts +0 -51
- package/dist/shared/utility/functions.cjs +0 -88
- package/dist/shared/utility/functions.cjs.map +0 -1
- package/dist/shared/utility/functions.d.cts +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/builders/util.builders.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"sources":["../../../src/core/builders/util.builders.ts"],"names":[],"mappings":";;AAgBO,SAAS,mBAA+D,QAAA,EAAe;AAC7F,EAAA,OAAO,IAAI,gBAAA,EAAoB,CAAE,aAAA,CAAc,GAAG,QAAQ,CAAA;AAC3D;AASO,SAAS,YAAY,IAAA,EAA6B;AACxD,EAAA,OAAO,IAAI,aAAa,IAAI,CAAA;AAC7B","file":"util.builders.js","sourcesContent":["import {\n\tActionRowBuilder,\n\tAPIEmbed,\n\tEmbedBuilder,\n\tEmbedData,\n\tMessageActionRowComponentBuilder,\n} from \"discord.js\";\n\n/**\n * Utility action row builder\n *\n * @export\n * @template {MessageActionRowComponentBuilder} T\n * @param {...T[]} builders\n * @returns {*}\n */\nexport function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]) {\n\treturn new ActionRowBuilder<T>().setComponents(...builders);\n}\n\n/**\n * Utility embed builder\n *\n * @export\n * @param {?(EmbedData | APIEmbed)} [data]\n * @returns {*}\n */\nexport function createEmbed(data?: EmbedData | APIEmbed) {\n\treturn new EmbedBuilder(data);\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export { T as default } from '../../index-
|
|
1
|
+
export { T as default } from '../../index-BqxT-x7T.js';
|
|
2
2
|
import 'discord.js';
|
|
3
|
+
import '../../shared/typings/permissions.js';
|
|
4
|
+
import '../../shared/typings/client.js';
|
|
3
5
|
import '../../shared/typings/registry.js';
|
|
6
|
+
import '../../shared/typings/components.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Client, REST, Routes } from 'discord.js';
|
|
2
2
|
import { registries } from '../registry/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { exists } from '../../shared/utility/functions.js';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
6
7
|
|
|
7
8
|
class TriviousClient extends Client {
|
|
8
9
|
/**
|
|
@@ -69,10 +70,14 @@ class TriviousClient extends Client {
|
|
|
69
70
|
const token = process.env[this._options.tokenReference];
|
|
70
71
|
if (!clientId || !token) throw new Error("[Trivious] Invalid clientId or token reference");
|
|
71
72
|
const commands = Array.from(this.registries.commands.get().values());
|
|
72
|
-
const body = [
|
|
73
|
+
const body = [
|
|
74
|
+
...commands.map(
|
|
75
|
+
(command) => "data" in command ? command.data.toJSON() : null
|
|
76
|
+
)
|
|
77
|
+
].filter((c) => c !== null);
|
|
73
78
|
if (commandHashConfig && commandHashConfig.enabled) {
|
|
74
79
|
const hashFile = path.join(commandHashConfig.filePath || "data", "commands.hash");
|
|
75
|
-
const newHash =
|
|
80
|
+
const newHash = createHash("sha256").update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString()).digest("hex");
|
|
76
81
|
let oldHash = "";
|
|
77
82
|
if (await exists(hashFile)) oldHash = readFileSync(hashFile, "utf-8");
|
|
78
83
|
if (newHash === oldHash) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/client/trivious.client.ts"],"names":["registries"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/core/client/trivious.client.ts"],"names":["registries"],"mappings":";;;;;;;AAqBA,MAAO,uBAAqC,MAAA,CAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzC,aAAa,UAAA,EAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QAAA,GAAW;AAChB,IAAA,MAAM,EAAE,UAAA,EAAAA,WAAAA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AEA,MAAA,aAAA,CAAc,QAAA,EAAU,OAAA,EAAS,EAAE,QAAA,EAAU,SAAS,CAAA;AACtD,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,qCAAA,EAAwC,QAAQ,CAAA,CAAE,CAAA;AAAA,IACjE;AAEA,IAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,EAAE,SAAS,IAAA,EAAM,CAAA,CAAE,QAAA,CAAS,KAAK,CAAA;AACvD,IAAA,MAAM,IAAA,CAAK,IAAI,MAAA,CAAO,mBAAA,CAAoB,QAAQ,CAAA,EAAG,EAAE,MAAM,CAAA;AAC7D,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,SAAA,CAAW,CAAA;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,mBAAmB,KAAA,EAAwC;AAC1D,IAAA,IAAA,CAAK,SAAS,eAAA,GAAkB,KAAA;AAAA,EACjC;AAAA,EAEA,IAAI,eAAA,GAAkB;AACrB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,eAAA,IAAmB,EAAC;AAAA,EAC1C;AACD","file":"trivious.client.js","sourcesContent":["import { Client, REST, Routes } from \"discord.js\";\nimport { registries } from \"../registry/index.js\";\nimport {\n\tTriviousClientOptions,\n\tPermissionLevel,\n\tSlashCommand,\n\tContextMenuCommand,\n} from \"src/shared/typings/index.js\";\nimport { exists } from \"src/shared/utility/functions.js\";\nimport path from \"node:path\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\n\n/**\n * Trivious base client.\n *\n * @export\n * @class TriviousClient\n * @typedef {TriviousClient}\n * @extends {Client}\n */\nexport default class TriviousClient extends Client {\n\t/**\n\t * Client registries.\n\t *\n\t * @public\n\t * @readonly\n\t * @type {*}\n\t */\n\treadonly registries = registries();\n\t/**\n\t * Client copy of the constructor options.\n\t *\n\t * @private\n\t * @type {TriviousClientOptions}\n\t */\n\treadonly _options: TriviousClientOptions;\n\n\t/**\n\t * Creates an instance of TriviousClient.\n\t *\n\t * @constructor\n\t * @param {TriviousClientOptions} options\n\t */\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis._options = options;\n\t}\n\n\t/**\n\t * Load all registries.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync register() {\n\t\tconst { registries } = this;\n\t\tawait registries.loadAll(this._options);\n\t\tconsole.log(\n\t\t\t`[Trivious] Loaded all registries (${registries.commands.get().size} commands, ${registries.events.get().size} events, ${registries.components.get().size} components, ${registries.modules.get().size} modules)`\n\t\t);\n\t}\n\n\t/**\n\t * Login and start the bot.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync start() {\n\t\tif (!process.env[this._options.tokenReference]) {\n\t\t\tif (process.env.NODE_ENV !== \"production\") return;\n\t\t\telse throw new Error(\"[Trivious] Invalid token reference\");\n\t\t}\n\n\t\tthis.registries.bind(this);\n\t\tawait this.login(process.env[this._options.tokenReference]);\n\t}\n\n\t/**\n\t * Deploy all commands.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync deploy() {\n\t\tconst { commandHashConfig } = this._options;\n\t\tconst clientId = process.env[this._options.clientIdReference];\n\t\tconst token = process.env[this._options.tokenReference];\n\t\tif (!clientId || !token) throw new Error(\"[Trivious] Invalid clientId or token reference\");\n\n\t\tconst commands = Array.from(this.registries.commands.get().values());\n\t\tconst body = [\n\t\t\t...commands.map(command =>\n\t\t\t\t\"data\" in command ? (command as SlashCommand | ContextMenuCommand).data.toJSON() : null\n\t\t\t),\n\t\t].filter(c => c !== null);\n\n\t\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\t\tconst hashFile = path.join(commandHashConfig.filePath || \"data\", \"commands.hash\");\n\t\t\tconst newHash = createHash(\"sha256\")\n\t\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t\t.digest(\"hex\");\n\n\t\t\tlet oldHash = \"\";\n\n\t\t\tif (await exists(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\t\t\tif (newHash === oldHash) {\n\t\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst hashDirectory = path.dirname(hashFile);\n\t\t\tif (!existsSync(hashDirectory)) {\n\t\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t\t}\n\n\t\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t\t}\n\n\t\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\t\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\t\tconsole.log(`[Trivious] Deployed ${body.length} commands`);\n\t}\n\n\t/**\n\t * Set the roles tied to a permission level.\n\t *\n\t * @param {Record<string, PermissionLevel>} roles\n\t */\n\tsetRolePermissions(roles: Record<string, PermissionLevel>) {\n\t\tthis._options.rolePermissions = roles;\n\t}\n\n\tget rolePermissions() {\n\t\treturn this._options.rolePermissions ?? {};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MessagePayload, InteractionEditReplyOptions, InteractionReplyOptions } from 'discord.js';
|
|
2
|
+
import { C as Command, a as ChatInputCommandInteraction, b as ContextMenuCommandInteraction, T as TriviousClient, S as SlashCommand } from '../../index-BqxT-x7T.js';
|
|
3
|
+
import { PermissionLevel } from '../../shared/typings/permissions.js';
|
|
4
|
+
import '../../shared/typings/registry.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
7
|
+
import '../builders/util.builders.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reply to a command, respecting whether it has been deferred or already replied to.
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @async
|
|
14
|
+
* @param {Command} command
|
|
15
|
+
* @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction
|
|
16
|
+
* @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
|
|
17
|
+
* @returns {*}
|
|
18
|
+
*/
|
|
19
|
+
declare function commandReply(command: Command, interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction, options: MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Compare a permission level to the guild member's permission level.
|
|
22
|
+
*
|
|
23
|
+
* @export
|
|
24
|
+
* @async
|
|
25
|
+
* @param {TriviousClient} client
|
|
26
|
+
* @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction
|
|
27
|
+
* @param {Command} command
|
|
28
|
+
* @param {PermissionLevel} requiredPermission
|
|
29
|
+
* @param {boolean} [doReply=true]
|
|
30
|
+
* @returns {unknown}
|
|
31
|
+
*/
|
|
32
|
+
declare function verifyGuildPermission(client: TriviousClient, interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction, command: Command, requiredPermission: PermissionLevel, doReply?: boolean): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Handle execution of a slash command.
|
|
35
|
+
*
|
|
36
|
+
* @export
|
|
37
|
+
* @async
|
|
38
|
+
* @param {TriviousClient} client
|
|
39
|
+
* @param {(SlashCommand | SlashSubcommand)} command
|
|
40
|
+
* @param {ChatInputCommandInteraction} interaction
|
|
41
|
+
* @returns {*}
|
|
42
|
+
*/
|
|
43
|
+
declare function handleSlashCommand(client: TriviousClient, command: SlashCommand, interaction: ChatInputCommandInteraction): Promise<void>;
|
|
44
|
+
|
|
45
|
+
export { commandReply, handleSlashCommand, verifyGuildPermission };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { PermissionLevel } from '../../index.js';
|
|
2
|
+
import { hasPermission } from '../../shared/utility/functions.js';
|
|
3
|
+
|
|
4
|
+
async function commandReply(command, interaction, options) {
|
|
5
|
+
if (interaction.replied || interaction.deferred) {
|
|
6
|
+
await interaction.editReply(options);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const newOptions = { ...options };
|
|
10
|
+
if (command.flags && command.flags.includes("EphemeralReply")) newOptions.flags = ["Ephemeral"];
|
|
11
|
+
await interaction.reply(newOptions);
|
|
12
|
+
}
|
|
13
|
+
async function verifyGuildPermission(client, interaction, command, requiredPermission, doReply = true) {
|
|
14
|
+
if (!interaction.inGuild()) return true;
|
|
15
|
+
const member = interaction.member;
|
|
16
|
+
const memberHasPermission = hasPermission(client, { permission: requiredPermission, member });
|
|
17
|
+
if (!memberHasPermission && doReply) {
|
|
18
|
+
await commandReply(command, interaction, {
|
|
19
|
+
content: `You do not have permission to run this command, required permission: \`${PermissionLevel[requiredPermission]}\``
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return memberHasPermission;
|
|
23
|
+
}
|
|
24
|
+
async function handleSlashCommand(client, command, interaction) {
|
|
25
|
+
const { options } = interaction;
|
|
26
|
+
const hasPerm = await verifyGuildPermission(
|
|
27
|
+
client,
|
|
28
|
+
interaction,
|
|
29
|
+
command,
|
|
30
|
+
command.permission || PermissionLevel.USER,
|
|
31
|
+
true
|
|
32
|
+
);
|
|
33
|
+
if ("run" in command && command.run && hasPerm) {
|
|
34
|
+
await command.run(client, interaction);
|
|
35
|
+
}
|
|
36
|
+
if (!hasPerm) return;
|
|
37
|
+
if (!options.getSubcommand(false) || !("subcommands" in command)) return;
|
|
38
|
+
const subcommandName = options.getSubcommand();
|
|
39
|
+
const subcommand = command.subcommands.get(subcommandName);
|
|
40
|
+
if (!subcommand) {
|
|
41
|
+
await commandReply(command, interaction, {
|
|
42
|
+
content: "This subcommand no longer exists or is not registered."
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
await subcommand.execute(client, interaction);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { commandReply, handleSlashCommand, verifyGuildPermission };
|
|
50
|
+
//# sourceMappingURL=methods.command.js.map
|
|
51
|
+
//# sourceMappingURL=methods.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/commands/methods.command.ts"],"names":[],"mappings":";;;AA2BA,eAAsB,YAAA,CACrB,OAAA,EACA,WAAA,EACA,OAAA,EACC;AACD,EAAA,IAAI,WAAA,CAAY,OAAA,IAAW,WAAA,CAAY,QAAA,EAAU;AAChD,IAAA,MAAM,WAAA,CAAY,UAAU,OAAsC,CAAA;AAClE,IAAA;AAAA,EACD;AAEA,EAAA,MAAM,UAAA,GAAa,EAAE,GAAG,OAAA,EAAQ;AAChC,EAAA,IAAI,OAAA,CAAQ,KAAA,IAAS,OAAA,CAAQ,KAAA,CAAM,QAAA,CAAS,gBAAgB,CAAA,EAAG,UAAA,CAAW,KAAA,GAAQ,CAAC,WAAW,CAAA;AAE9F,EAAA,MAAM,WAAA,CAAY,MAAM,UAAU,CAAA;AACnC;AAcA,eAAsB,sBACrB,MAAA,EACA,WAAA,EACA,OAAA,EACA,kBAAA,EACA,UAAmB,IAAA,EAClB;AACD,EAAA,IAAI,CAAC,WAAA,CAAY,OAAA,EAAQ,EAAG,OAAO,IAAA;AAEnC,EAAA,MAAM,SAAS,WAAA,CAAY,MAAA;AAC3B,EAAA,MAAM,sBAAsB,aAAA,CAAc,MAAA,EAAQ,EAAE,UAAA,EAAY,kBAAA,EAAoB,QAAQ,CAAA;AAE5F,EAAA,IAAI,CAAC,uBAAuB,OAAA,EAAS;AACpC,IAAA,MAAM,YAAA,CAAa,SAAS,WAAA,EAAa;AAAA,MACxC,OAAA,EAAS,CAAA,uEAAA,EAA0E,eAAA,CAAgB,kBAAkB,CAAC,CAAA,EAAA;AAAA,KACtH,CAAA;AAAA,EACF;AAEA,EAAA,OAAO,mBAAA;AACR;AAYA,eAAsB,kBAAA,CACrB,MAAA,EACA,OAAA,EACA,WAAA,EACC;AACD,EAAA,MAAM,EAAE,SAAQ,GAAI,WAAA;AAEpB,EAAA,MAAM,UAAU,MAAM,qBAAA;AAAA,IACrB,MAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA,CAAQ,cAAc,eAAA,CAAgB,IAAA;AAAA,IACtC;AAAA,GACD;AAEA,EAAA,IAAI,KAAA,IAAS,OAAA,IAAW,OAAA,CAAQ,GAAA,IAAO,OAAA,EAAS;AAC/C,IAAA,MAAM,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,WAAW,CAAA;AAAA,EACtC;AAEA,EAAA,IAAI,CAAC,OAAA,EAAS;AACd,EAAA,IAAI,CAAC,OAAA,CAAQ,aAAA,CAAc,KAAK,CAAA,IAAK,EAAE,iBAAiB,OAAA,CAAA,EAAU;AAElE,EAAA,MAAM,cAAA,GAAiB,QAAQ,aAAA,EAAc;AAC7C,EAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,WAAA,CAAa,GAAA,CAAI,cAAc,CAAA;AAE1D,EAAA,IAAI,CAAC,UAAA,EAAY;AAChB,IAAA,MAAM,YAAA,CAAa,SAAS,WAAA,EAAa;AAAA,MACxC,OAAA,EAAS;AAAA,KACT,CAAA;AACD,IAAA;AAAA,EACD;AAEA,EAAA,MAAM,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAC7C","file":"methods.command.js","sourcesContent":["import {\n\tGuildMember,\n\tInteractionEditReplyOptions,\n\tInteractionReplyOptions,\n\tMessagePayload,\n} from \"discord.js\";\nimport {\n\tChatInputCommandInteraction,\n\tCommand,\n\tContextMenuCommandInteraction,\n\tPermissionLevel,\n\tSlashCommand,\n\tSlashSubcommand,\n\tTriviousClient,\n} from \"src/index.js\";\nimport { hasPermission } from \"src/shared/utility/functions.js\";\n\n/**\n * Reply to a command, respecting whether it has been deferred or already replied to.\n *\n * @export\n * @async\n * @param {Command} command\n * @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction\n * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options\n * @returns {*}\n */\nexport async function commandReply(\n\tcommand: Command,\n\tinteraction: ChatInputCommandInteraction | ContextMenuCommandInteraction,\n\toptions: MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions\n) {\n\tif (interaction.replied || interaction.deferred) {\n\t\tawait interaction.editReply(options as InteractionEditReplyOptions);\n\t\treturn;\n\t}\n\n\tconst newOptions = { ...options } as InteractionReplyOptions;\n\tif (command.flags && command.flags.includes(\"EphemeralReply\")) newOptions.flags = [\"Ephemeral\"];\n\n\tawait interaction.reply(newOptions);\n}\n\n/**\n * Compare a permission level to the guild member's permission level.\n *\n * @export\n * @async\n * @param {TriviousClient} client\n * @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction\n * @param {Command} command\n * @param {PermissionLevel} requiredPermission\n * @param {boolean} [doReply=true]\n * @returns {unknown}\n */\nexport async function verifyGuildPermission(\n\tclient: TriviousClient,\n\tinteraction: ChatInputCommandInteraction | ContextMenuCommandInteraction,\n\tcommand: Command,\n\trequiredPermission: PermissionLevel,\n\tdoReply: boolean = true\n) {\n\tif (!interaction.inGuild()) return true;\n\n\tconst member = interaction.member as GuildMember;\n\tconst memberHasPermission = hasPermission(client, { permission: requiredPermission, member });\n\n\tif (!memberHasPermission && doReply) {\n\t\tawait commandReply(command, interaction, {\n\t\t\tcontent: `You do not have permission to run this command, required permission: \\`${PermissionLevel[requiredPermission]}\\``,\n\t\t});\n\t}\n\n\treturn memberHasPermission;\n}\n\n/**\n * Handle execution of a slash command.\n *\n * @export\n * @async\n * @param {TriviousClient} client\n * @param {(SlashCommand | SlashSubcommand)} command\n * @param {ChatInputCommandInteraction} interaction\n * @returns {*}\n */\nexport async function handleSlashCommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommand,\n\tinteraction: ChatInputCommandInteraction\n) {\n\tconst { options } = interaction;\n\n\tconst hasPerm = await verifyGuildPermission(\n\t\tclient,\n\t\tinteraction,\n\t\tcommand,\n\t\tcommand.permission || PermissionLevel.USER,\n\t\ttrue\n\t);\n\n\tif (\"run\" in command && command.run && hasPerm) {\n\t\tawait command.run(client, interaction);\n\t}\n\n\tif (!hasPerm) return;\n\tif (!options.getSubcommand(false) || !(\"subcommands\" in command)) return;\n\n\tconst subcommandName = options.getSubcommand();\n\tconst subcommand = command.subcommands!.get(subcommandName) as SlashSubcommand | undefined;\n\n\tif (!subcommand) {\n\t\tawait commandReply(command, interaction, {\n\t\t\tcontent: \"This subcommand no longer exists or is not registered.\",\n\t\t});\n\t\treturn;\n\t}\n\n\tawait subcommand.execute(client, interaction);\n}\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import 'discord.js';
|
|
2
|
+
import '../../shared/typings/permissions.js';
|
|
3
|
+
import '../../shared/typings/components.js';
|
|
4
|
+
export { l as Component } from '../../index-BqxT-x7T.js';
|
|
5
|
+
import '../../shared/typings/registry.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
7
|
+
import '../builders/util.builders.js';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { T as TriviousClient } from '../../index-
|
|
2
|
+
import { T as TriviousClient } from '../../index-BqxT-x7T.js';
|
|
3
|
+
import '../../shared/typings/permissions.js';
|
|
3
4
|
import '../../shared/typings/registry.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
5
8
|
|
|
6
9
|
declare const _default: {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CacheType } from 'discord.js';
|
|
3
|
+
import { T as TriviousClient } from '../../index-BqxT-x7T.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
3
5
|
import '../../shared/typings/registry.js';
|
|
6
|
+
import '../../shared/typings/components.js';
|
|
7
|
+
import '../../shared/typings/client.js';
|
|
4
8
|
import '../builders/util.builders.js';
|
|
5
9
|
|
|
6
10
|
declare const _default: {
|
|
7
11
|
name: "interactionCreate";
|
|
8
|
-
execute: (client: TriviousClient, interaction: discord_js.Interaction<
|
|
12
|
+
execute: (client: TriviousClient, interaction: discord_js.Interaction<CacheType>) => Promise<void>;
|
|
9
13
|
};
|
|
10
14
|
|
|
11
15
|
export { _default as default };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PermissionLevel, ComponentType } from '../../shared/typings/index.js';
|
|
3
3
|
import { hasPermission } from '../../shared/utility/functions.js';
|
|
4
|
+
import { verifyGuildPermission, commandReply, handleSlashCommand } from '../commands/methods.command.js';
|
|
5
|
+
import { deconstructCustomId } from '../../shared/utility/components.utility.js';
|
|
4
6
|
|
|
5
7
|
async function validateComponentGuildPermission(client, interaction, permission) {
|
|
6
8
|
if (interaction.guild) {
|
|
@@ -24,26 +26,34 @@ var interactionCreate_default = {
|
|
|
24
26
|
});
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const requiredPermission = command.
|
|
28
|
-
const hasPermission2 = await
|
|
29
|
+
const requiredPermission = command.permission;
|
|
30
|
+
const hasPermission2 = await verifyGuildPermission(
|
|
29
31
|
client,
|
|
30
32
|
interaction,
|
|
31
|
-
|
|
33
|
+
command,
|
|
34
|
+
requiredPermission || PermissionLevel.USER
|
|
32
35
|
);
|
|
33
36
|
if (!hasPermission2) return;
|
|
34
37
|
if (!("execute" in command)) {
|
|
35
|
-
await command
|
|
38
|
+
await commandReply(command, interaction, {
|
|
36
39
|
content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!"
|
|
37
40
|
});
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
40
|
-
if (command.
|
|
41
|
-
await command
|
|
43
|
+
if (command.flags?.includes("DeferReply")) {
|
|
44
|
+
await commandReply(command, interaction, { content: "Processing command..." });
|
|
42
45
|
}
|
|
43
|
-
if (
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (command.context === "SlashCommand" && "data" in command) {
|
|
47
|
+
await handleSlashCommand(
|
|
48
|
+
client,
|
|
49
|
+
command,
|
|
50
|
+
interaction
|
|
51
|
+
);
|
|
52
|
+
} else if (command.context === "ContextMenu") {
|
|
53
|
+
await command.execute(
|
|
54
|
+
client,
|
|
55
|
+
interaction
|
|
56
|
+
);
|
|
47
57
|
}
|
|
48
58
|
} else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {
|
|
49
59
|
const { compType, tags, data } = deconstructCustomId(interaction.customId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/events/interactionCreate.ts"],"names":["hasPermission"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/core/events/interactionCreate.ts"],"names":["hasPermission"],"mappings":";;;;;;AA0BA,eAAe,gCAAA,CACd,MAAA,EACA,WAAA,EACA,UAAA,EACC;AACD,EAAA,IAAI,YAAY,KAAA,EAAO;AACtB,IAAA,MAAM,SAAS,WAAA,CAAY,MAAA;AAC3B,IAAA,MAAM,sBAAsB,aAAA,CAAc,MAAA,EAAQ,EAAE,UAAA,EAAY,QAAQ,CAAA;AACxE,IAAA,OAAO,mBAAA;AAAA,EACR;AAEA,EAAA,OAAO,KAAA;AACR;AAEA,IAAO,yBAAA,GAAQ;AAAA,EACd,IAAA,EAAM,mBAAA;AAAA,EACN,OAAA,EAAS,OAAO,MAAA,EAAQ,WAAA,KAAgB;AACvC,IAAA,IAAI,WAAA,CAAY,kBAAA,EAAmB,IAAK,WAAA,CAAY,sBAAqB,EAAG;AAC3E,MAAA,MAAM,EAAE,aAAY,GAAI,WAAA;AAExB,MAAA,MAAM,kBAAA,GAAqB,MAAA,CAAO,UAAA,CAAW,QAAA,CAAS,GAAA,EAAI;AAC1D,MAAA,MAAM,OAAA,GAAU,kBAAA,CAAmB,GAAA,CAAI,WAAW,CAAA;A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AAA,IAAI,QAAA,KAAa,aAAA,CAAc,MAAA,IAAU,EAAE,uBAAuB,iBAAA,CAAA,EAAoB;AACtF,MAAA,IAAI,QAAA,KAAa,aAAA,CAAc,KAAA,IAAS,EAAE,WAAA,YAAuB,sBAAA,CAAA;AAChE,QAAA;AAED,MAAA,IAAI,IAAA,IAAQ,IAAA,CAAK,QAAA,CAAS,SAAS,CAAA,EAAG;AAEtC,MAAA,MAAM,oBAAA,GAAuB,MAAA,CAAO,UAAA,CAAW,UAAA,CAAW,GAAA,EAAI;AAC9D,MAAA,MAAM,SAAA,GAAY,oBAAA,CAAqB,GAAA,CAAI,IAAI,CAAA;AAC/C,MAAA,IAAI,CAAC,SAAA,EAAW;AACf,QAAA,MAAM,YAAY,KAAA,CAAM;AAAA,UACvB,OAAA,EAAS,CAAA,yDAAA,CAAA;AAAA,UACT,KAAA,EAAO,CAAC,WAAW;AAAA,SACnB,CAAA;AACD,QAAA;AAAA,MACD;AAEA,MAAA,MAAM,qBAAqB,SAAA,CAAU,UAAA;AACrC,MAAA,MAAMA,iBAAgB,MAAM,gCAAA;AAAA,QAC3B,MAAA;AAAA,QACA,WAAA;AAAA,QACA;AAAA,OACD;AACA,MAAA,IAAI,CAACA,cAAAA,EAAe;AAEpB,MAAA,IAAI,CAAC,WAAA,CAAY,aAAA,EAAc,EAAG,MAAM,YAAY,WAAA,EAAY;AAChE,MAAA,MAAM,SAAA,CAAU,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAAA,IAC5C;AAAA,EACD;AACD","file":"interactionCreate.js","sourcesContent":["import {\n\tButtonInteraction,\n\tCacheType,\n\tGuildMember,\n\tMessageContextMenuCommandInteraction,\n\tModalSubmitInteraction,\n\tUserContextMenuCommandInteraction,\n} from \"discord.js\";\nimport {\n\tComponentInteraction,\n\tComponentType,\n\tContextMenuCommand,\n\tEvent,\n\tPermissionLevel,\n\tSlashCommand,\n} from \"src/shared/typings/index.js\";\nimport { hasPermission } from \"src/shared/utility/functions.js\";\nimport {\n\tcommandReply,\n\thandleSlashCommand,\n\tverifyGuildPermission,\n} from \"../commands/methods.command.js\";\nimport { ChatInputCommandInteraction } from \"src/index.js\";\nimport { deconstructCustomId } from \"src/shared/utility/components.utility.js\";\nimport TriviousClient from \"../client/trivious.client.js\";\n\nasync function validateComponentGuildPermission(\n\tclient: TriviousClient,\n\tinteraction: ComponentInteraction,\n\tpermission: PermissionLevel\n) {\n\tif (interaction.guild) {\n\t\tconst member = interaction.member as GuildMember;\n\t\tconst memberHasPermission = hasPermission(client, { permission, member });\n\t\treturn memberHasPermission;\n\t}\n\n\treturn false;\n}\n\nexport default {\n\tname: \"interactionCreate\",\n\texecute: async (client, interaction) => {\n\t\tif (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {\n\t\t\tconst { commandName } = interaction;\n\n\t\t\tconst registeredCommands = client.registries.commands.get();\n\t\t\tconst command = registeredCommands.get(commandName);\n\t\t\tif (!command) {\n\t\t\t\tawait interaction.reply({\n\t\t\t\t\tcontent: `Command is outdated, inactive or does not have a handler!`,\n\t\t\t\t\tflags: [\"Ephemeral\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst requiredPermission = command.permission;\n\t\t\tconst hasPermission = await verifyGuildPermission(\n\t\t\t\tclient,\n\t\t\t\tinteraction,\n\t\t\t\tcommand,\n\t\t\t\trequiredPermission || PermissionLevel.USER\n\t\t\t);\n\t\t\tif (!hasPermission) return;\n\n\t\t\tif (!(\"execute\" in command)) {\n\t\t\t\tawait commandReply(command, interaction, {\n\t\t\t\t\tcontent:\n\t\t\t\t\t\t\"Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!\",\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (command.flags?.includes(\"DeferReply\")) {\n\t\t\t\tawait commandReply(command, interaction, { content: \"Processing command...\" });\n\t\t\t}\n\n\t\t\tif (command.context === \"SlashCommand\" && \"data\" in command) {\n\t\t\t\tawait handleSlashCommand(\n\t\t\t\t\tclient,\n\t\t\t\t\tcommand as SlashCommand,\n\t\t\t\t\tinteraction as ChatInputCommandInteraction\n\t\t\t\t);\n\t\t\t} else if (command.context === \"ContextMenu\") {\n\t\t\t\tawait (command as ContextMenuCommand).execute(\n\t\t\t\t\tclient,\n\t\t\t\t\tinteraction as\n\t\t\t\t\t\t| UserContextMenuCommandInteraction<CacheType>\n\t\t\t\t\t\t| MessageContextMenuCommandInteraction<CacheType>\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {\n\t\t\tconst { compType, tags, data } = deconstructCustomId(interaction.customId);\n\n\t\t\tif (compType === ComponentType.Button && !(interaction instanceof ButtonInteraction)) return;\n\t\t\tif (compType === ComponentType.Modal && !(interaction instanceof ModalSubmitInteraction))\n\t\t\t\treturn;\n\n\t\t\tif (tags && tags.includes(\"awaited\")) return;\n\n\t\t\tconst registeredComponents = client.registries.components.get();\n\t\t\tconst component = registeredComponents.get(data);\n\t\t\tif (!component) {\n\t\t\t\tawait interaction.reply({\n\t\t\t\t\tcontent: `Command is outdated, inactive or does not have a handler!`,\n\t\t\t\t\tflags: [\"Ephemeral\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst requiredPermission = component.permission;\n\t\t\tconst hasPermission = await validateComponentGuildPermission(\n\t\t\t\tclient,\n\t\t\t\tinteraction,\n\t\t\t\trequiredPermission\n\t\t\t);\n\t\t\tif (!hasPermission) return;\n\n\t\t\tif (!interaction.isModalSubmit()) await interaction.deferUpdate();\n\t\t\tawait component.execute(client, interaction);\n\t\t}\n\t},\n} satisfies Event<\"interactionCreate\">;\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { C as default } from '../../index-6Un9NsKu.js';
|
|
3
2
|
import '../../shared/typings/registry.js';
|
|
3
|
+
export { c as default } from '../../index-BqxT-x7T.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
@@ -28,9 +28,8 @@ class CommandRegistry extends BaseRegistry {
|
|
|
28
28
|
else if (await exists(indexJs)) commandFile = indexJs;
|
|
29
29
|
else continue;
|
|
30
30
|
const command = await this.importFile(commandFile);
|
|
31
|
-
if (!command) continue;
|
|
32
|
-
if (
|
|
33
|
-
if (command.isSlashCommand()) {
|
|
31
|
+
if (!command || !command.active || !("data" in command)) continue;
|
|
32
|
+
if ("subcommands" in command) {
|
|
34
33
|
const subcommandFiles = (await promises.readdir(fullPath)).filter(
|
|
35
34
|
(file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
|
|
36
35
|
);
|
|
@@ -39,8 +38,9 @@ class CommandRegistry extends BaseRegistry {
|
|
|
39
38
|
if (!subcommand) continue;
|
|
40
39
|
if (!subcommand.data.name || !(subcommand.data instanceof SlashCommandSubcommandBuilder))
|
|
41
40
|
continue;
|
|
41
|
+
if (!command.subcommands) command.subcommands = new Collection();
|
|
42
|
+
command.subcommands.set(subcommand.data.name, subcommand);
|
|
42
43
|
command.data.addSubcommand(subcommand.data);
|
|
43
|
-
command.metadata.subcommands.set(subcommand.data.name, subcommand);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
this.items.set(command.data.name, command);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/registry/command.registry.ts"],"names":["fs"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/core/registry/command.registry.ts"],"names":["fs"],"mappings":";;;;;;AAoBA,MAAO,wBAAsC,YAAA,CAAsB;AAAA,EACxD,KAAA,GAAQ,IAAI,UAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlD,MAAM,KAAK,SAAA,GAAoB,eAAA,CAAgB,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B;AAEA,QAAA,KAAA,MAAW,QAAQ,eAAA,EAAiB;AACnC,UAAA,MAAM,aAAa,MAAM,IAAA,CAAK,WAA4B,IAAA,CAAK,QAAA,EAAU,IAAI,CAAC,CAAA;AAC9E,UAAA,IAAI,CAAC,UAAA,EAAY;AACjB,UAAA,IAAI,CAAC,UAAA,CAAW,IAAA,CAAK,IAAA,IAAQ,EAAE,WAAW,IAAA,YAAgB,6BAAA,CAAA;AACzD,YAAA;AAED,UAAA,IAAI,CAAC,OAAA,CAAQ,WAAA,EAAa,OAAA,CAAQ,WAAA,GAAc,IAAI,UAAA,EAAoC;AACxF,UAAA,OAAA,CAAQ,WAAA,CAAY,GAAA,CAAI,UAAA,CAAW,IAAA,CAAK,MAAM,UAAU,CAAA;AACxD,UAAA,OAAA,CAAQ,IAAA,CAAK,aAAA,CAAc,UAAA,CAAW,IAAI,CAAA;AAAA,QAC3C;AAAA,MACD;AAEA,MAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,OAAA,CAAQ,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,IAC1C;AAEA,IAAA,OAAO,IAAA;AAAA,EACR;AACD","file":"command.registry.js","sourcesContent":["import { Collection, SlashCommandSubcommandBuilder } from \"discord.js\";\nimport {\n\tBaseRegistry,\n\tCommand,\n\tContextMenuCommand,\n\tSlashCommand,\n\tSlashSubcommand,\n} from \"src/shared/typings/index.js\";\nimport { exists, resolveUserPath } from \"src/shared/utility/functions.js\";\nimport { promises as fs } from \"fs\";\nimport path, { join } from \"node:path\";\n\n/**\n * Registry to load and get all commands.\n *\n * @export\n * @class CommandRegistry\n * @typedef {CommandRegistry}\n * @extends {BaseRegistry<AnyCommand>}\n */\nexport default class CommandRegistry extends BaseRegistry<Command> {\n\tprotected items = new Collection<string, Command>();\n\n\t/**\n\t * Load all commands and their subcommands\n\t *\n\t * @async\n\t * @param {string} [directory=getCorePath({ coreDirectory: \"commands\" })]\n\t * @returns {unknown}\n\t */\n\tasync load(directory: string = resolveUserPath(path.join(\"src\", \"commands\"))) {\n\t\tif (!(await exists(directory))) {\n\t\t\treturn this;\n\t\t}\n\n\t\tconst entries = await fs.readdir(directory, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(directory, entry.name);\n\t\t\tif (!entry.isDirectory()) continue;\n\n\t\t\tconst indexFile = join(fullPath, \"index.ts\");\n\t\t\tconst indexJs = join(fullPath, \"index.js\");\n\n\t\t\tlet commandFile = \"\";\n\t\t\tif (await exists(indexFile)) commandFile = indexFile;\n\t\t\telse if (await exists(indexJs)) commandFile = indexJs;\n\t\t\telse continue;\n\n\t\t\tconst command = (await this.importFile<Command>(commandFile)) as\n\t\t\t\t| SlashCommand\n\t\t\t\t| ContextMenuCommand\n\t\t\t\t| null;\n\t\t\tif (!command || !command.active || !(\"data\" in command)) continue;\n\n\t\t\tif (\"subcommands\" in command) {\n\t\t\t\tconst subcommandFiles = (await fs.readdir(fullPath)).filter(\n\t\t\t\t\tfile =>\n\t\t\t\t\t\t(file.endsWith(\".ts\") || file.endsWith(\".js\")) &&\n\t\t\t\t\t\t!file.startsWith(\"index.\") &&\n\t\t\t\t\t\t!file.endsWith(\".d.ts\")\n\t\t\t\t);\n\n\t\t\t\tfor (const file of subcommandFiles) {\n\t\t\t\t\tconst subcommand = await this.importFile<SlashSubcommand>(join(fullPath, file));\n\t\t\t\t\tif (!subcommand) continue;\n\t\t\t\t\tif (!subcommand.data.name || !(subcommand.data instanceof SlashCommandSubcommandBuilder))\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tif (!command.subcommands) command.subcommands = new Collection<string, SlashSubcommand>();\n\t\t\t\t\tcommand.subcommands.set(subcommand.data.name, subcommand);\n\t\t\t\t\tcommand.data.addSubcommand(subcommand.data);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.items.set(command.data.name, command);\n\t\t}\n\n\t\treturn this;\n\t}\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { a as default } from '../../index-6Un9NsKu.js';
|
|
3
2
|
import '../../shared/typings/registry.js';
|
|
3
|
+
export { d as default } from '../../index-BqxT-x7T.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/registry/component.registry.ts"],"names":["fs"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/core/registry/component.registry.ts"],"names":["fs"],"mappings":";;;;;;AAeA,MAAO,0BAAwC,YAAA,CAAwB;AAAA,EAC5D,KAAA,GAAQ,IAAI,UAAA,EAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASpD,MAAM,KAAK,SAAA,GAAoB,eAAA,CAAgB,KAAK,IAAA,CAAK,KAAA,EAAO,QAAQ,CAAC,CAAA,EAAkB;AAC1F,IAAA,IAAI,CAAE,MAAM,MAAA,CAAO,SAAS,GAAI,OAAO,IAAA;AAEvC,IAAA,MAAM,OAAA,GAAU,MAAMA,QAAA,CAAG,OAAA,CAAQ,WAAW,EAAE,aAAA,EAAe,MAAM,CAAA;AACnE,IAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC5B,MAAA,MAAM,QAAA,GAAW,IAAA,CAAK,SAAA,EAAW,KAAA,CAAM,IAAI,CAAA;AAE3C,MAAA,IAAI,KAAA,CAAM,aAAY,EAAG;AACxB,QAAA,MAAM,IAAA,CAAK,KAAK,QAAQ,CAAA;AACxB,QAAA;AAAA,MACD;AAEA,MAAA,IAAI,MAAM,MAAA,EAAO,IAAK,MAAM,IAAA,CAAK,QAAA,CAAS,KAAK,CAAA,EAAG;AACjD,QAAA,MAAM,KAAA,GAAQ,MAAM,IAAA,CAAK,UAAA,CAAsB,QAAQ,CAAA;AACvD,QAAA,IAAI,CAAC,KAAA,EAAO;AAEZ,QAAA,IAAI,EAAE,KAAA,CAAM,QAAA,IAAY,KAAA,CAAM,YAAA,CAAA,EAAe;AAC5C,UAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,eAAA,EAAkB,KAAA,CAAM,IAAI,CAAA,2CAAA,CAA6C,CAAA;AACvF,UAAA;AAAA,QACD;AAEA,QAAA,IAAA,CAAK,MAAM,GAAA,CAAK,KAAA,CAAM,QAAA,IAAY,KAAA,CAAM,cAAyB,KAAK,CAAA;AAAA,MACvE;AAAA,IACD;AAEA,IAAA,OAAO,IAAA;AAAA,EACR;AACD","file":"component.registry.js","sourcesContent":["import { Collection } from \"discord.js\";\nimport { BaseRegistry } from \"src/shared/typings/index.js\";\nimport { exists, resolveUserPath } from \"src/shared/utility/functions.js\";\nimport { promises as fs } from \"fs\";\nimport path, { join } from \"node:path\";\nimport { Component } from \"../components/component.base.js\";\n\n/**\n * Registry to load and get all components.\n *\n * @export\n * @class ComponentRegistry\n * @typedef {ComponentRegistry}\n * @extends {BaseRegistry<Component>}\n */\nexport default class ComponentRegistry extends BaseRegistry<Component> {\n\tprotected items = new Collection<string, Component>();\n\n\t/**\n\t * Load all components.\n\t *\n\t * @async\n\t * @param {string} [directory=getCorePath({ coreDirectory: \"events\" })]\n\t * @returns {Promise<this>}\n\t */\n\tasync load(directory: string = resolveUserPath(path.join(\"src\", \"events\"))): Promise<this> {\n\t\tif (!(await exists(directory))) return this;\n\n\t\tconst entries = await fs.readdir(directory, { withFileTypes: true });\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(directory, entry.name);\n\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tawait this.load(fullPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (entry.isFile() && entry.name.endsWith(\".js\")) {\n\t\t\t\tconst event = await this.importFile<Component>(fullPath);\n\t\t\t\tif (!event) continue;\n\n\t\t\t\tif (!(event.customId || event.customIdData)) {\n\t\t\t\t\tconsole.error(`Component from ${entry.name} does not return customId nor customIdData!`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis.items.set((event.customId || event.customIdData) as string, event);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { E as default } from '../../index-6Un9NsKu.js';
|
|
3
2
|
import '../../shared/typings/registry.js';
|
|
3
|
+
export { E as default } from '../../index-BqxT-x7T.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../../
|
|
1
|
+
import { TriviousClientOptions } from '../../shared/typings/client.js';
|
|
2
|
+
import { c as CommandRegistry, d as ComponentRegistry, E as EventRegistry, M as ModuleRegistry, T as TriviousClient } from '../../index-BqxT-x7T.js';
|
|
3
3
|
import 'discord.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
5
|
+
import '../../shared/typings/registry.js';
|
|
6
|
+
import '../../shared/typings/components.js';
|
|
4
7
|
import '../builders/util.builders.js';
|
|
5
8
|
|
|
6
9
|
/**
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { M as default } from '../../index-6Un9NsKu.js';
|
|
3
2
|
import '../../shared/typings/registry.js';
|
|
3
|
+
export { M as default } from '../../index-BqxT-x7T.js';
|
|
4
|
+
import '../../shared/typings/permissions.js';
|
|
5
|
+
import '../../shared/typings/components.js';
|
|
6
|
+
import '../../shared/typings/client.js';
|
|
4
7
|
import '../builders/util.builders.js';
|