trivious 2.0.6 → 2.1.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/README.md +6 -1
- package/dist/features/client/deploy.client.d.ts +2 -1
- package/dist/features/client/trivious.client.d.ts +2 -1
- package/dist/features/commands/commands.types.d.ts +2 -1
- package/dist/features/commands/methods.commands.d.ts +2 -1
- package/dist/features/commands/registry.commands.d.ts +2 -1
- package/dist/features/commands/registry.commands.js.map +1 -1
- package/dist/features/components/components.types.d.ts +2 -1
- package/dist/features/components/components.types.js.map +1 -1
- package/dist/features/components/registry.components.d.ts +2 -1
- package/dist/features/customId/customid.types.d.ts +2 -1
- package/dist/features/customId/methods.customid.d.ts +2 -1
- package/dist/features/events/events.types.d.ts +2 -1
- package/dist/features/events/presets/clientReady.d.ts +2 -1
- package/dist/features/events/presets/interactionCreate.d.ts +2 -1
- package/dist/features/events/presets/interactionCreate.js +23 -0
- package/dist/features/events/presets/interactionCreate.js.map +1 -1
- package/dist/features/events/registry.events.d.ts +2 -1
- package/dist/features/modules/modules.types.d.ts +2 -1
- package/dist/features/modules/registry.modules.d.ts +2 -1
- package/dist/features/permissions/methods.permissions.d.ts +9 -0
- package/dist/features/permissions/methods.permissions.js +41 -0
- package/dist/features/permissions/methods.permissions.js.map +1 -0
- package/dist/features/permissions/permissions.types.d.ts +9 -0
- package/dist/features/permissions/permissions.types.js +3 -0
- package/dist/features/permissions/permissions.types.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/{modules.types-Czzl6XR9.d.ts → modules.types-BUvtZD_e.d.ts} +8 -5
- package/dist/shared/registries.d.ts +2 -1
- package/dist/shared/typings.d.ts +2 -1
- package/dist/shared/typings.js +1 -0
- package/dist/utility/errors.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,11 @@ These default events can be found in `src/features/events/presets` in the Trivio
|
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
61
|
+
### Code examples
|
|
62
|
+
Examples for commands, components, events and modules can be found at https://github.com/commonly-ts/discord-bot-template/tree/main/templates.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
61
66
|
### Creating a Slash Command
|
|
62
67
|
|
|
63
68
|
```ts
|
|
@@ -125,7 +130,7 @@ export default {
|
|
|
125
130
|
|
|
126
131
|
### Project Structure
|
|
127
132
|
|
|
128
|
-
Any project structure (e.g. type-based, feature-based) is acceptable as long as everything you expect to be registered
|
|
133
|
+
Any project structure (e.g. type-based, feature-based) is acceptable as long as everything you expect to be registered are within the core directory.
|
|
129
134
|
|
|
130
135
|
For example, if all of your commands, components, events and modules are anywhere inside src/features, assuming they export the correct data, they will be detected and registered to the client.
|
|
131
136
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import './client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare function commandDeploy(client: TriviousClient): Promise<void>;
|
|
6
7
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, i as ContextCommandData, M as MessageCommandData, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, U as UserCommandData } from '../../modules.types-
|
|
2
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, i as ContextCommandData, M as MessageCommandData, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, U as UserCommandData } from '../../modules.types-BUvtZD_e.js';
|
|
3
|
+
import '../permissions/permissions.types.js';
|
|
3
4
|
import '../client/client.types.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
2
|
import { ChatInputCommandInteraction, Interaction, CacheType, InteractionReplyOptions, InteractionEditReplyOptions, MessagePayload } from 'discord.js';
|
|
3
|
-
import { T as TriviousClient, S as SlashCommandData, c as CommandFlags } from '../../modules.types-
|
|
3
|
+
import { T as TriviousClient, S as SlashCommandData, c as CommandFlags } from '../../modules.types-BUvtZD_e.js';
|
|
4
4
|
import '../client/client.types.js';
|
|
5
|
+
import '../permissions/permissions.types.js';
|
|
5
6
|
|
|
6
7
|
declare function interactionReply(options: {
|
|
7
8
|
interaction: Interaction<CacheType>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare function registerCommands(client: TriviousClient, directory: string): Promise<void>;
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"names":["fs"],"mappings":";;;;;;AAgBA,SAAS,eAAA,CACR,SACA,OAAA,EACU;AACV,EAAA,IAAI,EAAE,QAAA,IAAY,OAAA,IAAW,aAAA,IAAiB,UAAU,OAAO,KAAA;AAC/D,EAAA,IAAI,CAAC,OAAA,CAAQ,MAAA,EAAQ,OAAO,KAAA;AAC5B,EAAA,OAAO,QAAQ,OAAO,CAAA;AACvB;AAEA,eAAe,qBAAA,CACd,WACA,IAAA,EACC;AAED,EAAA,MAAM,WAAA,GAAc,IAAI,UAAA,EAAkE;AAE1F,EAAA,IAAI,EAAE,eAAA,IAAmB,IAAA,CAAK,IAAA,CAAA,EAAO,OAAO,WAAA;AAE5C,EAAA,MAAM,QAAQA,QAAA,CAAG,IAAA,CAAK,IAAA,CAAK,SAAA,EAAW,QAAQ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ACD","file":"registry.commands.js","sourcesContent":["import {\n\tBaseChatInputCommandData,\n\tBaseContextCommandData,\n\tMessageCommandData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n\tTriviousClient,\n\tUserCommandData,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport { importFile } from \"#utility/functions.js\";\nimport { ApplicationCommandType, Collection } from \"discord.js\";\nimport { Dirent, existsSync, promises as fs } from \"fs\";\nimport path, { join } from \"path\";\n\nfunction validateCommand<T extends BaseChatInputCommandData | BaseContextCommandData>(\n\tcommand: T,\n\texpects: (command: Partial<T>) => boolean\n): boolean {\n\tif (!(\"active\" in command && \"commandType\" in command)) return false;\n\tif (!command.active) return false;\n\treturn expects(command);\n}\n\nasync function parseSlashSubcommands(\n\tdirectory: string,\n\tdata: SlashCommandData | SlashSubcommandGroupData<boolean>\n) {\n\tconst _parentType = \"context\" in data ? \"command\" : \"group\";\n\tconst subcommands = new Collection<string, SlashSubcommandData<typeof _parentType, true>>();\n\n\tif (!(\"addSubcommand\" in data.data)) return subcommands;\n\n\tconst files = fs.glob(join(directory, \"./*.js\"));\n\tfor await (const file of files) {\n\t\tconst subcommand = await importFile<SlashSubcommandData<typeof _parentType, true>>(file);\n\t\tif (\n\t\t\t!subcommand ||\n\t\t\t!validateCommand(subcommand, (subcmd) => subcmd.context === \"SlashSubcommand\")\n\t\t)\n\t\t\tcontinue;\n\n\t\tsubcommand.parent = data;\n\t\tdata.data.addSubcommand(subcommand.data);\n\t\tsubcommands.set(subcommand.data.name, subcommand);\n\t}\n\n\tif (subcommands.size > 0) data.subcommands = subcommands;\n\treturn subcommands;\n}\n\nasync function parseSlashCommand(\n\tfile: string,\n\tparentDir: string,\n\tsubdirectories: Dirent<string>[]\n) {\n\tif (!existsSync(file)) return;\n\n\tconst command = await importFile<SlashCommandData>(file);\n\tif (\n\t\t!command ||\n\t\t!validateCommand(command, (cmd) => cmd.context === \"SlashCommand\") ||\n\t\t!(\"addSubcommand\" in command.data)\n\t)\n\t\treturn;\n\n\tawait parseSlashSubcommands(parentDir, command);\n\n\tfor (const subdir of subdirectories) {\n\t\tconst indexFile = path.resolve(subdir.parentPath, subdir.name, \"index.js\");\n\t\tif (!existsSync(indexFile)) continue;\n\n\t\tconst group = await importFile<SlashSubcommandGroupData<true>>(indexFile);\n\t\tif (\n\t\t\t!group ||\n\t\t\t!(\"context\" in group && \"addSubcommandGroup\" in command.data) ||\n\t\t\tgroup.context !== \"SlashSubcommandGroup\"\n\t\t)\n\t\t\tcontinue;\n\n\t\tgroup.parent = command;\n\t\tif (!command.subcommandGroups) command.subcommandGroups = new Collection();\n\t\tawait parseSlashSubcommands(join(subdir.parentPath, subdir.name), group);\n\n\t\tif (group.subcommands.size > 0) {\n\t\t\tcommand.data.addSubcommandGroup(group.data);\n\t\t\tcommand.subcommandGroups.set(group.data.name, group);\n\t\t}\n\t}\n\n\treturn command;\n}\n\nasync function parseContextCommands(parentDir: string) {\n\tconst collection = new Collection<string, MessageCommandData | UserCommandData>();\n\tconst files = fs.glob(join(parentDir, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst contextCommand = await importFile<MessageCommandData | UserCommandData>(file);\n\t\tif (\n\t\t\t!contextCommand ||\n\t\t\t!validateCommand(\n\t\t\t\tcontextCommand,\n\t\t\t\t(cmd) =>\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.Message ||\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.User\n\t\t\t)\n\t\t)\n\t\t\tcontinue;\n\n\t\tcontextCommand.data.setType(contextCommand.commandType);\n\t\tcollection.set(contextCommand.data.name, contextCommand);\n\t}\n\n\treturn collection;\n}\n\nasync function registerDirectory(client: TriviousClient, parentDir: string) {\n\tconst entries = await fs.readdir(parentDir, { withFileTypes: true });\n\tconst subdirectories = entries.filter((entry) => entry.isDirectory());\n\n\tconst indexFile = path.resolve(parentDir, \"index.js\");\n\tconst slashCommand = await parseSlashCommand(indexFile, parentDir, subdirectories);\n\tif (slashCommand) client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\n\tconst contextCommands = await parseContextCommands(parentDir);\n\tcontextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));\n}\n\nexport default async function registerCommands(client: TriviousClient, directory: string) {\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register commands; passed directory '${directory}' does not exist!`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\n\tconst processedDirectories = new Set<string>();\n\n\tconst files = fs.glob(join(directory, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst parentDir = path.dirname(file);\n\n\t\tif (processedDirectories.has(parentDir)) continue;\n\t\tprocessedDirectories.add(parentDir);\n\n\t\tawait registerDirectory(client, parentDir);\n\t}\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import 'discord.js';
|
|
2
|
-
export { e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction } from '../../modules.types-
|
|
2
|
+
export { e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction } from '../../modules.types-BUvtZD_e.js';
|
|
3
|
+
import '../permissions/permissions.types.js';
|
|
3
4
|
import '../client/client.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/components/components.types.ts"],"names":["ComponentContext"],"mappings":"AASO,IAAK,gBAAA,qBAAAA,iBAAAA,KAAL;AACN,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAA;AACA,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAA;AACA,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAA;AAHW,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA","file":"components.types.js","sourcesContent":["import { 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\n/**\n * Trivious component\n * @param component The component type\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 {\n\tcomponent: ComponentContext;\n\tidentifier: string;\n\tflags?: ComponentFlags[];\n\texecute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/features/components/components.types.ts"],"names":["ComponentContext"],"mappings":"AASO,IAAK,gBAAA,qBAAAA,iBAAAA,KAAL;AACN,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAA;AACA,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAA;AACA,EAAAA,iBAAAA,CAAAA,iBAAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAA;AAHW,EAAA,OAAAA,iBAAAA;AAAA,CAAA,EAAA,gBAAA,IAAA,EAAA","file":"components.types.js","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\n/**\n * Trivious component\n * @param component The component type\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 {\n\tcomponent: ComponentContext;\n\tidentifier: string;\n\tflags?: ComponentFlags[];\n\tpermissions?: CommandPermissionValues;\n\texecute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare function registerComponents(client: TriviousClient, directory: string): Promise<void>;
|
|
6
7
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '../client/client.types.js';
|
|
2
|
-
import { f as ComponentContext } from '../../modules.types-
|
|
2
|
+
import { f as ComponentContext } from '../../modules.types-BUvtZD_e.js';
|
|
3
|
+
import '../permissions/permissions.types.js';
|
|
3
4
|
import 'discord.js';
|
|
4
5
|
|
|
5
6
|
type ComponentTag = "awaited";
|
|
@@ -1,7 +1,8 @@
|
|
|
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-BUvtZD_e.js';
|
|
5
|
+
import '../permissions/permissions.types.js';
|
|
5
6
|
|
|
6
7
|
declare const customId: {
|
|
7
8
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../../client/client.types.js';
|
|
4
|
+
import '../../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare const _default: {
|
|
6
7
|
name: "clientReady";
|
|
@@ -1,6 +1,7 @@
|
|
|
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-BUvtZD_e.js';
|
|
3
3
|
import '../../client/client.types.js';
|
|
4
|
+
import '../../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare const _default: {
|
|
6
7
|
name: "interactionCreate";
|
|
@@ -2,6 +2,7 @@ import { ComponentContext } from '../../../shared/typings.js';
|
|
|
2
2
|
import { ApplicationCommandType, ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
|
|
3
3
|
import { interactionReply, handleSlashCommand } from '../../../features/commands/methods.commands.js';
|
|
4
4
|
import customId from '../../../features/customId/methods.customid.js';
|
|
5
|
+
import { canMemberRunCommand } from '../../../features/permissions/methods.permissions.js';
|
|
5
6
|
|
|
6
7
|
var interactionCreate_default = {
|
|
7
8
|
name: "interactionCreate",
|
|
@@ -18,6 +19,15 @@ var interactionCreate_default = {
|
|
|
18
19
|
});
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
22
|
+
const hasPermission = canMemberRunCommand(client, command, interaction.member);
|
|
23
|
+
if (!hasPermission) {
|
|
24
|
+
await interactionReply({
|
|
25
|
+
interaction,
|
|
26
|
+
replyPayload: { content: "You do not have permission to run this command" },
|
|
27
|
+
flags: ["EphemeralReply"]
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
21
31
|
if (command.commandType === ApplicationCommandType.ChatInput && interaction.isChatInputCommand()) {
|
|
22
32
|
await handleSlashCommand(client, command, interaction);
|
|
23
33
|
} else {
|
|
@@ -39,6 +49,19 @@ var interactionCreate_default = {
|
|
|
39
49
|
});
|
|
40
50
|
return;
|
|
41
51
|
}
|
|
52
|
+
const hasPermission = canMemberRunCommand(
|
|
53
|
+
client,
|
|
54
|
+
component,
|
|
55
|
+
interaction.member
|
|
56
|
+
);
|
|
57
|
+
if (!hasPermission) {
|
|
58
|
+
await interactionReply({
|
|
59
|
+
interaction,
|
|
60
|
+
replyPayload: { content: "You do not have permission to use this component" },
|
|
61
|
+
flags: ["EphemeralReply"]
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
42
65
|
await component.execute(client, interaction);
|
|
43
66
|
}
|
|
44
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"names":[],"mappings":";;;;;;AAWA,IAAO,yBAAA,GAAQ;AAAA,EACd,IAAA,EAAM,mBAAA;AAAA,EACN,MAAM,OAAA,CAAQ,MAAA,EAAQ,WAAA,EAAa;AAClC,IAAA,IAAI,WAAA,CAAY,kBAAA,EAAmB,IAAK,WAAA,CAAY,sBAAqB,EAAG;AAC3E,MAAA,MAAM,EAAE,aAAY,GAAI,WAAA;AAExB,MAAA,MAAM,YAAA,GAAe,WAAA,CAAY,kBAAA,EAAmB,GACjD,MAAA,CAAO,OAAO,QAAA,CAAS,SAAA,GACvB,MAAA,CAAO,MAAA,CAAO,QAAA,CAAS,OAAA;AAC1B,MAAA,MAAM,OAAA,GAAU,YAAA,CAAa,GAAA,CAAI,WAAW,CAAA;AAE5C,MAAA,IAAI,CAAC,OAAA,EAAS;AACb,QAAA,MAAM,gBAAA,CAAiB;AAAA,UACtB,WAAA;AAAA,UACA,YAAA,EAAc,EAAE,OAAA,EAAS,4DAAA,EAA6D;AAAA,UACtF,KAAA,EAAO,CAAC,gBAAgB;AAAA,SACxB,CAAA;AACD,QAAA;AAAA,MACD;AAEA,MAAA,MAAM,aAAA,GAAgB,mBAAA,CAAoB,MAAA,EAAQ,OAAA,EAAS,YAAY,MAAqB,CAAA;AAC5F,MAAA,IAAI,CAAC,aAAA,EAAe;AACnB,QAAA,MAAM,gBAAA,CAAiB;AAAA,UACtB,WAAA;AAAA,UACA,YAAA,EAAc,EAAE,OAAA,EAAS,gDAA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,CAAC,aAAA,EAAe;AACnB,QAAA,MAAM,gBAAA,CAAiB;AAAA,UACtB,WAAA;AAAA,UACA,YAAA,EAAc,EAAE,OAAA,EAAS,kDAAA,EAAmD;AAAA,UAC5E,KAAA,EAAO,CAAC,gBAAgB;AAAA,SACxB,CAAA;AACD,QAAA;AAAA,MACD;AAEA,MAAA,MAAM,SAAA,CAAU,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAAA,IAC5C;AAAA,EACD;AACD","file":"interactionCreate.js","sourcesContent":["import { ComponentContext, type ContextCommandData, type Event } from \"#typings\";\nimport {\n\tApplicationCommandType,\n\tButtonInteraction,\n\tGuildMember,\n\tModalSubmitInteraction,\n} from \"discord.js\";\nimport { handleSlashCommand, interactionReply } from \"src/features/commands/methods.commands.js\";\nimport customId from \"src/features/customId/methods.customid.js\";\nimport { canMemberRunCommand } from \"src/features/permissions/methods.permissions.js\";\n\nexport default {\n\tname: \"interactionCreate\",\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 hasPermission = canMemberRunCommand(client, command, interaction.member as GuildMember);\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 run this command\" },\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\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\n\t\t\tawait component.execute(client, interaction);\n\t\t}\n\t},\n} satisfies Event<\"interactionCreate\">;\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare function bindEvents(client: TriviousClient): Promise<void>;
|
|
6
7
|
declare function registerEvents(client: TriviousClient, directory: string): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { T as TriviousClient } from '../../modules.types-
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../client/client.types.js';
|
|
4
|
+
import '../permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare function bindModules(client: TriviousClient): Promise<void>;
|
|
6
7
|
declare function registerModules(client: TriviousClient, directory: string): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GuildMember, User } from 'discord.js';
|
|
2
|
+
import { T as TriviousClient, a as BaseCommandData, e as Component } from '../../modules.types-BUvtZD_e.js';
|
|
3
|
+
import '../client/client.types.js';
|
|
4
|
+
import './permissions.types.js';
|
|
5
|
+
|
|
6
|
+
declare function canMemberRunCommand(client: TriviousClient, command: BaseCommandData | Component, member: GuildMember): [boolean, string];
|
|
7
|
+
declare function canUserRunCommand(client: TriviousClient, command: BaseCommandData | Component, user: User): [boolean, string];
|
|
8
|
+
|
|
9
|
+
export { canMemberRunCommand, canUserRunCommand };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function canMemberRunCommand(client, command, member) {
|
|
2
|
+
const { permissions } = command;
|
|
3
|
+
if (!permissions) return [true, "No permissions set"];
|
|
4
|
+
if (client.trivious.ownerUserIds && client.trivious.ownerUserIds.includes(member.user.id))
|
|
5
|
+
return [true, "User can run command"];
|
|
6
|
+
const { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;
|
|
7
|
+
if (userIds) return canUserRunCommand(client, command, member.user);
|
|
8
|
+
let memberHasPermission = false;
|
|
9
|
+
let memberHasRole = false;
|
|
10
|
+
if (requiredMemberPermissions) {
|
|
11
|
+
for (const bit of requiredMemberPermissions) {
|
|
12
|
+
if (member.permissions.has(bit)) {
|
|
13
|
+
memberHasPermission = true;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (requiredRoleIds) {
|
|
19
|
+
for (const roleId of requiredRoleIds) {
|
|
20
|
+
if (member.roles.cache.has(roleId)) {
|
|
21
|
+
memberHasRole = true;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return memberHasPermission || memberHasRole ? [true, "User can run command"] : [false, "User cannot run command"];
|
|
27
|
+
}
|
|
28
|
+
function canUserRunCommand(client, command, user) {
|
|
29
|
+
const { permissions } = command;
|
|
30
|
+
if (!permissions) return [true, "No permissions set"];
|
|
31
|
+
if (client.trivious.ownerUserIds && client.trivious.ownerUserIds.includes(user.id))
|
|
32
|
+
return [true, "User can run command"];
|
|
33
|
+
const { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;
|
|
34
|
+
if (!userIds && (requiredMemberPermissions || requiredRoleIds))
|
|
35
|
+
return [false, "Cannot validate permissions; use canMemberRunCommand instead"];
|
|
36
|
+
return userIds.includes(user.id) ? [true, "User can run command"] : [false, "User cannot run command"];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { canMemberRunCommand, canUserRunCommand };
|
|
40
|
+
//# sourceMappingURL=methods.permissions.js.map
|
|
41
|
+
//# sourceMappingURL=methods.permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/permissions/methods.permissions.ts"],"names":[],"mappings":"AAGO,SAAS,mBAAA,CACf,MAAA,EACA,OAAA,EACA,MAAA,EACoB;AACpB,EAAA,MAAM,EAAE,aAAY,GAAI,OAAA;AACxB,EAAA,IAAI,CAAC,WAAA,EAAa,OAAO,CAAC,MAAM,oBAAoB,CAAA;AAEpD,EAAA,IAAI,MAAA,CAAO,SAAS,YAAA,IAAgB,MAAA,CAAO,SAAS,YAAA,CAAa,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,EA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2B,eAAA,EAAiB,OAAA,EAAQ,GAAI,WAAA;AAEhE,EAAA,IAAI,CAAC,YAAY,yBAAA,IAA6B,eAAA,CAAA;AAC7C,IAAA,OAAO,CAAC,OAAO,8DAA8D,CAAA;AAE9E,EAAA,OAAO,OAAA,CAAQ,QAAA,CAAS,IAAA,CAAK,EAAE,CAAA,GAC5B,CAAC,IAAA,EAAM,sBAAsB,CAAA,GAC7B,CAAC,KAAA,EAAO,yBAAyB,CAAA;AACrC","file":"methods.permissions.js","sourcesContent":["import { BaseCommandData, Component, TriviousClient } from \"#typings\";\nimport { GuildMember, User } from \"discord.js\";\n\nexport function canMemberRunCommand(\n\tclient: TriviousClient,\n\tcommand: BaseCommandData | Component,\n\tmember: GuildMember\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(member.user.id))\n\t\treturn [true, \"User can run command\"];\n\n\tconst { requiredMemberPermissions, requiredRoleIds, userIds } = permissions;\n\tif (userIds) return canUserRunCommand(client, command, member.user);\n\n\tlet memberHasPermission = false;\n\tlet memberHasRole = false;\n\n\tif (requiredMemberPermissions) {\n\t\tfor (const bit of requiredMemberPermissions) {\n\t\t\tif (member.permissions.has(bit)) {\n\t\t\t\tmemberHasPermission = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (requiredRoleIds) {\n\t\tfor (const roleId of requiredRoleIds) {\n\t\t\tif (member.roles.cache.has(roleId)) {\n\t\t\t\tmemberHasRole = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn memberHasPermission || memberHasRole\n\t\t? [true, \"User can run command\"]\n\t\t: [false, \"User cannot run command\"];\n}\n\nexport function canUserRunCommand(\n\tclient: TriviousClient,\n\tcommand: BaseCommandData | Component,\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\n\tif (!userIds && (requiredMemberPermissions || requiredRoleIds))\n\t\treturn [false, \"Cannot validate permissions; use canMemberRunCommand instead\"];\n\n\treturn userIds.includes(user.id)\n\t\t? [true, \"User can run command\"]\n\t\t: [false, \"User cannot run command\"];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"permissions.types.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createActionRow, createEmbed } from './features/builders/utility.builders.js';
|
|
2
2
|
export { handleSlashCommand, interactionReply } from './features/commands/methods.commands.js';
|
|
3
3
|
export { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from './features/client/client.types.js';
|
|
4
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction, i as ContextCommandData, E as Event, M as MessageCommandData, j as Module, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, T as TriviousClient, U as UserCommandData } from './modules.types-
|
|
4
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction, i as ContextCommandData, E as Event, M as MessageCommandData, j as Module, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, T as TriviousClient, U as UserCommandData } from './modules.types-BUvtZD_e.js';
|
|
5
5
|
export { ComponentCustomId, ComponentTag } from './features/customId/customid.types.js';
|
|
6
|
+
export { CommandPermissionValues } from './features/permissions/permissions.types.js';
|
|
6
7
|
import 'discord.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Client, Collection, ApplicationCommandType, Interaction,
|
|
1
|
+
import { Client, Collection, ApplicationCommandType, Interaction, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AnySelectMenuInteraction, ButtonInteraction, ModalSubmitInteraction, ClientEvents } from 'discord.js';
|
|
2
2
|
import { TriviousClientOptions } from './features/client/client.types.js';
|
|
3
|
+
import { CommandPermissionValues } from './features/permissions/permissions.types.js';
|
|
3
4
|
|
|
4
5
|
declare class TriviousClient extends Client {
|
|
5
6
|
trivious: TriviousClientOptions;
|
|
@@ -37,6 +38,7 @@ type CommandFunction<T extends Interaction> = (client: TriviousClient, interacti
|
|
|
37
38
|
interface BaseCommandData {
|
|
38
39
|
active: boolean;
|
|
39
40
|
flags?: CommandFlags[];
|
|
41
|
+
permissions?: CommandPermissionValues;
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* Base Trivious chat input command data
|
|
@@ -68,8 +70,8 @@ interface BaseContextCommandData extends BaseCommandData {
|
|
|
68
70
|
*/
|
|
69
71
|
interface SlashCommandData extends BaseChatInputCommandData {
|
|
70
72
|
context: "SlashCommand";
|
|
71
|
-
data:
|
|
72
|
-
subcommands?: Collection<string, SlashSubcommandData<
|
|
73
|
+
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
|
|
74
|
+
subcommands?: Collection<string, SlashSubcommandData<"command", true>>;
|
|
73
75
|
subcommandGroups?: Collection<string, SlashSubcommandGroupData<true>>;
|
|
74
76
|
run?: CommandFunction<ChatInputCommandInteraction>;
|
|
75
77
|
}
|
|
@@ -82,7 +84,7 @@ interface SlashCommandData extends BaseChatInputCommandData {
|
|
|
82
84
|
interface SlashSubcommandGroupData<Processed extends boolean = false> {
|
|
83
85
|
context: "SlashSubcommandGroup";
|
|
84
86
|
data: SlashCommandSubcommandGroupBuilder;
|
|
85
|
-
subcommands: Collection<string, SlashSubcommandData<
|
|
87
|
+
subcommands: Collection<string, SlashSubcommandData<"group", boolean>>;
|
|
86
88
|
parent?: Processed extends true ? SlashCommandData : SlashCommandData | undefined;
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
@@ -93,7 +95,7 @@ interface SlashSubcommandGroupData<Processed extends boolean = false> {
|
|
|
93
95
|
* @param data The slash subcommand builder
|
|
94
96
|
* @param execute Function for when the subcommand is executed
|
|
95
97
|
*/
|
|
96
|
-
interface SlashSubcommandData<
|
|
98
|
+
interface SlashSubcommandData<Parent extends "command" | "group" = "command", Processed extends boolean = false> extends BaseChatInputCommandData {
|
|
97
99
|
context: "SlashSubcommand";
|
|
98
100
|
data: SlashCommandSubcommandBuilder;
|
|
99
101
|
execute: CommandFunction<ChatInputCommandInteraction>;
|
|
@@ -145,6 +147,7 @@ interface Component {
|
|
|
145
147
|
component: ComponentContext;
|
|
146
148
|
identifier: string;
|
|
147
149
|
flags?: ComponentFlags[];
|
|
150
|
+
permissions?: CommandPermissionValues;
|
|
148
151
|
execute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;
|
|
149
152
|
}
|
|
150
153
|
|
|
@@ -2,9 +2,10 @@ import registerCommands from '../features/commands/registry.commands.js';
|
|
|
2
2
|
import registerComponents from '../features/components/registry.components.js';
|
|
3
3
|
import registerEvents, { bindEvents } from '../features/events/registry.events.js';
|
|
4
4
|
import registerModules, { bindModules } from '../features/modules/registry.modules.js';
|
|
5
|
-
import '../modules.types-
|
|
5
|
+
import '../modules.types-BUvtZD_e.js';
|
|
6
6
|
import 'discord.js';
|
|
7
7
|
import '../features/client/client.types.js';
|
|
8
|
+
import '../features/permissions/permissions.types.js';
|
|
8
9
|
|
|
9
10
|
declare const _default: {
|
|
10
11
|
readonly commands: {
|
package/dist/shared/typings.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from '../features/client/client.types.js';
|
|
2
|
-
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction, i as ContextCommandData, E as Event, M as MessageCommandData, j as Module, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, T as TriviousClient, U as UserCommandData } from '../modules.types-
|
|
2
|
+
export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as CommandFlags, d as CommandFunction, e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction, i as ContextCommandData, E as Event, M as MessageCommandData, j as Module, S as SlashCommandData, k as SlashSubcommandData, l as SlashSubcommandGroupData, T as TriviousClient, U as UserCommandData } from '../modules.types-BUvtZD_e.js';
|
|
3
3
|
export { ComponentCustomId, ComponentTag } from '../features/customId/customid.types.js';
|
|
4
|
+
export { CommandPermissionValues } from '../features/permissions/permissions.types.js';
|
|
4
5
|
import 'discord.js';
|
package/dist/shared/typings.js
CHANGED
|
@@ -5,5 +5,6 @@ export * from '../features/components/components.types.js';
|
|
|
5
5
|
export * from '../features/customId/customid.types.js';
|
|
6
6
|
export * from '../features/events/events.types.js';
|
|
7
7
|
export * from '../features/modules/modules.types.js';
|
|
8
|
+
export * from '../features/permissions/permissions.types.js';
|
|
8
9
|
//# sourceMappingURL=typings.js.map
|
|
9
10
|
//# sourceMappingURL=typings.js.map
|
package/dist/utility/errors.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { a as BaseCommandData, S as SlashCommandData } from '../modules.types-
|
|
1
|
+
import { a as BaseCommandData, S as SlashCommandData } from '../modules.types-BUvtZD_e.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import '../features/client/client.types.js';
|
|
4
|
+
import '../features/permissions/permissions.types.js';
|
|
4
5
|
|
|
5
6
|
declare class TriviousError extends Error {
|
|
6
7
|
readonly field?: string;
|