trivious 2.3.6 → 2.4.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/client/client.types.d.ts +14 -1
- package/dist/features/client/deploy.client.d.ts +1 -1
- package/dist/features/client/deploy.client.js +1 -1
- package/dist/features/client/deploy.client.js.map +1 -1
- package/dist/features/client/logger.js +4 -5
- package/dist/features/client/logger.js.map +1 -1
- package/dist/features/client/trivious.client.d.ts +1 -1
- package/dist/features/client/trivious.client.js +11 -8
- package/dist/features/client/trivious.client.js.map +1 -1
- package/dist/features/commands/builders.commands.d.ts +3 -2
- package/dist/features/commands/builders.commands.js +9 -0
- package/dist/features/commands/builders.commands.js.map +1 -1
- package/dist/features/commands/commands.types.d.ts +1 -1
- package/dist/features/commands/handlers/message.commands.d.ts +15 -0
- package/dist/features/commands/handlers/message.commands.js +109 -0
- package/dist/features/commands/handlers/message.commands.js.map +1 -0
- package/dist/features/commands/handlers/slash.commands.d.ts +9 -0
- package/dist/features/commands/handlers/slash.commands.js +74 -0
- package/dist/features/commands/handlers/slash.commands.js.map +1 -0
- package/dist/features/commands/methods.commands.d.ts +3 -4
- package/dist/features/commands/methods.commands.js +0 -70
- package/dist/features/commands/methods.commands.js.map +1 -1
- package/dist/features/commands/presets/help.d.ts +13 -0
- package/dist/features/commands/presets/help.js +40 -0
- package/dist/features/commands/presets/help.js.map +1 -0
- package/dist/features/commands/registry.commands.d.ts +1 -5
- package/dist/features/commands/registry.commands.js +44 -4
- package/dist/features/commands/registry.commands.js.map +1 -1
- package/dist/features/commands/utility.d.ts +12 -0
- package/dist/features/commands/utility.js +31 -0
- package/dist/features/commands/utility.js.map +1 -0
- package/dist/features/components/builders.components.d.ts +1 -1
- package/dist/features/components/builders.components.js +1 -1
- 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.map +1 -1
- package/dist/features/components/registry.components.d.ts +1 -5
- package/dist/features/components/registry.components.js +3 -3
- package/dist/features/components/registry.components.js.map +1 -1
- package/dist/features/customId/customid.types.d.ts +1 -1
- package/dist/features/customId/methods.customid.d.ts +1 -1
- package/dist/features/customId/methods.customid.js +1 -1
- package/dist/features/customId/methods.customid.js.map +1 -1
- package/dist/features/events/events.types.d.ts +1 -1
- package/dist/features/events/presets/clientReady.d.ts +1 -1
- package/dist/features/events/presets/clientReady.js.map +1 -1
- package/dist/features/events/presets/interactionCreate.d.ts +2 -1
- package/dist/features/events/presets/interactionCreate.js +9 -4
- package/dist/features/events/presets/interactionCreate.js.map +1 -1
- package/dist/features/events/presets/messageCreate.d.ts +13 -0
- package/dist/features/events/presets/messageCreate.js +128 -0
- package/dist/features/events/presets/messageCreate.js.map +1 -0
- package/dist/features/events/registry.events.d.ts +1 -6
- package/dist/features/events/registry.events.js +16 -3
- package/dist/features/events/registry.events.js.map +1 -1
- package/dist/features/modules/modules.types.d.ts +1 -1
- package/dist/features/modules/registry.modules.d.ts +1 -6
- package/dist/features/modules/registry.modules.js +2 -2
- package/dist/features/modules/registry.modules.js.map +1 -1
- package/dist/features/permissions/methods.permissions.d.ts +3 -3
- package/dist/features/permissions/methods.permissions.js +1 -0
- package/dist/features/permissions/methods.permissions.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/{modules.types-D-tuJArP.d.ts → modules.types-BgGFvIsW.d.ts} +87 -7
- package/dist/shared/registries.d.ts +1 -5
- package/dist/shared/registries.js +4 -4
- package/dist/shared/registries.js.map +1 -1
- package/dist/shared/typings.d.ts +2 -2
- package/dist/shared/typings.js +8 -8
- package/dist/shared/typings.js.map +1 -1
- package/dist/utility/errors.d.ts +1 -1
- package/dist/utility/errors.js.map +1 -1
- package/dist/utility/functions.d.ts +1 -1
- package/dist/utility/functions.js.map +1 -1
- package/package.json +16 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { p as MessageCommandData } from '../../../modules.types-BgGFvIsW.js';
|
|
2
|
+
import 'discord.js';
|
|
3
|
+
import '../../client/client.types.js';
|
|
4
|
+
import '../../permissions/permissions.types.js';
|
|
5
|
+
import '../../client/logger.js';
|
|
6
|
+
|
|
7
|
+
declare const _default: Omit<MessageCommandData<false, readonly [{
|
|
8
|
+
readonly name: "command-name";
|
|
9
|
+
readonly dataType: "text";
|
|
10
|
+
readonly description: "Name or alias of a command";
|
|
11
|
+
}], boolean>, "metadata">;
|
|
12
|
+
|
|
13
|
+
export { _default as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createEmbed, createMessageCommand } from "#trivious";
|
|
2
|
+
import { inlineCode } from "discord.js";
|
|
3
|
+
import { formatAliases, formatArguments, resolveCommand } from "../utility.js";
|
|
4
|
+
var help_default = createMessageCommand({
|
|
5
|
+
active: true,
|
|
6
|
+
name: "help",
|
|
7
|
+
description: "View information about a message command",
|
|
8
|
+
aliases: ["h"],
|
|
9
|
+
arguments: [
|
|
10
|
+
{ name: "command-name", dataType: "text", description: "Name or alias of a command" }
|
|
11
|
+
],
|
|
12
|
+
async execute(client, interaction) {
|
|
13
|
+
const { args, message } = interaction;
|
|
14
|
+
const query = args.get("command-name")?.trim().toLowerCase();
|
|
15
|
+
if (!query) {
|
|
16
|
+
await message.reply({ content: "Please specify a command name or alias." });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const command = resolveCommand(client, query);
|
|
20
|
+
if (!command) {
|
|
21
|
+
await message.reply({
|
|
22
|
+
content: `Could not find command or alias '${query}'`
|
|
23
|
+
});
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const prefix = client.trivious.messageCommands?.prefix ?? "?";
|
|
27
|
+
const aliases = formatAliases(prefix, command.aliases);
|
|
28
|
+
const argumentsList = formatArguments(command.arguments);
|
|
29
|
+
const embed = createEmbed({
|
|
30
|
+
title: `${prefix}${command.name}`,
|
|
31
|
+
description: `${command.description}
|
|
32
|
+
${inlineCode(command.metadata.usage)}${aliases}${argumentsList}`
|
|
33
|
+
});
|
|
34
|
+
await message.reply({ embeds: [embed] });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export {
|
|
38
|
+
help_default as default
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/commands/presets/help.ts"],"sourcesContent":["import { createEmbed, createMessageCommand } from \"#trivious\";\nimport { inlineCode } from \"discord.js\";\nimport { formatAliases, formatArguments, resolveCommand } from \"../utility.js\";\n\nexport default createMessageCommand({\n\tactive: true,\n\tname: \"help\",\n\tdescription: \"View information about a message command\",\n\taliases: [\"h\"],\n\targuments: [\n\t\t{ name: \"command-name\", dataType: \"text\", description: \"Name or alias of a command\" },\n\t],\n\tasync execute(client, interaction) {\n\t\tconst { args, message } = interaction;\n\t\tconst query = args.get(\"command-name\")?.trim().toLowerCase();\n\n\t\tif (!query) {\n\t\t\tawait message.reply({ content: \"Please specify a command name or alias.\" });\n\t\t\treturn;\n\t\t}\n\n\t\tconst command = resolveCommand(client, query);\n\t\tif (!command) {\n\t\t\tawait message.reply({\n\t\t\t\tcontent: `Could not find command or alias '${query}'`,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst prefix = client.trivious.messageCommands?.prefix ?? \"?\";\n\t\tconst aliases = formatAliases(prefix, command.aliases);\n\t\tconst argumentsList = formatArguments(command.arguments);\n\t\tconst embed = createEmbed({\n\t\t\ttitle: `${prefix}${command.name}`,\n\t\t\tdescription: `${command.description}\\n${inlineCode(command.metadata.usage)}${aliases}${argumentsList}`,\n\t\t});\n\n\t\tawait message.reply({ embeds: [embed] });\n\t},\n});\n"],"mappings":"AAAA,SAAS,aAAa,4BAA4B;AAClD,SAAS,kBAAkB;AAC3B,SAAS,eAAe,iBAAiB,sBAAsB;AAE/D,IAAO,eAAQ,qBAAqB;AAAA,EACnC,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,CAAC,GAAG;AAAA,EACb,WAAW;AAAA,IACV,EAAE,MAAM,gBAAgB,UAAU,QAAQ,aAAa,6BAA6B;AAAA,EACrF;AAAA,EACA,MAAM,QAAQ,QAAQ,aAAa;AAClC,UAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,UAAM,QAAQ,KAAK,IAAI,cAAc,GAAG,KAAK,EAAE,YAAY;AAE3D,QAAI,CAAC,OAAO;AACX,YAAM,QAAQ,MAAM,EAAE,SAAS,0CAA0C,CAAC;AAC1E;AAAA,IACD;AAEA,UAAM,UAAU,eAAe,QAAQ,KAAK;AAC5C,QAAI,CAAC,SAAS;AACb,YAAM,QAAQ,MAAM;AAAA,QACnB,SAAS,oCAAoC,KAAK;AAAA,MACnD,CAAC;AACD;AAAA,IACD;AAEA,UAAM,SAAS,OAAO,SAAS,iBAAiB,UAAU;AAC1D,UAAM,UAAU,cAAc,QAAQ,QAAQ,OAAO;AACrD,UAAM,gBAAgB,gBAAgB,QAAQ,SAAS;AACvD,UAAM,QAAQ,YAAY;AAAA,MACzB,OAAO,GAAG,MAAM,GAAG,QAAQ,IAAI;AAAA,MAC/B,aAAa,GAAG,QAAQ,WAAW;AAAA,EAAK,WAAW,QAAQ,SAAS,KAAK,CAAC,GAAG,OAAO,GAAG,aAAa;AAAA,IACrG,CAAC;AAED,UAAM,QAAQ,MAAM,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AAAA,EACxC;AACD,CAAC;","names":[]}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { x as default } from '../../modules.types-BgGFvIsW.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
5
|
import '../client/logger.js';
|
|
6
|
-
|
|
7
|
-
declare function registerCommands(client: TriviousClient, directory: string): Promise<void>;
|
|
8
|
-
|
|
9
|
-
export { registerCommands as default };
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { TriviousError } from "
|
|
2
|
-
import { importFile } from "
|
|
1
|
+
import { TriviousError } from "#utility/errors.js";
|
|
2
|
+
import { importFile } from "#utility/functions.js";
|
|
3
3
|
import { ApplicationCommandType, Collection } from "discord.js";
|
|
4
4
|
import { existsSync, promises as fs } from "fs";
|
|
5
5
|
import path from "path";
|
|
6
|
+
import { processPartialMessageCommand } from "./handlers/message.commands.js";
|
|
7
|
+
const parsedCache = /* @__PURE__ */ new Set();
|
|
6
8
|
async function parseBase(input, expects) {
|
|
7
9
|
let base = null;
|
|
8
10
|
if (typeof input === "string") {
|
|
11
|
+
const absolutePath = path.resolve(input);
|
|
12
|
+
if (parsedCache.has(absolutePath)) return null;
|
|
9
13
|
base = await importFile(input);
|
|
14
|
+
parsedCache.add(absolutePath);
|
|
10
15
|
} else base = input;
|
|
11
16
|
if (!base) return null;
|
|
12
17
|
if (expects && !expects(base)) return null;
|
|
@@ -49,6 +54,7 @@ function getDataFromCommandSet(set, options) {
|
|
|
49
54
|
}
|
|
50
55
|
async function setChildrenToParents(data) {
|
|
51
56
|
for (const [group, directory] of data.SlashSubcommandGroup) {
|
|
57
|
+
if (group.context !== "SlashSubcommandGroup") continue;
|
|
52
58
|
const slashCommand = group.parent || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
53
59
|
if (!slashCommand || !("addSubcommandGroup" in slashCommand.data)) {
|
|
54
60
|
console.warn("[Trivious] Could not find parent for subcommand group", group.data.name);
|
|
@@ -64,6 +70,7 @@ async function setChildrenToParents(data) {
|
|
|
64
70
|
slashCommand.data.addSubcommandGroup(group.data);
|
|
65
71
|
}
|
|
66
72
|
for (const [subcommand, directory] of data.SlashSubcommand) {
|
|
73
|
+
if (!subcommand.active || subcommand.context !== "SlashSubcommand") continue;
|
|
67
74
|
const parent = subcommand.parent || getDataFromCommandSet(data.SlashSubcommandGroup, { matchParentDirectory: directory }) || getDataFromCommandSet(data.SlashCommand, { matchParentDirectory: directory });
|
|
68
75
|
if (!parent || !("addSubcommand" in parent.data)) {
|
|
69
76
|
console.warn("[Trivious] Could not find parent for subcommand", subcommand.data.name);
|
|
@@ -72,7 +79,7 @@ async function setChildrenToParents(data) {
|
|
|
72
79
|
if (!parent.subcommands) parent.subcommands = new Collection();
|
|
73
80
|
if (parent.subcommands.has(subcommand.data.name))
|
|
74
81
|
console.warn(
|
|
75
|
-
`[Trivious] Subcommand '${subcommand.data.name}' under
|
|
82
|
+
`[Trivious] Subcommand '${subcommand.data.name}' under parent '${parent.data.name}' has been overridden by a subcommand with the same name`
|
|
76
83
|
);
|
|
77
84
|
subcommand.parent = parent;
|
|
78
85
|
parent.subcommands.set(subcommand.data.name, subcommand);
|
|
@@ -82,6 +89,7 @@ async function setChildrenToParents(data) {
|
|
|
82
89
|
async function registerSlashCommands(client, data) {
|
|
83
90
|
await setChildrenToParents(data);
|
|
84
91
|
for (const [slashCommand] of data.SlashCommand) {
|
|
92
|
+
if (!slashCommand.active || slashCommand.context !== "SlashCommand") continue;
|
|
85
93
|
if (client.stores.commands.chatInput.get(slashCommand.data.name))
|
|
86
94
|
client.logger.warn(
|
|
87
95
|
`Command '${slashCommand.data.name}' has been overridden by a command with the same name`
|
|
@@ -92,6 +100,7 @@ async function registerSlashCommands(client, data) {
|
|
|
92
100
|
}
|
|
93
101
|
async function registerContextMenuCommands(client, data) {
|
|
94
102
|
for (const [contextCommand] of data.ContextCommand) {
|
|
103
|
+
if (!contextCommand.active) continue;
|
|
95
104
|
if (client.stores.commands.chatInput.get(contextCommand.data.name))
|
|
96
105
|
client.logger.warn(
|
|
97
106
|
`Command '${contextCommand.data.name}' has been overridden by a command with the same name`
|
|
@@ -105,6 +114,31 @@ async function registerContextMenuCommands(client, data) {
|
|
|
105
114
|
client.stores.commands.context.set(contextCommand.data.name, contextCommand);
|
|
106
115
|
}
|
|
107
116
|
}
|
|
117
|
+
async function registerMessageCommands(client, data) {
|
|
118
|
+
for (const [command] of data.MessageCommand) {
|
|
119
|
+
if (!command.active || command.context !== "MessageCommand") continue;
|
|
120
|
+
if (client.stores.commands.chatInput.get(command.name))
|
|
121
|
+
client.logger.warn(
|
|
122
|
+
`Message command '${command.name}' has been overridden by a command with the same name`
|
|
123
|
+
);
|
|
124
|
+
const processedCommand = processPartialMessageCommand(client, command);
|
|
125
|
+
client.logger.debug("Registered message command:", command.name);
|
|
126
|
+
client.stores.commands.message.set(command.name, processedCommand);
|
|
127
|
+
if (command.aliases)
|
|
128
|
+
command.aliases.forEach((alias) => {
|
|
129
|
+
client.logger.debug(
|
|
130
|
+
"Registered message command alias:",
|
|
131
|
+
alias.trim().toLowerCase(),
|
|
132
|
+
"->",
|
|
133
|
+
command.name.toLowerCase()
|
|
134
|
+
);
|
|
135
|
+
client.stores.messageCommandAliases.set(
|
|
136
|
+
alias.trim().toLowerCase(),
|
|
137
|
+
command.name.toLowerCase()
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
108
142
|
async function registerCommands(client, directory) {
|
|
109
143
|
if (!existsSync(directory))
|
|
110
144
|
throw new TriviousError(
|
|
@@ -115,7 +149,8 @@ async function registerCommands(client, directory) {
|
|
|
115
149
|
SlashCommand: /* @__PURE__ */ new Set(),
|
|
116
150
|
SlashSubcommand: /* @__PURE__ */ new Set(),
|
|
117
151
|
SlashSubcommandGroup: /* @__PURE__ */ new Set(),
|
|
118
|
-
ContextCommand: /* @__PURE__ */ new Set()
|
|
152
|
+
ContextCommand: /* @__PURE__ */ new Set(),
|
|
153
|
+
MessageCommand: /* @__PURE__ */ new Set()
|
|
119
154
|
};
|
|
120
155
|
client.logger.debug("Starting command registration in:", directory);
|
|
121
156
|
const files = fs.glob(path.join(directory, "**/*.{js,ts}"));
|
|
@@ -126,8 +161,13 @@ async function registerCommands(client, directory) {
|
|
|
126
161
|
processedDirectories.add(parentDir);
|
|
127
162
|
await parseDirectory(data, parentDir);
|
|
128
163
|
}
|
|
164
|
+
const presetsDirectory = path.resolve(import.meta.dirname, "presets");
|
|
165
|
+
if (presetsDirectory && client.trivious.messageCommands)
|
|
166
|
+
await parseDirectory(data, presetsDirectory);
|
|
129
167
|
await registerSlashCommands(client, data);
|
|
168
|
+
await registerMessageCommands(client, data);
|
|
130
169
|
await registerContextMenuCommands(client, data);
|
|
170
|
+
parsedCache.clear();
|
|
131
171
|
}
|
|
132
172
|
export {
|
|
133
173
|
registerCommands as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"sourcesContent":["import {\n\tCollatedCommandData,\n\tCommandSetData,\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 { existsSync, promises as fs } from \"fs\";\nimport path from \"path\";\n\nasync function parseBase<T>(input: string | T, expects?: (base: Partial<T>) => boolean) {\n\tlet base: T | null = null;\n\tif (typeof input === \"string\") {\n\t\tbase = await importFile<T>(input);\n\t} else base = 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<\n\t\t\tSlashCommandData | SlashSubcommandData | SlashSubcommandGroupData | ContextCommandData\n\t\t>(file);\n\t\tif (!base) continue;\n\t\tconst targetSet =\n\t\t\t\"context\" in base\n\t\t\t\t? data[base.context]\n\t\t\t\t: \"commandType\" in base &&\n\t\t\t\t\t (base.commandType === ApplicationCommandType.Message ||\n\t\t\t\t\t\t\tbase.commandType === ApplicationCommandType.User)\n\t\t\t\t\t? data.ContextCommand\n\t\t\t\t\t: null;\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\nasync function registerSlashCommands(client: TriviousClient, data: CollatedCommandData) {\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\tclient.logger.warn(\n\t\t\t\t`Command '${slashCommand.data.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tclient.logger.debug(\"Registered slash command:\", slashCommand.data.name);\n\t\tclient.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\t}\n}\n\nasync function registerContextMenuCommands(client: TriviousClient, data: CollatedCommandData) {\n\tfor (const [contextCommand] of data.ContextCommand) {\n\t\tif (client.stores.commands.chatInput.get(contextCommand.data.name))\n\t\t\tclient.logger.warn(\n\t\t\t\t`Command '${contextCommand.data.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tclient.logger.debug(\n\t\t\t\"Registered\",\n\t\t\tApplicationCommandType[contextCommand.commandType],\n\t\t\t\"context command:\",\n\t\t\tcontextCommand.data.name\n\t\t);\n\t\tclient.stores.commands.context.set(contextCommand.data.name, contextCommand);\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 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\tContextCommand: new Set<CommandSetData<ContextCommandData>>(),\n\t};\n\tclient.logger.debug(\"Starting command registration in:\", directory);\n\tconst files = fs.glob(path.join(directory, \"**/*.{js,ts}\"));\n\tconst processedDirectories = new Set<string>();\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 registerSlashCommands(client, data);\n\tawait registerContextMenuCommands(client, data);\n}\n"],"mappings":"AASA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB,kBAAkB;AACnD,SAAS,YAAY,YAAY,UAAU;AAC3C,OAAO,UAAU;AAEjB,eAAe,UAAa,OAAmB,SAAyC;AACvF,MAAI,OAAiB;AACrB,MAAI,OAAO,UAAU,UAAU;AAC9B,WAAO,MAAM,WAAc,KAAK;AAAA,EACjC,MAAO,QAAO;AACd,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,QAAQ,OAAO;AAC/B,UAAM,OAA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AI;AAC/C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"sourcesContent":["import {\n\tCollatedCommandData,\n\tCommandSetData,\n\tContextCommandData,\n\tMessageCommandData,\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 { existsSync, promises as fs } from \"fs\";\nimport path from \"path\";\nimport { processPartialMessageCommand } from \"./handlers/message.commands.js\";\n\nconst parsedCache = new Set<string>();\nasync function parseBase<T>(input: string | T, expects?: (base: Partial<T>) => boolean) {\n\tlet base: T | null = null;\n\tif (typeof input === \"string\") {\n\t\tconst absolutePath = path.resolve(input);\n\t\tif (parsedCache.has(absolutePath)) return null;\n\t\tbase = await importFile<T>(input);\n\t\tparsedCache.add(absolutePath);\n\t} else base = 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<\n\t\t\t| SlashCommandData\n\t\t\t| SlashSubcommandData\n\t\t\t| SlashSubcommandGroupData\n\t\t\t| ContextCommandData\n\t\t\t| MessageCommandData\n\t\t>(file);\n\t\tif (!base) continue;\n\t\tconst targetSet =\n\t\t\t\"context\" in base\n\t\t\t\t? data[base.context]\n\t\t\t\t: \"commandType\" in base &&\n\t\t\t\t\t (base.commandType === ApplicationCommandType.Message ||\n\t\t\t\t\t\t\tbase.commandType === ApplicationCommandType.User)\n\t\t\t\t\t? data.ContextCommand\n\t\t\t\t\t: null;\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\tif (group.context !== \"SlashSubcommandGroup\") continue;\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\tif (!subcommand.active || subcommand.context !== \"SlashSubcommand\") continue;\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 parent '${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\nasync function registerSlashCommands(client: TriviousClient, data: CollatedCommandData) {\n\tawait setChildrenToParents(data);\n\tfor (const [slashCommand] of data.SlashCommand) {\n\t\tif (!slashCommand.active || slashCommand.context !== \"SlashCommand\") continue;\n\t\tif (client.stores.commands.chatInput.get(slashCommand.data.name))\n\t\t\tclient.logger.warn(\n\t\t\t\t`Command '${slashCommand.data.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tclient.logger.debug(\"Registered slash command:\", slashCommand.data.name);\n\t\tclient.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\t}\n}\n\nasync function registerContextMenuCommands(client: TriviousClient, data: CollatedCommandData) {\n\tfor (const [contextCommand] of data.ContextCommand) {\n\t\tif (!contextCommand.active) continue;\n\t\tif (client.stores.commands.chatInput.get(contextCommand.data.name))\n\t\t\tclient.logger.warn(\n\t\t\t\t`Command '${contextCommand.data.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tclient.logger.debug(\n\t\t\t\"Registered\",\n\t\t\tApplicationCommandType[contextCommand.commandType],\n\t\t\t\"context command:\",\n\t\t\tcontextCommand.data.name\n\t\t);\n\t\tclient.stores.commands.context.set(contextCommand.data.name, contextCommand);\n\t}\n}\n\nasync function registerMessageCommands(client: TriviousClient, data: CollatedCommandData) {\n\tfor (const [command] of data.MessageCommand) {\n\t\tif (!command.active || command.context !== \"MessageCommand\") continue;\n\t\tif (client.stores.commands.chatInput.get(command.name))\n\t\t\tclient.logger.warn(\n\t\t\t\t`Message command '${command.name}' has been overridden by a command with the same name`\n\t\t\t);\n\t\tconst processedCommand = processPartialMessageCommand(client, command);\n\t\tclient.logger.debug(\"Registered message command:\", command.name);\n\t\tclient.stores.commands.message.set(command.name, processedCommand);\n\t\tif (command.aliases)\n\t\t\tcommand.aliases.forEach((alias) => {\n\t\t\t\tclient.logger.debug(\n\t\t\t\t\t\"Registered message command alias:\",\n\t\t\t\t\talias.trim().toLowerCase(),\n\t\t\t\t\t\"->\",\n\t\t\t\t\tcommand.name.toLowerCase()\n\t\t\t\t);\n\t\t\t\tclient.stores.messageCommandAliases.set(\n\t\t\t\t\talias.trim().toLowerCase(),\n\t\t\t\t\tcommand.name.toLowerCase()\n\t\t\t\t);\n\t\t\t});\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 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\tContextCommand: new Set<CommandSetData<ContextCommandData>>(),\n\t\tMessageCommand: new Set<CommandSetData<MessageCommandData>>(),\n\t};\n\tclient.logger.debug(\"Starting command registration in:\", directory);\n\tconst files = fs.glob(path.join(directory, \"**/*.{js,ts}\"));\n\tconst processedDirectories = new Set<string>();\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\tconst presetsDirectory = path.resolve(import.meta.dirname, \"presets\");\n\tif (presetsDirectory && client.trivious.messageCommands)\n\t\tawait parseDirectory(data, presetsDirectory);\n\tawait registerSlashCommands(client, data);\n\tawait registerMessageCommands(client, data);\n\tawait registerContextMenuCommands(client, data);\n\tparsedCache.clear();\n}\n"],"mappings":"AAUA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB,kBAAkB;AACnD,SAAS,YAAY,YAAY,UAAU;AAC3C,OAAO,UAAU;AACjB,SAAS,oCAAoC;AAE7C,MAAM,cAAc,oBAAI,IAAY;AACpC,eAAe,UAAa,OAAmB,SAAyC;AACvF,MAAI,OAAiB;AACrB,MAAI,OAAO,UAAU,UAAU;AAC9B,UAAM,eAAe,KAAK,QAAQ,KAAK;AACvC,QAAI,YAAY,IAAI,YAAY,EAAG,QAAO;AAC1C,WAAO,MAAM,WAAc,KAAK;AAChC,gBAAY,IAAI,YAAY;AAAA,EAC7B,MAAO,QAAO;AACd,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,QAAQ,OAAO;AAC/B,UAAM,OAAO,MAAM,UAMjB,IAAI;AACN,QAAI,CAAC,KAAM;AACX,UAAM,YACL,aAAa,OACV,KAAK,KAAK,OAAO,IACjB,iBAAiB,SACf,KAAK,gBAAgB,uBAAuB,WAC7C,KAAK,gBAAgB,uBAAuB,QAC5C,K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AC1B;AAAA,MACD,CAAC;AAAA,EACH;AACD;AAEA,eAAO,iBAAwC,QAAwB,WAAmB;AACzF,MAAI,CAAC,WAAW,SAAS;AACxB,UAAM,IAAI;AAAA,MACT,iDAAiD,SAAS;AAAA,MAC1D;AAAA,IACD;AACD,QAAM,OAA4B;AAAA,IACjC,cAAc,oBAAI,IAAsC;AAAA,IACxD,iBAAiB,oBAAI,IAAyC;AAAA,IAC9D,sBAAsB,oBAAI,IAA8C;AAAA,IACxE,gBAAgB,oBAAI,IAAwC;AAAA,IAC5D,gBAAgB,oBAAI,IAAwC;AAAA,EAC7D;AACA,SAAO,OAAO,MAAM,qCAAqC,SAAS;AAClE,QAAM,QAAQ,GAAG,KAAK,KAAK,KAAK,WAAW,cAAc,CAAC;AAC1D,QAAM,uBAAuB,oBAAI,IAAY;AAC7C,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,mBAAmB,KAAK,QAAQ,YAAY,SAAS,SAAS;AACpE,MAAI,oBAAoB,OAAO,SAAS;AACvC,UAAM,eAAe,MAAM,gBAAgB;AAC5C,QAAM,sBAAsB,QAAQ,IAAI;AACxC,QAAM,wBAAwB,QAAQ,IAAI;AAC1C,QAAM,4BAA4B,QAAQ,IAAI;AAC9C,cAAY,MAAM;AACnB;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { k as MessageCommandArgument, p as MessageCommandData, T as TriviousClient } from '../../modules.types-BgGFvIsW.js';
|
|
2
|
+
import 'discord.js';
|
|
3
|
+
import '../client/client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
5
|
+
import '../client/logger.js';
|
|
6
|
+
|
|
7
|
+
declare function resolveCommand(client: TriviousClient, query: string): MessageCommandData<true, readonly MessageCommandArgument[] | undefined, boolean> | undefined;
|
|
8
|
+
declare function formatUsage(prefix: string, command: MessageCommandData<true>): string;
|
|
9
|
+
declare function formatArguments(args?: readonly MessageCommandArgument[]): string;
|
|
10
|
+
declare function formatAliases(prefix: string, aliases: string[] | undefined): string;
|
|
11
|
+
|
|
12
|
+
export { formatAliases, formatArguments, formatUsage, resolveCommand };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { bold, inlineCode } from "discord.js";
|
|
2
|
+
function resolveCommand(client, query) {
|
|
3
|
+
const targetName = client.stores.messageCommandAliases.get(query) ?? query;
|
|
4
|
+
return client.stores.commands.message.get(targetName);
|
|
5
|
+
}
|
|
6
|
+
function formatUsage(prefix, command) {
|
|
7
|
+
if (!command.arguments?.length) return `${prefix}${command.name}`;
|
|
8
|
+
const formattedArgs = command.arguments.map((arg) => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(" ");
|
|
9
|
+
return `${prefix}${command.name} ${formattedArgs}`;
|
|
10
|
+
}
|
|
11
|
+
function formatArguments(args) {
|
|
12
|
+
if (!args?.length) return "";
|
|
13
|
+
const list = args.map((arg) => `-# ${bold(arg.name)} (${arg.dataType}) - ${arg.description}`).join("\n");
|
|
14
|
+
return `
|
|
15
|
+
Arguments:
|
|
16
|
+
${list}`;
|
|
17
|
+
}
|
|
18
|
+
function formatAliases(prefix, aliases) {
|
|
19
|
+
if (!aliases || aliases.length === 0) return "";
|
|
20
|
+
const formattedList = aliases.map((alias) => inlineCode(`${prefix}${alias}`)).join(", ");
|
|
21
|
+
return `
|
|
22
|
+
|
|
23
|
+
Aliases: ${formattedList}`;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
formatAliases,
|
|
27
|
+
formatArguments,
|
|
28
|
+
formatUsage,
|
|
29
|
+
resolveCommand
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/utility.ts"],"sourcesContent":["import { MessageCommandArgument, MessageCommandData, TriviousClient } from \"#typings\";\nimport { bold, inlineCode } from \"discord.js\";\n\nexport function resolveCommand(client: TriviousClient, query: string) {\n\tconst targetName = client.stores.messageCommandAliases.get(query) ?? query;\n\treturn client.stores.commands.message.get(targetName);\n}\n\nexport function formatUsage(prefix: string, command: MessageCommandData<true>): string {\n\tif (!command.arguments?.length) return `${prefix}${command.name}`;\n\n\tconst formattedArgs = command.arguments\n\t\t.map((arg: any) => (arg.required ? `<${arg.name}>` : `[${arg.name}]`))\n\t\t.join(\" \");\n\n\treturn `${prefix}${command.name} ${formattedArgs}`;\n}\n\nexport function formatArguments(args?: readonly MessageCommandArgument[]): string {\n\tif (!args?.length) return \"\";\n\n\tconst list = args\n\t\t.map((arg) => `-# ${bold(arg.name)} (${arg.dataType}) - ${arg.description}`)\n\t\t.join(\"\\n\");\n\n\treturn `\\nArguments:\\n${list}`;\n}\n\nexport function formatAliases(prefix: string, aliases: string[] | undefined): string {\n\tif (!aliases || aliases.length === 0) return \"\";\n\tconst formattedList = aliases.map((alias: string) => inlineCode(`${prefix}${alias}`)).join(\", \");\n\treturn `\\n\\nAliases: ${formattedList}`;\n}\n"],"mappings":"AACA,SAAS,MAAM,kBAAkB;AAE1B,SAAS,eAAe,QAAwB,OAAe;AACrE,QAAM,aAAa,OAAO,OAAO,sBAAsB,IAAI,KAAK,KAAK;AACrE,SAAO,OAAO,OAAO,SAAS,QAAQ,IAAI,UAAU;AACrD;AAEO,SAAS,YAAY,QAAgB,SAA2C;AACtF,MAAI,CAAC,QAAQ,WAAW,OAAQ,QAAO,GAAG,MAAM,GAAG,QAAQ,IAAI;AAE/D,QAAM,gBAAgB,QAAQ,UAC5B,IAAI,CAAC,QAAc,IAAI,WAAW,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,GAAI,EACpE,KAAK,GAAG;AAEV,SAAO,GAAG,MAAM,GAAG,QAAQ,IAAI,IAAI,aAAa;AACjD;AAEO,SAAS,gBAAgB,MAAkD;AACjF,MAAI,CAAC,MAAM,OAAQ,QAAO;AAE1B,QAAM,OAAO,KACX,IAAI,CAAC,QAAQ,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,OAAO,IAAI,WAAW,EAAE,EAC1E,KAAK,IAAI;AAEX,SAAO;AAAA;AAAA,EAAiB,IAAI;AAC7B;AAEO,SAAS,cAAc,QAAgB,SAAuC;AACpF,MAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO;AAC7C,QAAM,gBAAgB,QAAQ,IAAI,CAAC,UAAkB,WAAW,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI;AAC/F,SAAO;AAAA;AAAA,WAAgB,aAAa;AACrC;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as Component, g as ComponentContext } from '../../modules.types-
|
|
1
|
+
import { f as Component, g as ComponentContext } from '../../modules.types-BgGFvIsW.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/components/builders.components.ts"],"sourcesContent":["import { Component, ComponentContext } from \"
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction } from '../../modules.types-
|
|
2
|
+
export { f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction } from '../../modules.types-BgGFvIsW.js';
|
|
3
3
|
import '../permissions/permissions.types.js';
|
|
4
4
|
import '../client/client.types.js';
|
|
5
5
|
import '../client/logger.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/components/components.types.ts"],"sourcesContent":["import { CommandPermissionValues, TriviousClient } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/components/components.types.ts"],"sourcesContent":["import { CommandPermissionValues, TriviousClient } from \"#typings\";\nimport { AnySelectMenuInteraction, ButtonInteraction, ModalSubmitInteraction } from \"discord.js\";\n\nexport type ComponentFlags = \"Cached\" | \"DeferReply\" | \"EphemeralReply\" | \"ExpectModal\";\nexport type ComponentInteraction =\n\t| AnySelectMenuInteraction\n\t| ButtonInteraction\n\t| ModalSubmitInteraction;\n\nexport enum ComponentContext {\n\tButton,\n\tSelectMenu,\n\tModal,\n}\n\ntype ContextualComponentInteraction<Context extends ComponentContext = ComponentContext> =\n\tContext extends ComponentContext.Button\n\t\t? ButtonInteraction\n\t\t: Context extends ComponentContext.SelectMenu\n\t\t\t? AnySelectMenuInteraction\n\t\t\t: Context extends ComponentContext.Modal\n\t\t\t\t? ModalSubmitInteraction\n\t\t\t\t: ComponentInteraction;\n\n/**\n * Trivious component\n * @param context The component context\n * @param identifier The unique identifier inside the custom id\n * @param flags The component flags\n * @param execute Component handler\n */\nexport interface Component<Context extends ComponentContext = ComponentContext> {\n\t/**\n\t * @deprecated Use context instead\n\t */\n\tcomponent?: Context;\n\tcontext: Context;\n\tidentifier: string;\n\tflags?: ComponentFlags[];\n\tpermissions?: CommandPermissionValues;\n\texecute: (\n\t\tclient: TriviousClient,\n\t\tinteraction: ContextualComponentInteraction<Context>\n\t) => Promise<void>;\n}\n"],"mappings":"AASO,IAAK,mBAAL,kBAAKA,sBAAL;AACN,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AAHW,SAAAA;AAAA,GAAA;","names":["ComponentContext"]}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { y as default } from '../../modules.types-BgGFvIsW.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import '../permissions/permissions.types.js';
|
|
5
5
|
import '../client/logger.js';
|
|
6
|
-
|
|
7
|
-
declare function registerComponents(client: TriviousClient, directory: string): Promise<void>;
|
|
8
|
-
|
|
9
|
-
export { registerComponents as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComponentContext } from "
|
|
2
|
-
import { TriviousError } from "
|
|
3
|
-
import { importFile } from "
|
|
1
|
+
import { ComponentContext } from "#typings";
|
|
2
|
+
import { TriviousError } from "#utility/errors.js";
|
|
3
|
+
import { importFile } from "#utility/functions.js";
|
|
4
4
|
import { existsSync, promises as fs } from "fs";
|
|
5
5
|
import { join } from "path";
|
|
6
6
|
async function registerComponents(client, directory) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/components/registry.components.ts"],"sourcesContent":["import { Component, ComponentContext, TriviousClient } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/components/registry.components.ts"],"sourcesContent":["import { Component, ComponentContext, TriviousClient } from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport { importFile } from \"#utility/functions.js\";\nimport { existsSync, promises as fs } from \"fs\";\nimport { join } from \"path\";\n\nexport default async function registerComponents(client: TriviousClient, directory: string) {\n\tclient.logger.debug(\"Starting component registration in:\", directory);\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register components; passed directory '${directory} does not exist!'`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\n\tconst files = fs.glob(join(directory, \"**/*.{js,ts}\"));\n\tfor await (const file of files) {\n\t\tconst component = await importFile<Component>(file);\n\t\tif (\n\t\t\t!component ||\n\t\t\t!(\n\t\t\t\t(\"component\" in component || \"context\" in component) &&\n\t\t\t\t\"identifier\" in component &&\n\t\t\t\t\"execute\" in component\n\t\t\t)\n\t\t)\n\t\t\tcontinue;\n\n\t\tif (client.stores.components.get(component.identifier))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Component identifier '${component.identifier}' with the context '${ComponentContext[component.context]}' has a duplicate and has been overridden`\n\t\t\t);\n\n\t\tclient.logger.debug(\"Registered component:\", component.identifier);\n\t\tclient.stores.components.set(component.identifier, component);\n\t}\n}\n"],"mappings":"AAAA,SAAoB,wBAAwC;AAC5D,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,YAAY,YAAY,UAAU;AAC3C,SAAS,YAAY;AAErB,eAAO,mBAA0C,QAAwB,WAAmB;AAC3F,SAAO,OAAO,MAAM,uCAAuC,SAAS;AACpE,MAAI,CAAC,WAAW,SAAS;AACxB,UAAM,IAAI;AAAA,MACT,oDAAoD,SAAS;AAAA,MAC7D;AAAA,IACD;AAED,QAAM,QAAQ,GAAG,KAAK,KAAK,WAAW,cAAc,CAAC;AACrD,mBAAiB,QAAQ,OAAO;AAC/B,UAAM,YAAY,MAAM,WAAsB,IAAI;AAClD,QACC,CAAC,aACD,GACE,eAAe,aAAa,aAAa,cAC1C,gBAAgB,aAChB,aAAa;AAGd;AAED,QAAI,OAAO,OAAO,WAAW,IAAI,UAAU,UAAU;AACpD,cAAQ;AAAA,QACP,oCAAoC,UAAU,UAAU,uBAAuB,iBAAiB,UAAU,OAAO,CAAC;AAAA,MACnH;AAED,WAAO,OAAO,MAAM,yBAAyB,UAAU,UAAU;AACjE,WAAO,OAAO,WAAW,IAAI,UAAU,YAAY,SAAS;AAAA,EAC7D;AACD;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../client/client.types.js';
|
|
2
|
-
import { g as ComponentContext } from '../../modules.types-
|
|
2
|
+
import { g as ComponentContext } from '../../modules.types-BgGFvIsW.js';
|
|
3
3
|
import '../permissions/permissions.types.js';
|
|
4
4
|
import 'discord.js';
|
|
5
5
|
import '../client/logger.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentCustomId } from './customid.types.js';
|
|
2
2
|
import '../client/client.types.js';
|
|
3
3
|
import 'discord.js';
|
|
4
|
-
import '../../modules.types-
|
|
4
|
+
import '../../modules.types-BgGFvIsW.js';
|
|
5
5
|
import '../permissions/permissions.types.js';
|
|
6
6
|
import '../client/logger.js';
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/customId/methods.customid.ts"],"sourcesContent":["import { ComponentContext, ComponentCustomId, ComponentTag } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/customId/methods.customid.ts"],"sourcesContent":["import { ComponentContext, ComponentCustomId, ComponentTag } from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\n\nconst customId = {\n\t/**\n\t * Decode a customId into its parts\n\t */\n\tdecode: (customId: string) => {\n\t\tconst [context, identifier, info] = customId.split(\":\") as [\n\t\t\tComponentContext,\n\t\t\tstring,\n\t\t\tstring | undefined,\n\t\t];\n\t\tconst [data, ...tags] = info\n\t\t\t? (info.split(\".\") as [string | undefined, ...ComponentTag[]])\n\t\t\t: [undefined, undefined];\n\n\t\treturn {\n\t\t\tcontext,\n\t\t\tidentifier,\n\t\t\tdata,\n\t\t\ttags,\n\t\t} as ComponentCustomId;\n\t},\n\t/**\n\t * Encode a customId\n\t */\n\tencode: (options: ComponentCustomId) => {\n\t\tconst { context, identifier, data, tags } = options;\n\t\tlet customId = `${context}:${identifier}`;\n\n\t\tif (data) customId += `:${data}`;\n\t\tif (tags) customId += `.${tags.join(\".\")}`;\n\n\t\tif (customId.length > 100) throw new TriviousError(\"Encoded customId exceeds 100 characters.\");\n\t\treturn customId;\n\t},\n} as const;\n\nexport default customId;\n"],"mappings":"AACA,SAAS,qBAAqB;AAE9B,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAIhB,QAAQ,CAACA,cAAqB;AAC7B,UAAM,CAAC,SAAS,YAAY,IAAI,IAAIA,UAAS,MAAM,GAAG;AAKtD,UAAM,CAAC,MAAM,GAAG,IAAI,IAAI,OACpB,KAAK,MAAM,GAAG,IACf,CAAC,QAAW,MAAS;AAExB,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAIA,QAAQ,CAAC,YAA+B;AACvC,UAAM,EAAE,SAAS,YAAY,MAAM,KAAK,IAAI;AAC5C,QAAIA,YAAW,GAAG,OAAO,IAAI,UAAU;AAEvC,QAAI,KAAM,CAAAA,aAAY,IAAI,IAAI;AAC9B,QAAI,KAAM,CAAAA,aAAY,IAAI,KAAK,KAAK,GAAG,CAAC;AAExC,QAAIA,UAAS,SAAS,IAAK,OAAM,IAAI,cAAc,0CAA0C;AAC7F,WAAOA;AAAA,EACR;AACD;AAEA,IAAO,2BAAQ;","names":["customId"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/events/presets/clientReady.ts"],"sourcesContent":["import { Event } from \"
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/events/presets/clientReady.ts"],"sourcesContent":["import { Event } from \"#typings\";\n\nexport default {\n\tname: \"clientReady\",\n\tonce: true,\n\tasync execute(client) {\n\t\tconsole.log(`Successfully logged into ${client.user?.username}`);\n\t},\n} satisfies Event<\"clientReady\">;\n"],"mappings":"AAEA,IAAO,sBAAQ;AAAA,EACd,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM,QAAQ,QAAQ;AACrB,YAAQ,IAAI,4BAA4B,OAAO,MAAM,QAAQ,EAAE;AAAA,EAChE;AACD;","names":[]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { T as TriviousClient } from '../../../modules.types-
|
|
2
|
+
import { T as TriviousClient } from '../../../modules.types-BgGFvIsW.js';
|
|
3
3
|
import '../../client/client.types.js';
|
|
4
4
|
import '../../permissions/permissions.types.js';
|
|
5
5
|
import '../../client/logger.js';
|
|
6
6
|
|
|
7
7
|
declare const _default: {
|
|
8
8
|
name: "interactionCreate";
|
|
9
|
+
conditions(client: TriviousClient): [boolean, string][];
|
|
9
10
|
execute(client: TriviousClient, interaction: discord_js.Interaction<discord_js.CacheType>): Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import customId from "#feature/customId/methods.customid.js";
|
|
2
|
+
import { canMemberRunCommand } from "#feature/permissions/methods.permissions.js";
|
|
3
|
+
import { handleSlashCommand, interactionReply } from "#trivious";
|
|
4
4
|
import {
|
|
5
5
|
ComponentContext
|
|
6
|
-
} from "
|
|
6
|
+
} from "#typings";
|
|
7
7
|
import {
|
|
8
8
|
ApplicationCommandType,
|
|
9
9
|
ButtonInteraction,
|
|
@@ -29,6 +29,11 @@ function validateMemberPermissionsForSubcommand(client, command, interaction) {
|
|
|
29
29
|
}
|
|
30
30
|
var interactionCreate_default = {
|
|
31
31
|
name: "interactionCreate",
|
|
32
|
+
conditions(client) {
|
|
33
|
+
return [
|
|
34
|
+
[client.stores.commands.chatInput.size > 0, "At least one (1) slash command registered."]
|
|
35
|
+
];
|
|
36
|
+
},
|
|
32
37
|
async execute(client, interaction) {
|
|
33
38
|
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
|
|
34
39
|
const { commandName } = interaction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"sourcesContent":["import customId from \"#feature/customId/methods.customid.js\";\nimport { canMemberRunCommand } from \"#feature/permissions/methods.permissions.js\";\nimport { handleSlashCommand, interactionReply } from \"#trivious\";\nimport {\n\tComponentContext,\n\tSlashCommandData,\n\tTriviousClient,\n\ttype ContextCommandData,\n\ttype Event,\n} from \"#typings\";\nimport {\n\tApplicationCommandType,\n\tButtonInteraction,\n\tChatInputCommandInteraction,\n\tGuildMember,\n\tMessageContextMenuCommandInteraction,\n\tModalSubmitInteraction,\n\tUserContextMenuCommandInteraction,\n} from \"discord.js\";\n\n/**\n * Check if the command is a subcommand and validate whether the member can run the command based on subcommand permissions\n */\nfunction validateMemberPermissionsForSubcommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData | ContextCommandData,\n\tinteraction:\n\t\t| ChatInputCommandInteraction\n\t\t| MessageContextMenuCommandInteraction\n\t\t| UserContextMenuCommandInteraction\n): [boolean, string] {\n\tif (!(\"subcommands\" in command)) return [false, \"Cannot validate subcommand permissions\"];\n\tif (!interaction.isChatInputCommand()) return [false, \"Cannot validate subcommand permissions\"];\n\n\tconst { options } = interaction;\n\n\tconst subcommandName = options.getSubcommand(false);\n\tconst groupName = options.getSubcommandGroup(false);\n\tif (!subcommandName) return [false, \"Cannot validate subcommand permissions\"];\n\n\tif (groupName) {\n\t\tconst group = command.subcommandGroups?.get(groupName);\n\t\tif (!group) return [false, \"Cannot validate subcommand permissions\"];\n\n\t\tconst subcommand = group.subcommands.get(subcommandName);\n\t\tif (!subcommand) return [false, \"Cannot validate subcommand permissions\"];\n\n\t\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember);\n\t}\n\n\tconst subcommand = command.subcommands?.get(subcommandName);\n\tif (!subcommand) return [false, \"Cannot validate subcommand permissions\"];\n\n\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember);\n}\n\nexport default {\n\tname: \"interactionCreate\",\n\tconditions(client) {\n\t\treturn [\n\t\t\t[client.stores.commands.chatInput.size > 0, \"At least one (1) slash command registered.\"],\n\t\t];\n\t},\n\tasync execute(client, interaction) {\n\t\tif (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {\n\t\t\tconst { commandName } = interaction;\n\n\t\t\tconst storeToCheck = interaction.isChatInputCommand()\n\t\t\t\t? client.stores.commands.chatInput\n\t\t\t\t: client.stores.commands.context;\n\t\t\tconst command = storeToCheck.get(commandName);\n\n\t\t\tif (!command) {\n\t\t\t\tawait interactionReply({\n\t\t\t\t\tinteraction,\n\t\t\t\t\treplyPayload: { content: \"Command is outdated, inactive, or does not have a handler!\" },\n\t\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst subcommandPerms = validateMemberPermissionsForSubcommand(client, command, interaction);\n\t\t\tconst commandPerms = canMemberRunCommand(client, command, interaction.member as GuildMember);\n\t\t\tconst hasPermission = subcommandPerms[0] && commandPerms[0] ? true : false;\n\t\t\tif (!hasPermission) {\n\t\t\t\tawait interactionReply({\n\t\t\t\t\tinteraction,\n\t\t\t\t\treplyPayload: {\n\t\t\t\t\t\tcontent: `You do not have permission to run this command`,\n\t\t\t\t\t},\n\t\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tcommand.commandType === ApplicationCommandType.ChatInput &&\n\t\t\t\tinteraction.isChatInputCommand()\n\t\t\t) {\n\t\t\t\tawait handleSlashCommand(client, command, interaction);\n\t\t\t} else {\n\t\t\t\tawait (command as ContextCommandData).execute(client, interaction as never);\n\t\t\t}\n\t\t} else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {\n\t\t\tconst { context, identifier, tags } = customId.decode(interaction.customId);\n\t\t\tif (context === ComponentContext.Button && !(interaction instanceof ButtonInteraction))\n\t\t\t\treturn;\n\t\t\tif (context === ComponentContext.Modal && !(interaction instanceof ModalSubmitInteraction))\n\t\t\t\treturn;\n\t\t\tif (tags && tags.includes(\"awaited\")) return;\n\n\t\t\tconst component = client.stores.components.get(identifier);\n\n\t\t\tif (!component) {\n\t\t\t\tawait interactionReply({\n\t\t\t\t\tinteraction,\n\t\t\t\t\treplyPayload: { content: \"Command is outdated, inactive, or does not have a handler!\" },\n\t\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst hasPermission = canMemberRunCommand(\n\t\t\t\tclient,\n\t\t\t\tcomponent,\n\t\t\t\tinteraction.member as GuildMember\n\t\t\t);\n\t\t\tif (!hasPermission) {\n\t\t\t\tawait interactionReply({\n\t\t\t\t\tinteraction,\n\t\t\t\t\treplyPayload: { content: \"You do not have permission to use this component\" },\n\t\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait component.execute(client, interaction);\n\t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;AACD;AAAA,MACD;AAEA,YAAM,gBAAgB;AAAA,QACrB;AAAA,QACA;AAAA,QACA,YAAY;AAAA,MACb;AACA,UAAI,CAAC,eAAe;AACnB,cAAM,iBAAiB;AAAA,UACtB;AAAA,UACA,cAAc,EAAE,SAAS,mDAAmD;AAAA,UAC5E,OAAO,CAAC,gBAAgB;AAAA,QACzB,CAAC;AACD;AAAA,MACD;AACA,YAAM,UAAU,QAAQ,QAAQ,WAAW;AAAA,IAC5C;AAAA,EACD;AACD;","names":["subcommand"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OmitPartialGroupDMChannel, Message } from 'discord.js';
|
|
2
|
+
import { T as TriviousClient } from '../../../modules.types-BgGFvIsW.js';
|
|
3
|
+
import '../../client/client.types.js';
|
|
4
|
+
import '../../permissions/permissions.types.js';
|
|
5
|
+
import '../../client/logger.js';
|
|
6
|
+
|
|
7
|
+
declare const _default: {
|
|
8
|
+
name: "messageCreate";
|
|
9
|
+
execute(client: TriviousClient, message: OmitPartialGroupDMChannel<Message<boolean>>): Promise<void>;
|
|
10
|
+
conditions(client: TriviousClient): [boolean, string][];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { _default as default };
|