trivious 2.3.7 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/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 +10 -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 -1
- 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 -1
- 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 -1
- 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 -1
- 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-DLv4ITOW.d.ts → modules.types-BgGFvIsW.d.ts} +61 -7
- package/dist/shared/registries.d.ts +1 -1
- 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 +15 -11
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BitField,
|
|
3
|
+
Collection,
|
|
4
|
+
GatewayIntentBits,
|
|
5
|
+
inlineCode
|
|
6
|
+
} from "discord.js";
|
|
7
|
+
import { canMemberRunCommand } from "#feature/permissions/methods.permissions.js";
|
|
8
|
+
import { parseMessageCommandArgument } from "#trivious";
|
|
9
|
+
async function getCommand(client, commandName, message) {
|
|
10
|
+
const nameLower = commandName.toLowerCase();
|
|
11
|
+
let command = client.stores.commands.message.get(nameLower);
|
|
12
|
+
if (!command) {
|
|
13
|
+
const mappedCommandName = client.stores.messageCommandAliases.get(nameLower);
|
|
14
|
+
command = mappedCommandName ? client.stores.commands.message.get(mappedCommandName) : void 0;
|
|
15
|
+
}
|
|
16
|
+
if (!command || !command.active) {
|
|
17
|
+
await message.reply({
|
|
18
|
+
content: "Invalid command; does not exist, missing handler, or is inactive."
|
|
19
|
+
});
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return command;
|
|
23
|
+
}
|
|
24
|
+
async function doPermissionsCheck(client, command, message) {
|
|
25
|
+
const [hasPermission, reason] = canMemberRunCommand(
|
|
26
|
+
client,
|
|
27
|
+
command,
|
|
28
|
+
message.member || message.author
|
|
29
|
+
);
|
|
30
|
+
if (!hasPermission) {
|
|
31
|
+
await message.reply({
|
|
32
|
+
content: `You do not have permission to run this command: ${reason}`
|
|
33
|
+
});
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
async function doCommandFlagChecks(command, message) {
|
|
39
|
+
if (!command.flags) return false;
|
|
40
|
+
if ("InGuild" in command.flags && !message.member) {
|
|
41
|
+
await message.reply({
|
|
42
|
+
content: "This command can only be ran inside a guild!"
|
|
43
|
+
});
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if ("OutGuild" in command.flags && message.member) {
|
|
47
|
+
await message.reply({
|
|
48
|
+
content: "This command **cannot** be ran inside a guild!"
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
var messageCreate_default = {
|
|
55
|
+
name: "messageCreate",
|
|
56
|
+
async execute(client, message) {
|
|
57
|
+
const config = client.trivious.messageCommands;
|
|
58
|
+
if (!config) {
|
|
59
|
+
return client.logger.warn(
|
|
60
|
+
"At least one message command is registered, but message commands have not been configured in the TriviousClient."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const { prefix } = config;
|
|
64
|
+
if (!message.content.startsWith(prefix)) return;
|
|
65
|
+
const input = message.content.slice(prefix.length);
|
|
66
|
+
const [commandName] = input.split(" ");
|
|
67
|
+
const command = await getCommand(client, commandName, message);
|
|
68
|
+
if (!command) return;
|
|
69
|
+
const hasPermission = await doPermissionsCheck(client, command, message);
|
|
70
|
+
if (!hasPermission) return;
|
|
71
|
+
const failedFlagChecks = await doCommandFlagChecks(command, message);
|
|
72
|
+
if (failedFlagChecks) return;
|
|
73
|
+
let args = null;
|
|
74
|
+
if (command.arguments) {
|
|
75
|
+
const result = input.match(command.metadata.regex);
|
|
76
|
+
if (!result) {
|
|
77
|
+
await message.reply({
|
|
78
|
+
content: `Incorrect command or missing one or more required arguments.
|
|
79
|
+
Expected usage: ${inlineCode(
|
|
80
|
+
command.metadata.usage
|
|
81
|
+
)}.
|
|
82
|
+
-# Use ${inlineCode(`${prefix}help ${command.name}`)} for more information about this command.`
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const matches = result.slice(1, command.arguments.length + 1);
|
|
87
|
+
const rejectedArguments = [];
|
|
88
|
+
args = new Collection();
|
|
89
|
+
matches.forEach((value, index) => {
|
|
90
|
+
const argument = command.arguments[index];
|
|
91
|
+
const [parsedValue, reason] = parseMessageCommandArgument(argument.dataType, value, {
|
|
92
|
+
client,
|
|
93
|
+
name: argument.name,
|
|
94
|
+
guild: message.guild
|
|
95
|
+
});
|
|
96
|
+
if (!parsedValue) {
|
|
97
|
+
rejectedArguments.push([argument.name, reason]);
|
|
98
|
+
}
|
|
99
|
+
args.set(argument.name, parsedValue);
|
|
100
|
+
});
|
|
101
|
+
if (rejectedArguments.length > 0) {
|
|
102
|
+
await message.reply({
|
|
103
|
+
content: `Failed parsing command, one or more arguments were rejected:
|
|
104
|
+
${rejectedArguments.map(([name, reason]) => `-# [${name}] ${reason}`).join("\n")}`
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
await command.execute(client, { message, command, args });
|
|
110
|
+
},
|
|
111
|
+
conditions(client) {
|
|
112
|
+
return [
|
|
113
|
+
[client.stores.commands.message.size > 0, "At least one (1) message command registered."],
|
|
114
|
+
[
|
|
115
|
+
new BitField(client.trivious.intents).has(GatewayIntentBits.MessageContent),
|
|
116
|
+
"TriviousClient has MessageContent gateway intent."
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
new BitField(client.trivious.intents).has(GatewayIntentBits.GuildMessages),
|
|
120
|
+
"TriviousClient has GuildMessages gateway intent."
|
|
121
|
+
]
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export {
|
|
126
|
+
messageCreate_default as default
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=messageCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/events/presets/messageCreate.ts"],"sourcesContent":["import {\n\tBitField,\n\tCollection,\n\tGatewayIntentBits,\n\tinlineCode,\n\tMessage,\n\tOmitPartialGroupDMChannel,\n} from \"discord.js\";\n\nimport { canMemberRunCommand } from \"#feature/permissions/methods.permissions.js\";\nimport { parseMessageCommandArgument } from \"#trivious\";\nimport { Event, MessageCommandData, TriviousClient } from \"#typings\";\n\nasync function getCommand(\n\tclient: TriviousClient,\n\tcommandName: string,\n\tmessage: OmitPartialGroupDMChannel<Message<boolean>>\n): Promise<MessageCommandData<true> | null> {\n\tconst nameLower = commandName.toLowerCase();\n\tlet command = client.stores.commands.message.get(nameLower);\n\n\tif (!command) {\n\t\tconst mappedCommandName = client.stores.messageCommandAliases.get(nameLower);\n\t\tcommand = mappedCommandName ? client.stores.commands.message.get(mappedCommandName) : undefined;\n\t}\n\n\tif (!command || !command.active) {\n\t\tawait message.reply({\n\t\t\tcontent: \"Invalid command; does not exist, missing handler, or is inactive.\",\n\t\t});\n\t\treturn null;\n\t}\n\n\treturn command;\n}\n\nasync function doPermissionsCheck(\n\tclient: TriviousClient,\n\tcommand: MessageCommandData,\n\tmessage: OmitPartialGroupDMChannel<Message<boolean>>\n): Promise<boolean> {\n\tconst [hasPermission, reason] = canMemberRunCommand(\n\t\tclient,\n\t\tcommand,\n\t\tmessage.member || message.author\n\t);\n\n\tif (!hasPermission) {\n\t\tawait message.reply({\n\t\t\tcontent: `You do not have permission to run this command: ${reason}`,\n\t\t});\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nasync function doCommandFlagChecks(\n\tcommand: MessageCommandData,\n\tmessage: OmitPartialGroupDMChannel<Message<boolean>>\n): Promise<boolean> {\n\tif (!command.flags) return false;\n\tif (\"InGuild\" in command.flags && !message.member) {\n\t\tawait message.reply({\n\t\t\tcontent: \"This command can only be ran inside a guild!\",\n\t\t});\n\t\treturn true;\n\t}\n\tif (\"OutGuild\" in command.flags && message.member) {\n\t\tawait message.reply({\n\t\t\tcontent: \"This command **cannot** be ran inside a guild!\",\n\t\t});\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport default {\n\tname: \"messageCreate\",\n\tasync execute(client, message) {\n\t\tconst config = client.trivious.messageCommands;\n\t\tif (!config) {\n\t\t\treturn client.logger.warn(\n\t\t\t\t\"At least one message command is registered, but message commands have not been configured in the TriviousClient.\"\n\t\t\t);\n\t\t}\n\n\t\tconst { prefix } = config;\n\t\tif (!message.content.startsWith(prefix)) return;\n\n\t\tconst input = message.content.slice(prefix.length);\n\t\tconst [commandName] = input.split(\" \");\n\n\t\tconst command = await getCommand(client, commandName, message);\n\t\tif (!command) return;\n\n\t\tconst hasPermission = await doPermissionsCheck(client, command, message);\n\t\tif (!hasPermission) return;\n\n\t\tconst failedFlagChecks = await doCommandFlagChecks(command, message);\n\t\tif (failedFlagChecks) return;\n\n\t\tlet args: Collection<string, any> | null = null;\n\t\tif (command.arguments) {\n\t\t\tconst result = input.match(command.metadata.regex);\n\t\t\tif (!result) {\n\t\t\t\tawait message.reply({\n\t\t\t\t\tcontent: `Incorrect command or missing one or more required arguments.\\nExpected usage: ${inlineCode(\n\t\t\t\t\t\tcommand.metadata.usage\n\t\t\t\t\t)}.\\n-# Use ${inlineCode(`${prefix}help ${command.name}`)} for more information about this command.`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst matches = result.slice(1, command.arguments.length + 1);\n\t\t\tconst rejectedArguments: [string, string][] = [];\n\t\t\targs = new Collection<string, any>();\n\n\t\t\tmatches.forEach((value, index) => {\n\t\t\t\tconst argument = command.arguments![index];\n\t\t\t\tconst [parsedValue, reason] = parseMessageCommandArgument(argument.dataType, value, {\n\t\t\t\t\tclient,\n\t\t\t\t\tname: argument.name,\n\t\t\t\t\tguild: message.guild,\n\t\t\t\t});\n\n\t\t\t\tif (!parsedValue) {\n\t\t\t\t\trejectedArguments.push([argument.name, reason!]);\n\t\t\t\t}\n\n\t\t\t\targs!.set(argument.name, parsedValue);\n\t\t\t});\n\n\t\t\tif (rejectedArguments.length > 0) {\n\t\t\t\tawait message.reply({\n\t\t\t\t\tcontent: `Failed parsing command, one or more arguments were rejected:\\n${rejectedArguments\n\t\t\t\t\t\t.map(([name, reason]) => `-# [${name}] ${reason}`)\n\t\t\t\t\t\t.join(\"\\n\")}`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tawait command.execute(client, { message, command, args });\n\t},\n\n\tconditions(client) {\n\t\treturn [\n\t\t\t[client.stores.commands.message.size > 0, \"At least one (1) message command registered.\"],\n\t\t\t[\n\t\t\t\tnew BitField(client.trivious.intents).has(GatewayIntentBits.MessageContent),\n\t\t\t\t\"TriviousClient has MessageContent gateway intent.\",\n\t\t\t],\n\t\t\t[\n\t\t\t\tnew BitField(client.trivious.intents).has(GatewayIntentBits.GuildMessages),\n\t\t\t\t\"TriviousClient has GuildMessages gateway intent.\",\n\t\t\t],\n\t\t];\n\t},\n} satisfies Event<\"messageCreate\">;\n"],"mappings":"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","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as bindEvents, z 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';
|
|
@@ -1,5 +1,5 @@
|
|
|
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 { existsSync, promises as fs } from "fs";
|
|
4
4
|
import path, { join } from "path";
|
|
5
5
|
async function loadPresetEvents(client) {
|
|
@@ -9,12 +9,25 @@ async function loadPresetEvents(client) {
|
|
|
9
9
|
for await (const file of files) {
|
|
10
10
|
const event = await parseEvent(file);
|
|
11
11
|
if (!event) continue;
|
|
12
|
+
if (event.conditions && !event.conditions(client).every(([isValid, description], index) => {
|
|
13
|
+
if (!isValid)
|
|
14
|
+
client.logger.debug(
|
|
15
|
+
"[EVENT REGISTRY]",
|
|
16
|
+
`Condition #${index + 1} "${description}" for event`,
|
|
17
|
+
event.name,
|
|
18
|
+
"not met; this event will not be triggered."
|
|
19
|
+
);
|
|
20
|
+
return isValid;
|
|
21
|
+
})) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
12
24
|
client.stores.events.set(event.name, event);
|
|
25
|
+
client.logger.debug("Registered preset-event:", event.name);
|
|
13
26
|
}
|
|
14
27
|
}
|
|
15
28
|
async function parseEvent(file) {
|
|
16
29
|
const event = await importFile(file);
|
|
17
|
-
if (!event || !("name" in event && "execute" in event)) return null;
|
|
30
|
+
if (!event || !("name" in event && "execute" in event) || "context" in event) return null;
|
|
18
31
|
return event;
|
|
19
32
|
}
|
|
20
33
|
async function bindEvents(client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/events/registry.events.ts"],"sourcesContent":["import { Event, TriviousClient } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/events/registry.events.ts"],"sourcesContent":["import { Event, TriviousClient } from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport { importFile } from \"#utility/functions.js\";\nimport { ClientEvents } from \"discord.js\";\nimport { existsSync, promises as fs } from \"fs\";\nimport path, { join } from \"path\";\n\nasync function loadPresetEvents(client: TriviousClient) {\n\tconst directory = path.resolve(import.meta.dirname, \"presets\");\n\tif (!existsSync(directory)) return;\n\n\tconst files = fs.glob(join(directory, \"*.{js,ts}\"));\n\tfor await (const file of files) {\n\t\tconst event = await parseEvent(file);\n\t\tif (!event) continue;\n\t\tif (\n\t\t\tevent.conditions &&\n\t\t\t!event.conditions(client).every(([isValid, description], index) => {\n\t\t\t\tif (!isValid)\n\t\t\t\t\tclient.logger.debug(\n\t\t\t\t\t\t\"[EVENT REGISTRY]\",\n\t\t\t\t\t\t`Condition #${index + 1} \"${description}\" for event`,\n\t\t\t\t\t\tevent.name,\n\t\t\t\t\t\t\"not met; this event will not be triggered.\"\n\t\t\t\t\t);\n\t\t\t\treturn isValid;\n\t\t\t})\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tclient.stores.events.set(event.name, event);\n\t\tclient.logger.debug(\"Registered preset-event:\", event.name);\n\t}\n}\n\nasync function parseEvent(file: string) {\n\tconst event = await importFile<Event>(file);\n\tif (!event || !(\"name\" in event && \"execute\" in event) || \"context\" in event) return null;\n\treturn event;\n}\n\nexport async function bindEvents(client: TriviousClient) {\n\tfor (const event of client.stores.events.values()) {\n\t\tconst handler = (...args: ClientEvents[typeof event.name]) =>\n\t\t\tvoid event.execute(client, ...args);\n\n\t\tif (event.once) client.once(event.name, handler);\n\t\telse client.on(event.name, handler);\n\t}\n}\n\nexport default async function registerEvents(client: TriviousClient, directory: string) {\n\tclient.logger.debug(\"Starting event registration in:\", directory);\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register events; passed directory '${directory}' does not exist!`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\n\tawait loadPresetEvents(client);\n\tconst files = fs.glob(join(directory, \"**/*.{js,ts}\"));\n\tfor await (const file of files) {\n\t\tconst event = await parseEvent(file);\n\t\tif (!event) continue;\n\n\t\tif (client.stores.events.get(event.name))\n\t\t\tconsole.warn(`[Trivious] Event '${event.name}' has a duplicate and has been overridden`);\n\n\t\tclient.logger.debug(\"Registered event:\", event.name);\n\t\tclient.stores.events.set(event.name, event);\n\t}\n}\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAE3B,SAAS,YAAY,YAAY,UAAU;AAC3C,OAAO,QAAQ,YAAY;AAE3B,eAAe,iBAAiB,QAAwB;AACvD,QAAM,YAAY,KAAK,QAAQ,YAAY,SAAS,SAAS;AAC7D,MAAI,CAAC,WAAW,SAAS,EAAG;AAE5B,QAAM,QAAQ,GAAG,KAAK,KAAK,WAAW,WAAW,CAAC;AAClD,mBAAiB,QAAQ,OAAO;AAC/B,UAAM,QAAQ,MAAM,WAAW,IAAI;AACnC,QAAI,CAAC,MAAO;AACZ,QACC,MAAM,cACN,CAAC,MAAM,WAAW,MAAM,EAAE,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,UAAU;AAClE,UAAI,CAAC;AACJ,eAAO,OAAO;AAAA,UACb;AAAA,UACA,cAAc,QAAQ,CAAC,KAAK,WAAW;AAAA,UACvC,MAAM;AAAA,UACN;AAAA,QACD;AACD,aAAO;AAAA,IACR,CAAC,GACA;AACD;AAAA,IACD;AACA,WAAO,OAAO,OAAO,IAAI,MAAM,MAAM,KAAK;AAC1C,WAAO,OAAO,MAAM,4BAA4B,MAAM,IAAI;AAAA,EAC3D;AACD;AAEA,eAAe,WAAW,MAAc;AACvC,QAAM,QAAQ,MAAM,WAAkB,IAAI;AAC1C,MAAI,CAAC,SAAS,EAAE,UAAU,SAAS,aAAa,UAAU,aAAa,MAAO,QAAO;AACrF,SAAO;AACR;AAEA,eAAsB,WAAW,QAAwB;AACxD,aAAW,SAAS,OAAO,OAAO,OAAO,OAAO,GAAG;AAClD,UAAM,UAAU,IAAI,SACnB,KAAK,MAAM,QAAQ,QAAQ,GAAG,IAAI;AAEnC,QAAI,MAAM,KAAM,QAAO,KAAK,MAAM,MAAM,OAAO;AAAA,QAC1C,QAAO,GAAG,MAAM,MAAM,OAAO;AAAA,EACnC;AACD;AAEA,eAAO,eAAsC,QAAwB,WAAmB;AACvF,SAAO,OAAO,MAAM,mCAAmC,SAAS;AAChE,MAAI,CAAC,WAAW,SAAS;AACxB,UAAM,IAAI;AAAA,MACT,gDAAgD,SAAS;AAAA,MACzD;AAAA,IACD;AAED,QAAM,iBAAiB,MAAM;AAC7B,QAAM,QAAQ,GAAG,KAAK,KAAK,WAAW,cAAc,CAAC;AACrD,mBAAiB,QAAQ,OAAO;AAC/B,UAAM,QAAQ,MAAM,WAAW,IAAI;AACnC,QAAI,CAAC,MAAO;AAEZ,QAAI,OAAO,OAAO,OAAO,IAAI,MAAM,IAAI;AACtC,cAAQ,KAAK,qBAAqB,MAAM,IAAI,2CAA2C;AAExF,WAAO,OAAO,MAAM,qBAAqB,MAAM,IAAI;AACnD,WAAO,OAAO,OAAO,IAAI,MAAM,MAAM,KAAK;AAAA,EAC3C;AACD;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { F as bindModules, D 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';
|
|
@@ -1,5 +1,5 @@
|
|
|
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 { existsSync, promises as fs } from "fs";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
async function bindModules(client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/modules/registry.modules.ts"],"sourcesContent":["import { Module, TriviousClient } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/modules/registry.modules.ts"],"sourcesContent":["import { Module, 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 async function bindModules(client: TriviousClient) {\n\tfor (const moduleData of client.stores.modules.values()) {\n\t\tfor (const [name, handler] of Object.entries(moduleData.events)) {\n\t\t\tconst listener = (...args: unknown[]) =>\n\t\t\t\tvoid (handler as (client: TriviousClient, ...args: unknown[]) => any)(client, ...args);\n\n\t\t\tclient.on(name, listener);\n\t\t}\n\t}\n}\n\nexport default async function registerModules(client: TriviousClient, directory: string) {\n\tclient.logger.debug(\"Starting module registration in:\", directory);\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register modules; 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 moduleData = await importFile<Module>(file);\n\t\tif (!moduleData || !(\"name\" in moduleData && \"events\" in moduleData)) continue;\n\n\t\tif (client.stores.events.get(moduleData.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Module '${moduleData.name}' has a duplicate and has been overridden`\n\t\t\t);\n\n\t\tclient.stores.modules.set(moduleData.name, moduleData);\n\t}\n}\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,YAAY,YAAY,UAAU;AAC3C,SAAS,YAAY;AAErB,eAAsB,YAAY,QAAwB;AACzD,aAAW,cAAc,OAAO,OAAO,QAAQ,OAAO,GAAG;AACxD,eAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,WAAW,MAAM,GAAG;AAChE,YAAM,WAAW,IAAI,SACpB,KAAM,QAAgE,QAAQ,GAAG,IAAI;AAEtF,aAAO,GAAG,MAAM,QAAQ;AAAA,IACzB;AAAA,EACD;AACD;AAEA,eAAO,gBAAuC,QAAwB,WAAmB;AACxF,SAAO,OAAO,MAAM,oCAAoC,SAAS;AACjE,MAAI,CAAC,WAAW,SAAS;AACxB,UAAM,IAAI;AAAA,MACT,iDAAiD,SAAS;AAAA,MAC1D;AAAA,IACD;AAED,QAAM,QAAQ,GAAG,KAAK,KAAK,WAAW,cAAc,CAAC;AACrD,mBAAiB,QAAQ,OAAO;AAC/B,UAAM,aAAa,MAAM,WAAmB,IAAI;AAChD,QAAI,CAAC,cAAc,EAAE,UAAU,cAAc,YAAY,YAAa;AAEtE,QAAI,OAAO,OAAO,OAAO,IAAI,WAAW,IAAI;AAC3C,cAAQ;AAAA,QACP,sBAAsB,WAAW,IAAI;AAAA,MACtC;AAED,WAAO,OAAO,QAAQ,IAAI,WAAW,MAAM,UAAU;AAAA,EACtD;AACD;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { GuildMember, User } from 'discord.js';
|
|
2
|
-
import { T as TriviousClient, a as BaseCommandData, f as Component } from '../../modules.types-
|
|
2
|
+
import { T as TriviousClient, a as BaseCommandData, f as Component, p as MessageCommandData } from '../../modules.types-BgGFvIsW.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
4
|
import './permissions.types.js';
|
|
5
5
|
import '../client/logger.js';
|
|
6
6
|
|
|
7
|
-
declare function canMemberRunCommand(client: TriviousClient, command: BaseCommandData | Component, member: GuildMember): [boolean, string];
|
|
8
|
-
declare function canUserRunCommand(client: TriviousClient, command: BaseCommandData | Component, user: User): [boolean, string];
|
|
7
|
+
declare function canMemberRunCommand(client: TriviousClient, command: BaseCommandData | Component | MessageCommandData, member: GuildMember | User): [boolean, string];
|
|
8
|
+
declare function canUserRunCommand(client: TriviousClient, command: BaseCommandData | Component | MessageCommandData, user: User): [boolean, string];
|
|
9
9
|
|
|
10
10
|
export { canMemberRunCommand, canUserRunCommand };
|
|
@@ -2,6 +2,7 @@ import { PermissionFlagsBits } from "discord.js";
|
|
|
2
2
|
function canMemberRunCommand(client, command, member) {
|
|
3
3
|
const { permissions } = command;
|
|
4
4
|
if (!permissions) return [true, "No permissions set"];
|
|
5
|
+
if (!("nickname" in member)) return canUserRunCommand(client, command, member);
|
|
5
6
|
if (client.trivious.ownerUserIds && client.trivious.ownerUserIds.includes(member.user.id) || member.permissions.has(PermissionFlagsBits.Administrator))
|
|
6
7
|
return [true, "User can run command; Administrator privileges"];
|
|
7
8
|
const { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/permissions/methods.permissions.ts"],"sourcesContent":["import { BaseCommandData, Component, TriviousClient } from \"
|
|
1
|
+
{"version":3,"sources":["../../../src/features/permissions/methods.permissions.ts"],"sourcesContent":["import { BaseCommandData, Component, MessageCommandData, TriviousClient } from \"#typings\";\nimport { GuildMember, PermissionFlagsBits, User } from \"discord.js\";\n\nexport function canMemberRunCommand(\n\tclient: TriviousClient,\n\tcommand: BaseCommandData | Component | MessageCommandData,\n\tmember: GuildMember | User\n): [boolean, string] {\n\tconst { permissions } = command;\n\tif (!permissions) return [true, \"No permissions set\"];\n\tif (!(\"nickname\" in member)) return canUserRunCommand(client, command, member);\n\n\t// If the member is a bot owner or has Administrator permissions\n\tif (\n\t\t(client.trivious.ownerUserIds && client.trivious.ownerUserIds.includes(member.user.id)) ||\n\t\tmember.permissions.has(PermissionFlagsBits.Administrator)\n\t)\n\t\treturn [true, \"User can run command; Administrator privileges\"];\n\n\tconst { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;\n\tif (userIds) return canUserRunCommand(client, command, member.user);\n\tconst permissionFlags = requiredMemberPermissions || permissions.permissionFlags;\n\tconst roleIds = requiredRoleIds || permissions.roleIds;\n\n\tif (permissionFlags) {\n\t\tfor (const bit of permissionFlags) {\n\t\t\tif (member.permissions.has(bit)) {\n\t\t\t\treturn [true, \"User can run command; Has required permission(s)\"];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (roleIds) {\n\t\tfor (const roleId of roleIds) {\n\t\t\tif (member.roles.cache.has(roleId)) {\n\t\t\t\treturn [true, \"User can run command; Has required role(s)\"];\n\t\t\t}\n\t\t}\n\t}\n\n\treturn [false, \"User cannot run command; Meets zero requirements\"];\n}\n\nexport function canUserRunCommand(\n\tclient: TriviousClient,\n\tcommand: BaseCommandData | Component | MessageCommandData,\n\tuser: User\n): [boolean, string] {\n\tconst { permissions } = command;\n\tif (!permissions) return [true, \"No permissions set\"];\n\n\tif (client.trivious.ownerUserIds && client.trivious.ownerUserIds.includes(user.id))\n\t\treturn [true, \"User can run command\"];\n\n\tconst { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;\n\tconst permissionFlags = requiredMemberPermissions || permissions.permissionFlags;\n\tconst roleIds = requiredRoleIds || permissions.roleIds;\n\n\tif (!userIds && (permissionFlags || roleIds))\n\t\treturn [false, \"Cannot validate permissions; use canMemberRunCommand instead\"];\n\n\tif (!userIds) return [true, \"No permissions set\"];\n\treturn userIds.includes(user.id)\n\t\t? [true, \"User can run command\"]\n\t\t: [false, \"User cannot run command\"];\n}\n"],"mappings":"AACA,SAAsB,2BAAiC;AAEhD,SAAS,oBACf,QACA,SACA,QACoB;AACpB,QAAM,EAAE,YAAY,IAAI;AACxB,MAAI,CAAC,YAAa,QAAO,CAAC,MAAM,oBAAoB;AACpD,MAAI,EAAE,cAAc,QAAS,QAAO,kBAAkB,QAAQ,SAAS,MAAM;AAG7E,MACE,OAAO,SAAS,gBAAgB,OAAO,SAAS,aAAa,SAAS,OAAO,KAAK,EAAE,KACrF,OAAO,YAAY,IAAI,oBAAoB,aAAa;AAExD,WAAO,CAAC,MAAM,gDAAgD;AAE/D,QAAM,EAAE,2BAA2B,iBAAiB,QAAQ,IAAI;AAChE,MAAI,QAAS,QAAO,kBAAkB,QAAQ,SAAS,OAAO,IAAI;AAClE,QAAM,kBAAkB,6BAA6B,YAAY;AACjE,QAAM,UAAU,mBAAmB,YAAY;AAE/C,MAAI,iBAAiB;AACpB,eAAW,OAAO,iBAAiB;AAClC,UAAI,OAAO,YAAY,IAAI,GAAG,GAAG;AAChC,eAAO,CAAC,MAAM,kDAAkD;AAAA,MACjE;AAAA,IACD;AAAA,EACD;AAEA,MAAI,SAAS;AACZ,eAAW,UAAU,SAAS;AAC7B,UAAI,OAAO,MAAM,MAAM,IAAI,MAAM,GAAG;AACnC,eAAO,CAAC,MAAM,4CAA4C;AAAA,MAC3D;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAC,OAAO,kDAAkD;AAClE;AAEO,SAAS,kBACf,QACA,SACA,MACoB;AACpB,QAAM,EAAE,YAAY,IAAI;AACxB,MAAI,CAAC,YAAa,QAAO,CAAC,MAAM,oBAAoB;AAEpD,MAAI,OAAO,SAAS,gBAAgB,OAAO,SAAS,aAAa,SAAS,KAAK,EAAE;AAChF,WAAO,CAAC,MAAM,sBAAsB;AAErC,QAAM,EAAE,2BAA2B,iBAAiB,QAAQ,IAAI;AAChE,QAAM,kBAAkB,6BAA6B,YAAY;AACjE,QAAM,UAAU,mBAAmB,YAAY;AAE/C,MAAI,CAAC,YAAY,mBAAmB;AACnC,WAAO,CAAC,OAAO,8DAA8D;AAE9E,MAAI,CAAC,QAAS,QAAO,CAAC,MAAM,oBAAoB;AAChD,SAAO,QAAQ,SAAS,KAAK,EAAE,IAC5B,CAAC,MAAM,sBAAsB,IAC7B,CAAC,OAAO,yBAAyB;AACrC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
export { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from './features/client/client.types.js';
|
|
2
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CollatedCommandData, c as CommandFlags, d as CommandFunction, e as CommandSetData, f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction, j as ContextCommandData, E as Event, M as Module, S as SlashCommandData,
|
|
1
|
+
export { CommandHashConfiguration, FeatureBasedStructure, MessageCommandConfiguration, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from './features/client/client.types.js';
|
|
2
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CollatedCommandData, c as CommandFlags, d as CommandFunction, e as CommandSetData, f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction, j as ContextCommandData, E as Event, M as MessageCommandArgs, k as MessageCommandArgument, l as MessageCommandArgumentType, m as MessageCommandArgumentTypeMap, n as MessageCommandArgumentsMap, o as MessageCommandBaseData, p as MessageCommandData, q as MessageCommandFlags, r as MessageCommandInteraction, s as MessageCommandMetadata, t as Module, R as RO_ArrayType, u as ResolveArgType, S as SlashCommandData, v as SlashSubcommandData, w as SlashSubcommandGroupData, T as TriviousClient } from './modules.types-BgGFvIsW.js';
|
|
3
3
|
export { ComponentCustomId, ComponentTag } from './features/customId/customid.types.js';
|
|
4
4
|
export { CommandPermissionValues } from './features/permissions/permissions.types.js';
|
|
5
5
|
export { createActionRow, createEmbed } from './features/builders/utility.builders.js';
|
|
6
|
-
export {
|
|
6
|
+
export { parseMessageCommandArgument, processPartialMessageCommand } from './features/commands/handlers/message.commands.js';
|
|
7
|
+
export { handleSlashCommand } from './features/commands/handlers/slash.commands.js';
|
|
8
|
+
export { interactionReply } from './features/commands/methods.commands.js';
|
|
7
9
|
export { default as customId } from './features/customId/methods.customid.js';
|
|
8
|
-
export { createMessageContextCommand, createSlashCommand, createSlashSubcommand, createSlashSubcommandGroup, createSubcommand, createSubcommandGroup, createUserContextCommand } from './features/commands/builders.commands.js';
|
|
10
|
+
export { createMessageCommand, createMessageContextCommand, createSlashCommand, createSlashSubcommand, createSlashSubcommandGroup, createSubcommand, createSubcommandGroup, createUserContextCommand } from './features/commands/builders.commands.js';
|
|
9
11
|
export { createButtonComponent, createComponent, createModalComponent, createSelectMenuComponent } from './features/components/builders.components.js';
|
|
10
12
|
import 'discord.js';
|
|
11
13
|
import './features/client/logger.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "
|
|
3
|
-
export * from "
|
|
4
|
-
|
|
5
|
-
export * from "
|
|
6
|
-
|
|
1
|
+
export * from "#typings";
|
|
2
|
+
export * from "#feature/builders/utility.builders.js";
|
|
3
|
+
export * from "#feature/commands/handlers/message.commands.js";
|
|
4
|
+
export * from "#feature/commands/handlers/slash.commands.js";
|
|
5
|
+
export * from "#feature/commands/methods.commands.js";
|
|
6
|
+
import { default as default2 } from "#feature/customId/methods.customid.js";
|
|
7
|
+
export * from "#feature/commands/builders.commands.js";
|
|
8
|
+
export * from "#feature/components/builders.components.js";
|
|
7
9
|
export {
|
|
8
10
|
default2 as customId
|
|
9
11
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from \"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from \"#typings\";\n\n// Methods\nexport * from \"#feature/builders/utility.builders.js\";\nexport * from \"#feature/commands/handlers/message.commands.js\";\nexport * from \"#feature/commands/handlers/slash.commands.js\";\nexport * from \"#feature/commands/methods.commands.js\";\nexport { default as customId } from \"#feature/customId/methods.customid.js\";\n\n// Builders\nexport * from \"#feature/commands/builders.commands.js\";\nexport * from \"#feature/components/builders.components.js\";\n"],"mappings":"AACA,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA2B;AAGpC,cAAc;AACd,cAAc;","names":["default"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, Collection, ApplicationCommandType, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, Interaction, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ButtonInteraction, AnySelectMenuInteraction, ModalSubmitInteraction, ClientEvents } from 'discord.js';
|
|
1
|
+
import { Client, Collection, ApplicationCommandType, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, Interaction, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, User, Channel, Role, Message, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ButtonInteraction, AnySelectMenuInteraction, ModalSubmitInteraction, ClientEvents } from 'discord.js';
|
|
2
2
|
import { TriviousClientOptions } from './features/client/client.types.js';
|
|
3
3
|
import { CommandPermissionValues } from './features/permissions/permissions.types.js';
|
|
4
4
|
import { Logger } from './features/client/logger.js';
|
|
@@ -35,10 +35,12 @@ declare class TriviousClient extends Client {
|
|
|
35
35
|
commands: {
|
|
36
36
|
chatInput: Collection<string, SlashCommandData>;
|
|
37
37
|
context: Collection<string, ContextCommandData>;
|
|
38
|
+
message: Collection<string, MessageCommandData<true>>;
|
|
38
39
|
};
|
|
39
40
|
components: Collection<string, Component>;
|
|
40
41
|
events: Collection<string, Event>;
|
|
41
42
|
modules: Collection<string, Module>;
|
|
43
|
+
messageCommandAliases: Collection<string, string>;
|
|
42
44
|
};
|
|
43
45
|
logger: Logger;
|
|
44
46
|
constructor(options: TriviousClientOptions);
|
|
@@ -47,25 +49,23 @@ declare class TriviousClient extends Client {
|
|
|
47
49
|
*
|
|
48
50
|
* @throws {TriviousError} If invalid bot token
|
|
49
51
|
*/
|
|
50
|
-
start(): Promise<void>;
|
|
52
|
+
start(deploy?: boolean): Promise<void>;
|
|
51
53
|
register(): Promise<void>;
|
|
52
54
|
deploy(): Promise<void>;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
type ChatInputCommandContext = "SlashCommand" | "SlashSubcommand" | "SlashSubcommandGroup";
|
|
56
58
|
type CommandFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
|
|
59
|
+
type MessageCommandFlags = "InGuild" | "OutGuild";
|
|
57
60
|
type CommandFunction<T extends Interaction> = (client: TriviousClient, interaction: T) => Promise<void>;
|
|
58
61
|
/**
|
|
59
62
|
* Base Trivious command data
|
|
60
63
|
*
|
|
61
|
-
* @param context The command context
|
|
62
|
-
* @param commandType ApplicationCommandType
|
|
63
64
|
* @param active Whether or not to register and recognise the command
|
|
64
|
-
* @param
|
|
65
|
+
* @param permissions What users and roles can use the command
|
|
65
66
|
*/
|
|
66
67
|
interface BaseCommandData {
|
|
67
68
|
active: boolean;
|
|
68
|
-
flags?: CommandFlags[];
|
|
69
69
|
permissions?: CommandPermissionValues;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -75,6 +75,7 @@ interface BaseCommandData {
|
|
|
75
75
|
* @param commandType ApplicationCommandType.ChatInput
|
|
76
76
|
*/
|
|
77
77
|
interface BaseChatInputCommandData extends BaseCommandData {
|
|
78
|
+
flags?: CommandFlags[];
|
|
78
79
|
context: ChatInputCommandContext;
|
|
79
80
|
commandType: ApplicationCommandType.ChatInput;
|
|
80
81
|
}
|
|
@@ -84,6 +85,7 @@ interface BaseChatInputCommandData extends BaseCommandData {
|
|
|
84
85
|
* @param commandType ApplicationCommandType.Message | ApplicationCommandType.User
|
|
85
86
|
*/
|
|
86
87
|
interface ContextCommandData<T extends "Message" | "User" | null = null> extends BaseCommandData {
|
|
88
|
+
flags?: CommandFlags[];
|
|
87
89
|
commandType: T extends null ? ApplicationCommandType.Message | ApplicationCommandType.User : T extends "Message" ? ApplicationCommandType.Message : ApplicationCommandType.User;
|
|
88
90
|
data: ContextMenuCommandBuilder;
|
|
89
91
|
execute: CommandFunction<T extends null ? MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction : T extends "Message" ? MessageContextMenuCommandInteraction : UserContextMenuCommandInteraction>;
|
|
@@ -137,7 +139,58 @@ type CollatedCommandData = {
|
|
|
137
139
|
SlashSubcommand: Set<CommandSetData<SlashSubcommandData>>;
|
|
138
140
|
SlashSubcommandGroup: Set<CommandSetData<SlashSubcommandGroupData>>;
|
|
139
141
|
ContextCommand: Set<CommandSetData<ContextCommandData>>;
|
|
142
|
+
MessageCommand: Set<CommandSetData<MessageCommandData>>;
|
|
140
143
|
};
|
|
144
|
+
interface MessageCommandBaseData {
|
|
145
|
+
active: boolean;
|
|
146
|
+
permissions?: CommandPermissionValues;
|
|
147
|
+
}
|
|
148
|
+
type RO_ArrayType<T> = readonly T[] | undefined;
|
|
149
|
+
type MessageCommandArgs<Arguments extends RO_ArrayType<MessageCommandArgument>> = Arguments extends readonly MessageCommandArgument[] ? [Arguments[number]] extends [never] ? null : MessageCommandArgumentsMap<Arguments> : null;
|
|
150
|
+
type ResolveArgType<Argument extends MessageCommandArgument> = Argument["dataType"] extends keyof MessageCommandArgumentTypeMap ? MessageCommandArgumentTypeMap[Argument["dataType"]] : unknown;
|
|
151
|
+
type MessageCommandArgumentType = keyof MessageCommandArgumentTypeMap;
|
|
152
|
+
interface MessageCommandArgumentTypeMap {
|
|
153
|
+
"text": string;
|
|
154
|
+
"number": number;
|
|
155
|
+
"date": Date;
|
|
156
|
+
"timestamp": Date;
|
|
157
|
+
"snowflake": string;
|
|
158
|
+
"snowflake/user": User;
|
|
159
|
+
"snowflake/channel": Channel;
|
|
160
|
+
"snowflake/role": Role;
|
|
161
|
+
"duration": number;
|
|
162
|
+
}
|
|
163
|
+
interface MessageCommandArgumentsMap<Args extends readonly MessageCommandArgument[]> extends Omit<Collection<string, any>, "get"> {
|
|
164
|
+
get<K extends Args[number]["name"]>(key: K): Extract<Args[number], {
|
|
165
|
+
name: K;
|
|
166
|
+
}> extends infer Arg ? Arg extends MessageCommandArgument ? Arg["required"] extends true ? ResolveArgType<Arg> : ResolveArgType<Arg> | undefined : undefined : undefined;
|
|
167
|
+
}
|
|
168
|
+
interface MessageCommandArgument {
|
|
169
|
+
name: string;
|
|
170
|
+
description: string;
|
|
171
|
+
dataType: MessageCommandArgumentType;
|
|
172
|
+
required?: boolean;
|
|
173
|
+
value?: string;
|
|
174
|
+
}
|
|
175
|
+
interface MessageCommandInteraction<Arguments extends RO_ArrayType<MessageCommandArgument> = readonly MessageCommandArgument[] | undefined, InGuild extends boolean = boolean> {
|
|
176
|
+
args: MessageCommandArgs<Arguments>;
|
|
177
|
+
command: MessageCommandData<true>;
|
|
178
|
+
message: Message<InGuild>;
|
|
179
|
+
}
|
|
180
|
+
interface MessageCommandMetadata {
|
|
181
|
+
regex: RegExp;
|
|
182
|
+
usage: string;
|
|
183
|
+
}
|
|
184
|
+
interface MessageCommandData<Processed extends boolean = boolean, Arguments extends RO_ArrayType<MessageCommandArgument> = readonly MessageCommandArgument[] | undefined, InGuild extends boolean = boolean> extends BaseCommandData {
|
|
185
|
+
context: "MessageCommand";
|
|
186
|
+
name: string;
|
|
187
|
+
description: string;
|
|
188
|
+
arguments?: Arguments;
|
|
189
|
+
aliases?: string[];
|
|
190
|
+
flags?: MessageCommandFlags[];
|
|
191
|
+
metadata: Processed extends true ? MessageCommandMetadata : undefined;
|
|
192
|
+
execute: (client: TriviousClient, interaction: MessageCommandInteraction<Arguments, InGuild>) => Promise<void>;
|
|
193
|
+
}
|
|
141
194
|
|
|
142
195
|
type ComponentFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
|
|
143
196
|
type ComponentInteraction = AnySelectMenuInteraction | ButtonInteraction | ModalSubmitInteraction;
|
|
@@ -169,6 +222,7 @@ interface Component<Context extends ComponentContext = ComponentContext> {
|
|
|
169
222
|
interface Event<K extends keyof ClientEvents = keyof ClientEvents> {
|
|
170
223
|
name: K;
|
|
171
224
|
once?: boolean;
|
|
225
|
+
conditions?: (client: TriviousClient) => [boolean, string][];
|
|
172
226
|
execute: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void> | void;
|
|
173
227
|
}
|
|
174
228
|
|
|
@@ -179,4 +233,4 @@ interface Module {
|
|
|
179
233
|
};
|
|
180
234
|
}
|
|
181
235
|
|
|
182
|
-
export { type BaseChatInputCommandData as B, type ChatInputCommandContext as C, type Event as E, type
|
|
236
|
+
export { bindEvents as A, type BaseChatInputCommandData as B, type ChatInputCommandContext as C, registerModules as D, type Event as E, bindModules as F, type MessageCommandArgs as M, type RO_ArrayType as R, type SlashCommandData as S, TriviousClient as T, type BaseCommandData as a, type CollatedCommandData as b, type CommandFlags as c, type CommandFunction as d, type CommandSetData as e, type Component as f, ComponentContext as g, type ComponentFlags as h, type ComponentInteraction as i, type ContextCommandData as j, type MessageCommandArgument as k, type MessageCommandArgumentType as l, type MessageCommandArgumentTypeMap as m, type MessageCommandArgumentsMap as n, type MessageCommandBaseData as o, type MessageCommandData as p, type MessageCommandFlags as q, type MessageCommandInteraction as r, type MessageCommandMetadata as s, type Module as t, type ResolveArgType as u, type SlashSubcommandData as v, type SlashSubcommandGroupData as w, registerCommands as x, registerComponents as y, registerEvents as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as registerCommands, y as registerComponents, z as registerEvents, A as bindEvents, D as registerModules, F as bindModules } from '../modules.types-BgGFvIsW.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../features/client/client.types.js';
|
|
4
4
|
import '../features/permissions/permissions.types.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import registerCommands from "
|
|
2
|
-
import registerComponents from "
|
|
3
|
-
import registerEvents, { bindEvents } from "
|
|
4
|
-
import registerModules, { bindModules } from "
|
|
1
|
+
import registerCommands from "#feature/commands/registry.commands.js";
|
|
2
|
+
import registerComponents from "#feature/components/registry.components.js";
|
|
3
|
+
import registerEvents, { bindEvents } from "#feature/events/registry.events.js";
|
|
4
|
+
import registerModules, { bindModules } from "#feature/modules/registry.modules.js";
|
|
5
5
|
var registries_default = {
|
|
6
6
|
commands: {
|
|
7
7
|
register: registerCommands
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/registries.ts"],"sourcesContent":["import registerCommands from \"
|
|
1
|
+
{"version":3,"sources":["../../src/shared/registries.ts"],"sourcesContent":["import registerCommands from \"#feature/commands/registry.commands.js\";\nimport registerComponents from \"#feature/components/registry.components.js\";\nimport registerEvents, { bindEvents } from \"#feature/events/registry.events.js\";\nimport registerModules, { bindModules } from \"#feature/modules/registry.modules.js\";\n\nexport default {\n\tcommands: {\n\t\tregister: registerCommands,\n\t},\n\tcomponents: {\n\t\tregister: registerComponents,\n\t},\n\tevents: {\n\t\tregister: registerEvents,\n\t\tbind: bindEvents,\n\t},\n\tmodules: {\n\t\tregister: registerModules,\n\t\tbind: bindModules,\n\t},\n} as const;\n"],"mappings":"AAAA,OAAO,sBAAsB;AAC7B,OAAO,wBAAwB;AAC/B,OAAO,kBAAkB,kBAAkB;AAC3C,OAAO,mBAAmB,mBAAmB;AAE7C,IAAO,qBAAQ;AAAA,EACd,UAAU;AAAA,IACT,UAAU;AAAA,EACX;AAAA,EACA,YAAY;AAAA,IACX,UAAU;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,IACP,UAAU;AAAA,IACV,MAAM;AAAA,EACP;AAAA,EACA,SAAS;AAAA,IACR,UAAU;AAAA,IACV,MAAM;AAAA,EACP;AACD;","names":[]}
|
package/dist/shared/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from '../features/client/client.types.js';
|
|
2
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CollatedCommandData, c as CommandFlags, d as CommandFunction, e as CommandSetData, f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction, j as ContextCommandData, E as Event, M as Module, S as SlashCommandData,
|
|
1
|
+
export { CommandHashConfiguration, FeatureBasedStructure, MessageCommandConfiguration, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from '../features/client/client.types.js';
|
|
2
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CollatedCommandData, c as CommandFlags, d as CommandFunction, e as CommandSetData, f as Component, g as ComponentContext, h as ComponentFlags, i as ComponentInteraction, j as ContextCommandData, E as Event, M as MessageCommandArgs, k as MessageCommandArgument, l as MessageCommandArgumentType, m as MessageCommandArgumentTypeMap, n as MessageCommandArgumentsMap, o as MessageCommandBaseData, p as MessageCommandData, q as MessageCommandFlags, r as MessageCommandInteraction, s as MessageCommandMetadata, t as Module, R as RO_ArrayType, u as ResolveArgType, S as SlashCommandData, v as SlashSubcommandData, w as SlashSubcommandGroupData, T as TriviousClient } from '../modules.types-BgGFvIsW.js';
|
|
3
3
|
export { ComponentCustomId, ComponentTag } from '../features/customId/customid.types.js';
|
|
4
4
|
export { CommandPermissionValues } from '../features/permissions/permissions.types.js';
|
|
5
5
|
import 'discord.js';
|
package/dist/shared/typings.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
import { default as default2 } from "
|
|
3
|
-
export * from "
|
|
4
|
-
export * from "
|
|
5
|
-
export * from "
|
|
6
|
-
export * from "
|
|
7
|
-
export * from "
|
|
8
|
-
export * from "
|
|
1
|
+
export * from "#feature/client/client.types.js";
|
|
2
|
+
import { default as default2 } from "#feature/client/trivious.client.js";
|
|
3
|
+
export * from "#feature/commands/commands.types.js";
|
|
4
|
+
export * from "#feature/components/components.types.js";
|
|
5
|
+
export * from "#feature/customId/customid.types.js";
|
|
6
|
+
export * from "#feature/events/events.types.js";
|
|
7
|
+
export * from "#feature/modules/modules.types.js";
|
|
8
|
+
export * from "#feature/permissions/permissions.types.js";
|
|
9
9
|
export {
|
|
10
10
|
default2 as TriviousClient
|
|
11
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/typings.ts"],"sourcesContent":["export * from \"
|
|
1
|
+
{"version":3,"sources":["../../src/shared/typings.ts"],"sourcesContent":["export * from \"#feature/client/client.types.js\";\nexport { default as TriviousClient } from \"#feature/client/trivious.client.js\";\nexport * from \"#feature/commands/commands.types.js\";\nexport * from \"#feature/components/components.types.js\";\nexport * from \"#feature/customId/customid.types.js\";\nexport * from \"#feature/events/events.types.js\";\nexport * from \"#feature/modules/modules.types.js\";\nexport * from \"#feature/permissions/permissions.types.js\";\n"],"mappings":"AAAA,cAAc;AACd,SAAoB,WAAXA,gBAAiC;AAC1C,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":["default"]}
|
package/dist/utility/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as BaseCommandData, S as SlashCommandData } from '../modules.types-
|
|
1
|
+
import { a as BaseCommandData, S as SlashCommandData } from '../modules.types-BgGFvIsW.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../features/client/client.types.js';
|
|
4
4
|
import '../features/permissions/permissions.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utility/errors.ts"],"sourcesContent":["import { BaseCommandData, SlashCommandData } from \"
|
|
1
|
+
{"version":3,"sources":["../../src/utility/errors.ts"],"sourcesContent":["import { BaseCommandData, SlashCommandData } from \"#feature/commands/commands.types.js\";\n\nexport class TriviousError extends Error {\n\treadonly field?: string;\n\treadonly cause?: string;\n\n\tconstructor(message: string, cause?: string) {\n\t\tmessage = `[Trivious] ${message}`;\n\t\tsuper(message);\n\n\t\tthis.message = message;\n\t\tthis.cause = cause;\n\t\tthis.name = \"TriviousError\";\n\t}\n}\n\nexport class CommandError extends Error {\n\treadonly commandName?: string;\n\n\tconstructor(message: string, command: Partial<BaseCommandData | SlashCommandData>) {\n\t\tmessage = `[Trivious] ${message}`;\n\t\tsuper(message);\n\n\t\tthis.name = \"CommandError\";\n\n\t\tif (\"data\" in command) this.commandName = command.data?.name;\n\t\t// if (this.commandContext && this.commandName)\n\t\t// \tthis.cause = `Error in ${this.commandContext} '${this.commandName}'`;\n\t}\n}\n"],"mappings":"AAEO,MAAM,sBAAsB,MAAM;AAAA,EAC/B;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,OAAgB;AAC5C,cAAU,cAAc,OAAO;AAC/B,UAAM,OAAO;AAEb,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,OAAO;AAAA,EACb;AACD;AAEO,MAAM,qBAAqB,MAAM;AAAA,EAC9B;AAAA,EAET,YAAY,SAAiB,SAAsD;AAClF,cAAU,cAAc,OAAO;AAC/B,UAAM,OAAO;AAEb,SAAK,OAAO;AAEZ,QAAI,UAAU,QAAS,MAAK,cAAc,QAAQ,MAAM;AAAA,EAGzD;AACD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utility/functions.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\nconst fileCache = new Map<string, Promise<any | null>>();\nexport function importFile<T>(filePath: string) {\n\tif (filePath.endsWith(\".d.ts\") || filePath.endsWith(\".js.map\")) return null;\n\tconst absolutePath = path.resolve(filePath);\n\tif (fileCache.has(absolutePath)) return fileCache.get(absolutePath)!;\n\n\tconst processPromise = (async () => {\n\t\ttry {\n\t\t\tconst { default: file } = await import(pathToFileURL(absolutePath).href);\n\t\t\tif (!file) return null;\n\n\t\t\tconst imports = file.default || file;\n\t\t\tif (typeof imports === \"function\" && imports.prototype) return new imports() as T;\n\t\t\tif (typeof imports === \"object\" && imports !== null) {\n\t\t\t\tif (Object.keys(imports).length === 0) return null;\n\t\t\t\treturn imports as T;\n\t\t\t}\n\n\t\t\treturn null;\n\t\t} catch (err: any) {\n\t\t\tconsole.warn(`[Trivious] Error while import file ${filePath}`, err);\n\t\t\treturn null;\n\t\t}\n\t})();\n\n\tfileCache.set(absolutePath, processPromise);\n\tprocessPromise.then((result) => {\n\t\tif (result === null) fileCache.delete(absolutePath);\n\t});\n\treturn processPromise;\n}\n\nexport function clearFileImportsCache() {\n\tfileCache.clear();\n}\n\nexport async function exists(path: string) {\n\ttry {\n\t\tawait fs.access(path);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,MAAM,YAAY,oBAAI,IAAiC;AAChD,SAAS,WAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/utility/functions.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\nconst fileCache = new Map<string, Promise<any | null>>();\nexport function importFile<T>(filePath: string): Promise<T | null> | null {\n\tif (filePath.endsWith(\".d.ts\") || filePath.endsWith(\".js.map\")) return null;\n\tconst absolutePath = path.resolve(filePath);\n\tif (fileCache.has(absolutePath)) return fileCache.get(absolutePath)!;\n\n\tconst processPromise = (async () => {\n\t\ttry {\n\t\t\tconst { default: file } = await import(pathToFileURL(absolutePath).href);\n\t\t\tif (!file) return null;\n\n\t\t\tconst imports = file.default || file;\n\t\t\tif (typeof imports === \"function\" && imports.prototype) return new imports() as T;\n\t\t\tif (typeof imports === \"object\" && imports !== null) {\n\t\t\t\tif (Object.keys(imports).length === 0) return null;\n\t\t\t\treturn imports as T;\n\t\t\t}\n\n\t\t\treturn null;\n\t\t} catch (err: any) {\n\t\t\tconsole.warn(`[Trivious] Error while import file ${filePath}`, err);\n\t\t\treturn null;\n\t\t}\n\t})();\n\n\tfileCache.set(absolutePath, processPromise);\n\tprocessPromise.then((result) => {\n\t\tif (result === null) fileCache.delete(absolutePath);\n\t});\n\treturn processPromise;\n}\n\nexport function clearFileImportsCache() {\n\tfileCache.clear();\n}\n\nexport async function exists(path: string) {\n\ttry {\n\t\tawait fs.access(path);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,MAAM,YAAY,oBAAI,IAAiC;AAChD,SAAS,WAAc,UAA4C;AACzE,MAAI,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,SAAS,EAAG,QAAO;AACvE,QAAM,eAAe,KAAK,QAAQ,QAAQ;AAC1C,MAAI,UAAU,IAAI,YAAY,EAAG,QAAO,UAAU,IAAI,YAAY;AAElE,QAAM,kBAAkB,YAAY;AACnC,QAAI;AACH,YAAM,EAAE,SAAS,KAAK,IAAI,MAAM,OAAO,cAAc,YAAY,EAAE;AACnE,UAAI,CAAC,KAAM,QAAO;AAElB,YAAM,UAAU,KAAK,WAAW;AAChC,UAAI,OAAO,YAAY,cAAc,QAAQ,UAAW,QAAO,IAAI,QAAQ;AAC3E,UAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAI,OAAO,KAAK,OAAO,EAAE,WAAW,EAAG,QAAO;AAC9C,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR,SAAS,KAAU;AAClB,cAAQ,KAAK,sCAAsC,QAAQ,IAAI,GAAG;AAClE,aAAO;AAAA,IACR;AAAA,EACD,GAAG;AAEH,YAAU,IAAI,cAAc,cAAc;AAC1C,iBAAe,KAAK,CAAC,WAAW;AAC/B,QAAI,WAAW,KAAM,WAAU,OAAO,YAAY;AAAA,EACnD,CAAC;AACD,SAAO;AACR;AAEO,SAAS,wBAAwB;AACvC,YAAU,MAAM;AACjB;AAEA,eAAsB,OAAOA,OAAc;AAC1C,MAAI;AACH,UAAM,GAAG,OAAOA,KAAI;AACpB,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;","names":["path"]}
|