trivious 2.1.2 → 2.1.4

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.
Files changed (32) hide show
  1. package/dist/{modules.types-BUvtZD_e.d.ts → commands.types-lx3T1lsC.d.ts} +42 -67
  2. package/dist/features/client/deploy.client.d.ts +1 -1
  3. package/dist/features/client/deploy.client.js +1 -3
  4. package/dist/features/client/deploy.client.js.map +1 -1
  5. package/dist/features/client/trivious.client.d.ts +1 -1
  6. package/dist/features/client/trivious.client.js.map +1 -1
  7. package/dist/features/commands/builders.commands.d.ts +12 -0
  8. package/dist/features/commands/builders.commands.js +39 -0
  9. package/dist/features/commands/builders.commands.js.map +1 -0
  10. package/dist/features/commands/commands.types.d.ts +1 -1
  11. package/dist/features/commands/methods.commands.d.ts +1 -1
  12. package/dist/features/commands/registry.commands.d.ts +1 -1
  13. package/dist/features/commands/registry.commands.js +15 -1
  14. package/dist/features/commands/registry.commands.js.map +1 -1
  15. package/dist/features/components/components.types.d.ts +1 -1
  16. package/dist/features/components/registry.components.d.ts +1 -1
  17. package/dist/features/customId/customid.types.d.ts +1 -1
  18. package/dist/features/customId/methods.customid.d.ts +1 -1
  19. package/dist/features/events/events.types.d.ts +1 -1
  20. package/dist/features/events/presets/clientReady.d.ts +1 -1
  21. package/dist/features/events/presets/interactionCreate.d.ts +1 -1
  22. package/dist/features/events/presets/interactionCreate.js.map +1 -1
  23. package/dist/features/events/registry.events.d.ts +1 -1
  24. package/dist/features/modules/modules.types.d.ts +1 -1
  25. package/dist/features/modules/registry.modules.d.ts +1 -1
  26. package/dist/features/permissions/methods.permissions.d.ts +1 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.js +1 -0
  29. package/dist/shared/registries.d.ts +1 -1
  30. package/dist/shared/typings.d.ts +1 -1
  31. package/dist/utility/errors.d.ts +1 -1
  32. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { Client, Collection, ApplicationCommandType, Interaction, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AnySelectMenuInteraction, ButtonInteraction, ModalSubmitInteraction, ClientEvents } from 'discord.js';
1
+ import { Client, Collection, AnySelectMenuInteraction, ButtonInteraction, ModalSubmitInteraction, ClientEvents, ApplicationCommandType, Interaction, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction } 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
 
@@ -7,7 +7,7 @@ declare class TriviousClient extends Client {
7
7
  readonly stores: {
8
8
  commands: {
9
9
  chatInput: Collection<string, SlashCommandData>;
10
- context: Collection<string, BaseContextCommandData>;
10
+ context: Collection<string, ContextCommandData>;
11
11
  };
12
12
  components: Collection<string, Component>;
13
13
  events: Collection<string, Event>;
@@ -24,6 +24,41 @@ declare class TriviousClient extends Client {
24
24
  deploy(): Promise<void>;
25
25
  }
26
26
 
27
+ type ComponentFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
28
+ type ComponentInteraction = AnySelectMenuInteraction | ButtonInteraction | ModalSubmitInteraction;
29
+ declare enum ComponentContext {
30
+ Button = 0,
31
+ SelectMenu = 1,
32
+ Modal = 2
33
+ }
34
+ /**
35
+ * Trivious component
36
+ * @param component The component type
37
+ * @param identifier The unique identifier inside the custom id
38
+ * @param flags The component flags
39
+ * @param execute Component handler
40
+ */
41
+ interface Component {
42
+ component: ComponentContext;
43
+ identifier: string;
44
+ flags?: ComponentFlags[];
45
+ permissions?: CommandPermissionValues;
46
+ execute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;
47
+ }
48
+
49
+ interface Event<K extends keyof ClientEvents = keyof ClientEvents> {
50
+ name: K;
51
+ once?: boolean;
52
+ execute: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void> | void;
53
+ }
54
+
55
+ interface Module {
56
+ name: string;
57
+ events: {
58
+ [K in keyof ClientEvents]?: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void>;
59
+ };
60
+ }
61
+
27
62
  type ChatInputCommandContext = "SlashCommand" | "SlashSubcommand" | "SlashSubcommandGroup";
28
63
  type CommandFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
29
64
  type CommandFunction<T extends Interaction> = (client: TriviousClient, interaction: T) => Promise<void>;
@@ -55,8 +90,10 @@ interface BaseChatInputCommandData extends BaseCommandData {
55
90
  *
56
91
  * @param commandType ApplicationCommandType.Message | ApplicationCommandType.User
57
92
  */
58
- interface BaseContextCommandData extends BaseCommandData {
59
- commandType: ApplicationCommandType.Message | ApplicationCommandType.User;
93
+ interface ContextCommandData<T extends "Message" | "User" | null = null> extends BaseCommandData {
94
+ commandType: T extends null ? ApplicationCommandType.Message | ApplicationCommandType.User : T extends "Message" ? ApplicationCommandType.Message : ApplicationCommandType.User;
95
+ data: ContextMenuCommandBuilder;
96
+ execute: CommandFunction<T extends null ? MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction : T extends "Message" ? MessageContextMenuCommandInteraction : UserContextMenuCommandInteraction>;
60
97
  }
61
98
  /**
62
99
  * Trivious slash command data
@@ -101,67 +138,5 @@ interface SlashSubcommandData<Parent extends "command" | "group" = "command", Pr
101
138
  execute: CommandFunction<ChatInputCommandInteraction>;
102
139
  parent?: Processed extends true ? Parent extends "command" ? SlashCommandData : SlashSubcommandGroupData<true> : Parent extends "command" ? SlashCommandData | undefined : SlashSubcommandGroupData<false> | undefined;
103
140
  }
104
- /**
105
- * Trivious message command data
106
- *
107
- * @param context MessageContextCommand
108
- * @param commandType ApplicationCommandType.Message
109
- * @param data The context menu builder
110
- * @param execute Function for when the message command is executed
111
- */
112
- interface MessageCommandData extends BaseContextCommandData {
113
- commandType: ApplicationCommandType.Message;
114
- data: ContextMenuCommandBuilder;
115
- execute: CommandFunction<MessageContextMenuCommandInteraction>;
116
- }
117
- /**
118
- * Trivious user command data
119
- *
120
- * @param context UserContextCommand
121
- * @param commandType ApplicationCommandType.User
122
- * @param data The context menu builder
123
- * @param execute Function for when the user command is executed
124
- */
125
- interface UserCommandData extends BaseContextCommandData {
126
- commandType: ApplicationCommandType.User;
127
- data: ContextMenuCommandBuilder;
128
- execute: CommandFunction<UserContextMenuCommandInteraction>;
129
- }
130
- type ContextCommandData = MessageCommandData | UserCommandData;
131
-
132
- type ComponentFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
133
- type ComponentInteraction = AnySelectMenuInteraction | ButtonInteraction | ModalSubmitInteraction;
134
- declare enum ComponentContext {
135
- Button = 0,
136
- SelectMenu = 1,
137
- Modal = 2
138
- }
139
- /**
140
- * Trivious component
141
- * @param component The component type
142
- * @param identifier The unique identifier inside the custom id
143
- * @param flags The component flags
144
- * @param execute Component handler
145
- */
146
- interface Component {
147
- component: ComponentContext;
148
- identifier: string;
149
- flags?: ComponentFlags[];
150
- permissions?: CommandPermissionValues;
151
- execute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;
152
- }
153
-
154
- interface Event<K extends keyof ClientEvents = keyof ClientEvents> {
155
- name: K;
156
- once?: boolean;
157
- execute: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void> | void;
158
- }
159
-
160
- interface Module {
161
- name: string;
162
- events: {
163
- [K in keyof ClientEvents]?: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void>;
164
- };
165
- }
166
141
 
167
- export { type BaseChatInputCommandData as B, type ChatInputCommandContext as C, type Event as E, type MessageCommandData as M, type SlashCommandData as S, TriviousClient as T, type UserCommandData as U, type BaseCommandData as a, type BaseContextCommandData as b, type CommandFlags as c, type CommandFunction as d, type Component as e, ComponentContext as f, type ComponentFlags as g, type ComponentInteraction as h, type ContextCommandData as i, type Module as j, type SlashSubcommandData as k, type SlashSubcommandGroupData as l };
142
+ export { type BaseChatInputCommandData as B, type ChatInputCommandContext as C, type Event as E, type Module as M, type SlashCommandData as S, TriviousClient as T, type BaseCommandData as a, type CommandFlags as b, type CommandFunction as c, type Component as d, ComponentContext as e, type ComponentFlags as f, type ComponentInteraction as g, type ContextCommandData as h, type SlashSubcommandData as i, type SlashSubcommandGroupData as j };
@@ -1,4 +1,4 @@
1
- import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../commands.types-lx3T1lsC.js';
2
2
  import 'discord.js';
3
3
  import './client.types.js';
4
4
  import '../permissions/permissions.types.js';
@@ -13,9 +13,7 @@ async function commandDeploy(client) {
13
13
  const commands = client.stores.commands;
14
14
  const body = [
15
15
  ...commands.chatInput.map((command) => command.data.toJSON()),
16
- ...commands.context.map(
17
- (command) => command.data.toJSON()
18
- )
16
+ ...commands.context.map((command) => command.data.toJSON())
19
17
  ];
20
18
  if (commandHashConfig && commandHashConfig.enabled) {
21
19
  const hashFile = join(commandHashConfig.persistentDataPath || "data", "commands.hash");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"names":[],"mappings":";;;;;;AAQA,eAAO,cAAqC,MAAA,EAAwB;AACnE,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,MAAA,CAAO,QAAA;AAErC,EAAA,MAAM,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,YAAY,iBAAiB,CAAA;AAC1E,EAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,YAAY,cAAc,CAAA;AACpE,EAAA,IAAI,CAAC,YAAY,CAAC,KAAA;AACjB,IAAA,MAAM,IAAI,cAAc,gDAAgD,CAAA;AAEzE,EAA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A,OAAA,CAAQ,KAAA,CAAM,CAAA,qCAAA,EAAwC,QAAQ,CAAA,CAAE,CAAA;AAAA,EACjE;AAEA,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,EAAE,SAAS,IAAA,EAAM,CAAA,CAAE,QAAA,CAAS,KAAK,CAAA;AACvD,EAAA,MAAM,IAAA,CAAK,IAAI,MAAA,CAAO,mBAAA,CAAoB,QAAQ,CAAA,EAAG,EAAE,MAAM,CAAA;AAC7D,EAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,SAAA,CAAW,CAAA;AAC5D","file":"deploy.client.js","sourcesContent":["import { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { TriviousError } from \"src/utility/errors.js\";\nimport { MessageCommandData, UserCommandData } from \"../commands/commands.types.js\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) =>\n\t\t\t(command as UserCommandData | MessageCommandData).data.toJSON()\n\t\t),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"]}
1
+ {"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"names":[],"mappings":";;;;;;AAOA,eAAO,cAAqC,MAAA,EAAwB;AACnE,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,MAAA,CAAO,QAAA;AAErC,EAAA,MAAM,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,YAAY,iBAAiB,CAAA;AAC1E,EAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,YAAY,cAAc,CAAA;AACpE,EAAA,IAAI,CAAC,YAAY,CAAC,KAAA;AACjB,IAAA,MAAM,IAAI,cAAc,gDAAgD,CAAA;AAEzE,EAAA,MAAM,QAAA,GAAW,OAAO,MAAA,CAAO,QAAA;AAC/B,EAAA,MAAM,IAAA,GAAO;AAAA,IACZ,GAAG,SAAS,SAAA,CAAU,GAAA,CAAI,CAAC,OAAA,KAAY,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAQ,CAAA;AAAA,IAC5D,GAAG,SAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,OAAA,KAAY,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAQ;AAAA,GAC3D;AAEA,EAAA,IAAI,iBAAA,IAAqB,kBAAkB,OAAA,EAAS;AACnD,IAAA,MAAM,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,CAAW,CAAA;AAC5D","file":"deploy.client.js","sourcesContent":["import { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { TriviousError } from \"src/utility/errors.js\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) => command.data.toJSON()),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import 'discord.js';
2
2
  import './client.types.js';
3
- export { T as default } from '../../modules.types-BUvtZD_e.js';
3
+ export { T as default } from '../../commands.types-lx3T1lsC.js';
4
4
  import '../permissions/permissions.types.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"names":[],"mappings":";;;;;;AAeA,MAAO,uBAAqC,MAAA,CAAO;AAAA,EAClD,QAAA;AAAA,EACS,MAAA;AAAA,EAUT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAEhB,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACb,QAAA,EAAU;AAAA,QACT,SAAA,EAAW,IAAI,UAAA,EAAW;AAAA,QAC1B,OAAA,EAAS,IAAI,UAAA;AAAW,OACzB;AAAA,MACA,UAAA,EAAY,IAAI,UAAA,EAAW;AAAA,MAC3B,MAAA,EAAQ,IAAI,UAAA,EAAW;AAAA,MACvB,OAAA,EAAS,IAAI,UAAA;AAAW,KACzB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAAA,GAAQ;AACb,IAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,IAAA,CAAK,QAAA,CAAS,YAAY,cAAc,CAAA;AAClE,IAAA,IAAI,CAAC,KAAA,EAAO;AACX,MAAA,MAAM,IAAI,aAAA;AAAA,QACT,CAAA,gCAAA,EAAmC,IAAA,CAAK,QAAA,CAAS,WAAA,CAAY,cAAc,CAAA,iBAAA,CAAA;AAAA,QAC3E;AAAA,OACD;AAAA,IACD;AAEA,IAAA,MAAM,KAAK,QAAA,EAAS;AACpB,IAAA,MAAM,KAAK,MAAA,EAAO;AAElB,IAAA,IAAI;AACH,MAAA,MAAM,UAAA,CAAW,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AACjC,MAAA,MAAM,UAAA,CAAW,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,IACnC,SAAS,GAAA,EAAU;AAClB,MAAA,MAAM,KAAA,GAAQ,IAAI,aAAA,CAAc,GAAA,CAAI,SAAS,uCAAuC,CAAA;AACpF,MAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA,IACpB;AAEA,IAAA,MAAM,IAAA,CAAK,MAAM,KAAK,CAAA;AAAA,EACvB;AAAA,EAEA,MAAM,QAAA,GAAW;AAChB,IAAA,MAAM,GAAA,GAAM,SAAA,CAAU,mBAAA,CAAoB,IAAA,CAAK,SAAS,QAAQ,CAAA;AAEhE,IAAA,MAAM,UAAA,CAAW,MAAA,CAAO,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC1C,IAAA,MAAM,UAAA,CAAW,OAAA,CAAQ,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC3C,IAAA,MAAM,UAAA,CAAW,QAAA,CAAS,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC5C,IAAA,MAAM,UAAA,CAAW,UAAA,CAAW,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAAA,EAC/C;AAAA,EAEA,MAAM,MAAA,GAAS;AACd,IAAA,MAAM,cAAc,IAAI,CAAA;AAAA,EACzB;AACD","file":"trivious.client.js","sourcesContent":["import { Client, Collection } from \"discord.js\";\nimport registries from \"src/shared/registries.js\";\nimport structure from \"../structure/index.structure.js\";\n\nimport {\n\tBaseContextCommandData,\n\tComponent,\n\tEvent,\n\tModule,\n\tSlashCommandData,\n\tTriviousClientOptions,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport commandDeploy from \"./deploy.client.js\";\n\nexport default class TriviousClient extends Client {\n\ttrivious: TriviousClientOptions;\n\treadonly stores: {\n\t\tcommands: {\n\t\t\tchatInput: Collection<string, SlashCommandData>;\n\t\t\tcontext: Collection<string, BaseContextCommandData>;\n\t\t};\n\t\tcomponents: Collection<string, Component>;\n\t\tevents: Collection<string, Event>;\n\t\tmodules: Collection<string, Module>;\n\t};\n\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\n\n\t\tthis.stores = {\n\t\t\tcommands: {\n\t\t\t\tchatInput: new Collection(),\n\t\t\t\tcontext: new Collection(),\n\t\t\t},\n\t\t\tcomponents: new Collection(),\n\t\t\tevents: new Collection(),\n\t\t\tmodules: new Collection(),\n\t\t};\n\t}\n\n\t/**\n\t * Register, deploy and log into the bot.\n\t *\n\t * @throws {TriviousError} If invalid bot token\n\t */\n\tasync start() {\n\t\tconst token = process.env[this.trivious.credentials.tokenReference];\n\t\tif (!token) {\n\t\t\tthrow new TriviousError(\n\t\t\t\t`Bot token environment variable '${this.trivious.credentials.tokenReference}' does not exist!`,\n\t\t\t\t\"Null environment variable\"\n\t\t\t);\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\ttry {\n\t\t\tawait registries.events.bind(this);\n\t\t\tawait registries.modules.bind(this);\n\t\t} catch (err: any) {\n\t\t\tconst error = new TriviousError(err.message, \"Error during events and modules binds\");\n\t\t\tconsole.error(error);\n\t\t}\n\n\t\tawait this.login(token);\n\t}\n\n\tasync register() {\n\t\tconst dir = structure.resolveRelativePath(this.trivious.corePath);\n\n\t\tawait registries.events.register(this, dir);\n\t\tawait registries.modules.register(this, dir);\n\t\tawait registries.commands.register(this, dir);\n\t\tawait registries.components.register(this, dir);\n\t}\n\n\tasync deploy() {\n\t\tawait commandDeploy(this);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"names":[],"mappings":";;;;;;AAeA,MAAO,uBAAqC,MAAA,CAAO;AAAA,EAClD,QAAA;AAAA,EACS,MAAA;AAAA,EAUT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAEhB,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACb,QAAA,EAAU;AAAA,QACT,SAAA,EAAW,IAAI,UAAA,EAA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,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC3C,IAAA,MAAM,UAAA,CAAW,QAAA,CAAS,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC5C,IAAA,MAAM,UAAA,CAAW,UAAA,CAAW,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAAA,EAC/C;AAAA,EAEA,MAAM,MAAA,GAAS;AACd,IAAA,MAAM,cAAc,IAAI,CAAA;AAAA,EACzB;AACD","file":"trivious.client.js","sourcesContent":["import { Client, Collection } from \"discord.js\";\nimport registries from \"src/shared/registries.js\";\nimport structure from \"../structure/index.structure.js\";\n\nimport {\n\tComponent,\n\tContextCommandData,\n\tEvent,\n\tModule,\n\tSlashCommandData,\n\tTriviousClientOptions,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport commandDeploy from \"./deploy.client.js\";\n\nexport default class TriviousClient extends Client {\n\ttrivious: TriviousClientOptions;\n\treadonly stores: {\n\t\tcommands: {\n\t\t\tchatInput: Collection<string, SlashCommandData>;\n\t\t\tcontext: Collection<string, ContextCommandData>;\n\t\t};\n\t\tcomponents: Collection<string, Component>;\n\t\tevents: Collection<string, Event>;\n\t\tmodules: Collection<string, Module>;\n\t};\n\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\n\n\t\tthis.stores = {\n\t\t\tcommands: {\n\t\t\t\tchatInput: new Collection(),\n\t\t\t\tcontext: new Collection(),\n\t\t\t},\n\t\t\tcomponents: new Collection(),\n\t\t\tevents: new Collection(),\n\t\t\tmodules: new Collection(),\n\t\t};\n\t}\n\n\t/**\n\t * Register, deploy and log into the bot.\n\t *\n\t * @throws {TriviousError} If invalid bot token\n\t */\n\tasync start() {\n\t\tconst token = process.env[this.trivious.credentials.tokenReference];\n\t\tif (!token) {\n\t\t\tthrow new TriviousError(\n\t\t\t\t`Bot token environment variable '${this.trivious.credentials.tokenReference}' does not exist!`,\n\t\t\t\t\"Null environment variable\"\n\t\t\t);\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\ttry {\n\t\t\tawait registries.events.bind(this);\n\t\t\tawait registries.modules.bind(this);\n\t\t} catch (err: any) {\n\t\t\tconst error = new TriviousError(err.message, \"Error during events and modules binds\");\n\t\t\tconsole.error(error);\n\t\t}\n\n\t\tawait this.login(token);\n\t}\n\n\tasync register() {\n\t\tconst dir = structure.resolveRelativePath(this.trivious.corePath);\n\n\t\tawait registries.events.register(this, dir);\n\t\tawait registries.modules.register(this, dir);\n\t\tawait registries.commands.register(this, dir);\n\t\tawait registries.components.register(this, dir);\n\t}\n\n\tasync deploy() {\n\t\tawait commandDeploy(this);\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { h as ContextCommandData, S as SlashCommandData, i as SlashSubcommandData, j as SlashSubcommandGroupData } from '../../commands.types-lx3T1lsC.js';
2
+ import 'discord.js';
3
+ import '../client/client.types.js';
4
+ import '../permissions/permissions.types.js';
5
+
6
+ declare function createSlashCommand(data: Omit<SlashCommandData, "context" | "commandType" | "subcommands" | "subcommandGroups">): SlashCommandData;
7
+ declare function createSubcommand(data: Omit<SlashSubcommandData, "context" | "commandType" | "parent">): SlashSubcommandData;
8
+ declare function createSubcommandGroup(data: Omit<SlashSubcommandGroupData, "context" | "parent" | "subcommands">): SlashSubcommandGroupData;
9
+ declare function createMessageComponentCommand(data: Omit<ContextCommandData<"Message">, "commandType">): ContextCommandData<"Message">;
10
+ declare function createUserComponentCommand(data: Omit<ContextCommandData<"User">, "commandType">): ContextCommandData<"User">;
11
+
12
+ export { createMessageComponentCommand, createSlashCommand, createSubcommand, createSubcommandGroup, createUserComponentCommand };
@@ -0,0 +1,39 @@
1
+ import { ApplicationCommandType, Collection } from 'discord.js';
2
+
3
+ function createSlashCommand(data) {
4
+ return {
5
+ ...data,
6
+ context: "SlashCommand",
7
+ commandType: ApplicationCommandType.ChatInput
8
+ };
9
+ }
10
+ function createSubcommand(data) {
11
+ return {
12
+ ...data,
13
+ context: "SlashSubcommand",
14
+ commandType: ApplicationCommandType.ChatInput
15
+ };
16
+ }
17
+ function createSubcommandGroup(data) {
18
+ return {
19
+ ...data,
20
+ context: "SlashSubcommandGroup",
21
+ subcommands: new Collection()
22
+ };
23
+ }
24
+ function createMessageComponentCommand(data) {
25
+ return {
26
+ ...data,
27
+ commandType: ApplicationCommandType.Message
28
+ };
29
+ }
30
+ function createUserComponentCommand(data) {
31
+ return {
32
+ ...data,
33
+ commandType: ApplicationCommandType.User
34
+ };
35
+ }
36
+
37
+ export { createMessageComponentCommand, createSlashCommand, createSubcommand, createSubcommandGroup, createUserComponentCommand };
38
+ //# sourceMappingURL=builders.commands.js.map
39
+ //# sourceMappingURL=builders.commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/features/commands/builders.commands.ts"],"names":[],"mappings":";;AAQO,SAAS,mBACf,IAAA,EACmB;AACnB,EAAA,OAAO;AAAA,IACN,GAAG,IAAA;AAAA,IACH,OAAA,EAAS,cAAA;AAAA,IACT,aAAa,sBAAA,CAAuB;AAAA,GACrC;AACD;AAEO,SAAS,iBACf,IAAA,EACsB;AACtB,EAAA,OAAO;AAAA,IACN,GAAG,IAAA;AAAA,IACH,OAAA,EAAS,iBAAA;AAAA,IACT,aAAa,sBAAA,CAAuB;AAAA,GACrC;AACD;AAEO,SAAS,sBACf,IAAA,EAC2B;AAC3B,EAAA,OAAO;AAAA,IACN,GAAG,IAAA;AAAA,IACH,OAAA,EAAS,sBAAA;AAAA,IACT,WAAA,EAAa,IAAI,UAAA;AAAW,GAC7B;AACD;AAEO,SAAS,8BACf,IAAA,EACgC;AAChC,EAAA,OAAO;AAAA,IACN,GAAG,IAAA;AAAA,IACH,aAAa,sBAAA,CAAuB;AAAA,GACrC;AACD;AAEO,SAAS,2BACf,IAAA,EAC6B;AAC7B,EAAA,OAAO;AAAA,IACN,GAAG,IAAA;AAAA,IACH,aAAa,sBAAA,CAAuB;AAAA,GACrC;AACD","file":"builders.commands.js","sourcesContent":["import { ApplicationCommandType, Collection } from \"discord.js\";\nimport {\n\tContextCommandData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n} from \"./commands.types.js\";\n\nexport function createSlashCommand(\n\tdata: Omit<SlashCommandData, \"context\" | \"commandType\" | \"subcommands\" | \"subcommandGroups\">\n): SlashCommandData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashCommand\",\n\t\tcommandType: ApplicationCommandType.ChatInput,\n\t} satisfies SlashCommandData;\n}\n\nexport function createSubcommand(\n\tdata: Omit<SlashSubcommandData, \"context\" | \"commandType\" | \"parent\">\n): SlashSubcommandData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommand\",\n\t\tcommandType: ApplicationCommandType.ChatInput,\n\t} satisfies SlashSubcommandData;\n}\n\nexport function createSubcommandGroup(\n\tdata: Omit<SlashSubcommandGroupData, \"context\" | \"parent\" | \"subcommands\">\n): SlashSubcommandGroupData {\n\treturn {\n\t\t...data,\n\t\tcontext: \"SlashSubcommandGroup\",\n\t\tsubcommands: new Collection(),\n\t} satisfies SlashSubcommandGroupData;\n}\n\nexport function createMessageComponentCommand(\n\tdata: Omit<ContextCommandData<\"Message\">, \"commandType\">\n): ContextCommandData<\"Message\"> {\n\treturn {\n\t\t...data,\n\t\tcommandType: ApplicationCommandType.Message,\n\t} satisfies ContextCommandData<\"Message\">;\n}\n\nexport function createUserComponentCommand(\n\tdata: Omit<ContextCommandData<\"User\">, \"commandType\">\n): ContextCommandData<\"User\"> {\n\treturn {\n\t\t...data,\n\t\tcommandType: ApplicationCommandType.User,\n\t} satisfies ContextCommandData<\"User\">;\n}\n"]}
@@ -1,4 +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-BUvtZD_e.js';
2
+ export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CommandFlags, c as CommandFunction, h as ContextCommandData, S as SlashCommandData, i as SlashSubcommandData, j as SlashSubcommandGroupData } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../permissions/permissions.types.js';
4
4
  import '../client/client.types.js';
@@ -1,6 +1,6 @@
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-BUvtZD_e.js';
3
+ import { T as TriviousClient, S as SlashCommandData, b as CommandFlags } from '../../commands.types-lx3T1lsC.js';
4
4
  import '../client/client.types.js';
5
5
  import '../permissions/permissions.types.js';
6
6
 
@@ -1,4 +1,4 @@
1
- import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../commands.types-lx3T1lsC.js';
2
2
  import 'discord.js';
3
3
  import '../client/client.types.js';
4
4
  import '../permissions/permissions.types.js';
@@ -19,6 +19,10 @@ async function parseSlashSubcommands(directory, data) {
19
19
  continue;
20
20
  subcommand.parent = data;
21
21
  data.data.addSubcommand(subcommand.data);
22
+ if (subcommands.has(subcommand.data.name))
23
+ console.warn(
24
+ `[Trivious] Subcommand '${subcommand.data.name}' under ${data.context} '${data.data.name}' has a duplicate and has been overridden`
25
+ );
22
26
  subcommands.set(subcommand.data.name, subcommand);
23
27
  }
24
28
  if (subcommands.size > 0) data.subcommands = subcommands;
@@ -40,6 +44,10 @@ async function parseSlashCommand(file, parentDir, subdirectories) {
40
44
  if (!command.subcommandGroups) command.subcommandGroups = new Collection();
41
45
  await parseSlashSubcommands(join(subdir.parentPath, subdir.name), group);
42
46
  if (group.subcommands.size > 0) {
47
+ if (command.subcommandGroups.has(group.data.name))
48
+ console.warn(
49
+ `[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${command.data.name}' has a duplicate and has been overridden`
50
+ );
43
51
  command.data.addSubcommandGroup(group.data);
44
52
  command.subcommandGroups.set(group.data.name, group);
45
53
  }
@@ -66,7 +74,13 @@ async function registerDirectory(client, parentDir) {
66
74
  const subdirectories = entries.filter((entry) => entry.isDirectory());
67
75
  const indexFile = path.resolve(parentDir, "index.js");
68
76
  const slashCommand = await parseSlashCommand(indexFile, parentDir, subdirectories);
69
- if (slashCommand) client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);
77
+ if (slashCommand) {
78
+ if (client.stores.commands.chatInput.has(slashCommand.data.name))
79
+ console.warn(
80
+ `[Trivious] SlashCommand '${slashCommand.data.name}' has a duplicate and has been overridden`
81
+ );
82
+ client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);
83
+ }
70
84
  const contextCommands = await parseContextCommands(parentDir);
71
85
  contextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));
72
86
  }
@@ -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,CAAC,CAAA;AAC/C,EAAA,WAAA,MAAiB,QAAQ,KAAA,EAAO;AAC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AAA;AAEnC,IAAA,IAAI,oBAAA,CAAqB,GAAA,CAAI,SAAS,CAAA,EAAG;AACzC,IAAA,oBAAA,CAAqB,IAAI,SAAS,CAAA;AAElC,IAAA,MAAM,iBAAA,CAAkB,QAAQ,SAAS,CAAA;AAAA,EAC1C;AACD","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
+ {"version":3,"sources":["../../../src/features/commands/registry.commands.ts"],"names":["fs"],"mappings":";;;;;;AAcA,SAAS,eAAA,CACR,SACA,OAAA,EACU;AACV,EAAA,IAAI,EAAE,QAAA,IAAY,OAAA,IAAW,aAAA,IAAiB,UAAU,OAAO,KAAA;AAC/D,EAAA,IAAI,CAAC,OAAA,CAAQ,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,CAAC,CA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;AAAA,OACnD;AAED,IAAA,MAAA,CAAO,OAAO,QAAA,CAAS,SAAA,CAAU,IAAI,YAAA,CAAa,IAAA,CAAK,MAAM,YAAY,CAAA;AAAA,EAC1E;AAEA,EAAA,MAAM,eAAA,GAAkB,MAAM,oBAAA,CAAqB,SAAS,CAAA;AAC5D,EAAA,eAAA,CAAgB,OAAA,CAAQ,CAAC,GAAA,KAAQ,MAAA,CAAO,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM,GAAG,CAAC,CAAA;AACxF;AAEA,eAAO,gBAAA,CAAwC,QAAwB,SAAA,EAAmB;AACzF,EAAA,IAAI,CAAC,WAAW,SAAS,CAAA;AACxB,IAAA,MAAM,IAAI,aAAA;AAAA,MACT,kDAAkD,SAAS,CAAA,iBAAA,CAAA;AAAA,MAC3D;AAAA,KACD;AAED,EAAA,MAAM,oBAAA,uBAA2B,GAAA,EAAY;AAE7C,EAAA,MAAM,QAAQA,QAAA,CAAG,IAAA,CAAK,IAAA,CAAK,SAAA,EAAW,SAAS,CAAC,CAAA;AAChD,EAAA,WAAA,MAAiB,QAAQ,KAAA,EAAO;AAC/B,IAAA,MAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA;AAEnC,IAAA,IAAI,oBAAA,CAAqB,GAAA,CAAI,SAAS,CAAA,EAAG;AACzC,IAAA,oBAAA,CAAqB,IAAI,SAAS,CAAA;AAElC,IAAA,MAAM,iBAAA,CAAkB,QAAQ,SAAS,CAAA;AAAA,EAC1C;AACD","file":"registry.commands.js","sourcesContent":["import {\n\tBaseChatInputCommandData,\n\tContextCommandData,\n\tSlashCommandData,\n\tSlashSubcommandData,\n\tSlashSubcommandGroupData,\n\tTriviousClient,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport { importFile } from \"#utility/functions.js\";\nimport { ApplicationCommandType, Collection } from \"discord.js\";\nimport { Dirent, existsSync, promises as fs } from \"fs\";\nimport path, { join } from \"path\";\n\nfunction validateCommand<T extends BaseChatInputCommandData | ContextCommandData>(\n\tcommand: T,\n\texpects: (command: Partial<T>) => boolean\n): boolean {\n\tif (!(\"active\" in command && \"commandType\" in command)) return false;\n\tif (!command.active) return false;\n\treturn expects(command);\n}\n\nasync function parseSlashSubcommands(\n\tdirectory: string,\n\tdata: SlashCommandData | SlashSubcommandGroupData<boolean>\n) {\n\tconst _parentType = \"context\" in data ? \"command\" : \"group\";\n\tconst subcommands = new Collection<string, SlashSubcommandData<typeof _parentType, true>>();\n\n\tif (!(\"addSubcommand\" in data.data)) return subcommands;\n\n\tconst files = fs.glob(join(directory, \"./*.js\"));\n\tfor await (const file of files) {\n\t\tconst subcommand = await importFile<SlashSubcommandData<typeof _parentType, true>>(file);\n\t\tif (\n\t\t\t!subcommand ||\n\t\t\t!validateCommand(subcommand, (subcmd) => subcmd.context === \"SlashSubcommand\")\n\t\t)\n\t\t\tcontinue;\n\n\t\tsubcommand.parent = data;\n\t\tdata.data.addSubcommand(subcommand.data);\n\n\t\tif (subcommands.has(subcommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] Subcommand '${subcommand.data.name}' under ${data.context} '${data.data.name}' has a duplicate and has been overridden`\n\t\t\t);\n\t\tsubcommands.set(subcommand.data.name, subcommand);\n\t}\n\n\tif (subcommands.size > 0) data.subcommands = subcommands;\n\treturn subcommands;\n}\n\nasync function parseSlashCommand(\n\tfile: string,\n\tparentDir: string,\n\tsubdirectories: Dirent<string>[]\n) {\n\tif (!existsSync(file)) return;\n\n\tconst command = await importFile<SlashCommandData>(file);\n\tif (\n\t\t!command ||\n\t\t!validateCommand(command, (cmd) => cmd.context === \"SlashCommand\") ||\n\t\t!(\"addSubcommand\" in command.data)\n\t)\n\t\treturn;\n\n\tawait parseSlashSubcommands(parentDir, command);\n\n\tfor (const subdir of subdirectories) {\n\t\tconst indexFile = path.resolve(subdir.parentPath, subdir.name, \"index.js\");\n\t\tif (!existsSync(indexFile)) continue;\n\n\t\tconst group = await importFile<SlashSubcommandGroupData<true>>(indexFile);\n\t\tif (\n\t\t\t!group ||\n\t\t\t!(\"context\" in group && \"addSubcommandGroup\" in command.data) ||\n\t\t\tgroup.context !== \"SlashSubcommandGroup\"\n\t\t)\n\t\t\tcontinue;\n\n\t\tgroup.parent = command;\n\t\tif (!command.subcommandGroups) command.subcommandGroups = new Collection();\n\t\tawait parseSlashSubcommands(join(subdir.parentPath, subdir.name), group);\n\n\t\tif (group.subcommands.size > 0) {\n\t\t\tif (command.subcommandGroups.has(group.data.name))\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[Trivious] SubcommandGroup '${group.data.name}' under SlashCommand '${command.data.name}' has a duplicate and has been overridden`\n\t\t\t\t);\n\n\t\t\tcommand.data.addSubcommandGroup(group.data);\n\t\t\tcommand.subcommandGroups.set(group.data.name, group);\n\t\t}\n\t}\n\n\treturn command;\n}\n\nasync function parseContextCommands(parentDir: string) {\n\tconst collection = new Collection<string, ContextCommandData>();\n\tconst files = fs.glob(join(parentDir, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst contextCommand = await importFile<ContextCommandData>(file);\n\t\tif (\n\t\t\t!contextCommand ||\n\t\t\t!validateCommand(\n\t\t\t\tcontextCommand,\n\t\t\t\t(cmd) =>\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.Message ||\n\t\t\t\t\tcmd.commandType === ApplicationCommandType.User\n\t\t\t)\n\t\t)\n\t\t\tcontinue;\n\n\t\tcontextCommand.data.setType(contextCommand.commandType);\n\t\tcollection.set(contextCommand.data.name, contextCommand);\n\t}\n\n\treturn collection;\n}\n\nasync function registerDirectory(client: TriviousClient, parentDir: string) {\n\tconst entries = await fs.readdir(parentDir, { withFileTypes: true });\n\tconst subdirectories = entries.filter((entry) => entry.isDirectory());\n\n\tconst indexFile = path.resolve(parentDir, \"index.js\");\n\tconst slashCommand = await parseSlashCommand(indexFile, parentDir, subdirectories);\n\tif (slashCommand) {\n\t\tif (client.stores.commands.chatInput.has(slashCommand.data.name))\n\t\t\tconsole.warn(\n\t\t\t\t`[Trivious] SlashCommand '${slashCommand.data.name}' has a duplicate and has been overridden`\n\t\t\t);\n\n\t\tclient.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);\n\t}\n\n\tconst contextCommands = await parseContextCommands(parentDir);\n\tcontextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));\n}\n\nexport default async function registerCommands(client: TriviousClient, directory: string) {\n\tif (!existsSync(directory))\n\t\tthrow new TriviousError(\n\t\t\t`Could not register commands; passed directory '${directory}' does not exist!`,\n\t\t\t\"Nonexistant directory passed\"\n\t\t);\n\n\tconst processedDirectories = new Set<string>();\n\n\tconst files = fs.glob(join(directory, \"**/*.js\"));\n\tfor await (const file of files) {\n\t\tconst parentDir = path.dirname(file);\n\n\t\tif (processedDirectories.has(parentDir)) continue;\n\t\tprocessedDirectories.add(parentDir);\n\n\t\tawait registerDirectory(client, parentDir);\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import 'discord.js';
2
- export { e as Component, f as ComponentContext, g as ComponentFlags, h as ComponentInteraction } from '../../modules.types-BUvtZD_e.js';
2
+ export { d as Component, e as ComponentContext, f as ComponentFlags, g as ComponentInteraction } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../permissions/permissions.types.js';
4
4
  import '../client/client.types.js';
@@ -1,4 +1,4 @@
1
- import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../commands.types-lx3T1lsC.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
1
  import '../client/client.types.js';
2
- import { f as ComponentContext } from '../../modules.types-BUvtZD_e.js';
2
+ import { e as ComponentContext } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../permissions/permissions.types.js';
4
4
  import 'discord.js';
5
5
 
@@ -1,7 +1,7 @@
1
1
  import { ComponentCustomId } from './customid.types.js';
2
2
  import '../client/client.types.js';
3
3
  import 'discord.js';
4
- import '../../modules.types-BUvtZD_e.js';
4
+ import '../../commands.types-lx3T1lsC.js';
5
5
  import '../permissions/permissions.types.js';
6
6
 
7
7
  declare const customId: {
@@ -1,4 +1,4 @@
1
1
  import 'discord.js';
2
- export { E as Event } from '../../modules.types-BUvtZD_e.js';
2
+ export { E as Event } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../client/client.types.js';
4
4
  import '../permissions/permissions.types.js';
@@ -1,4 +1,4 @@
1
- import { T as TriviousClient } from '../../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../../commands.types-lx3T1lsC.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
1
  import * as discord_js from 'discord.js';
2
- import { T as TriviousClient } from '../../../modules.types-BUvtZD_e.js';
2
+ import { T as TriviousClient } from '../../../commands.types-lx3T1lsC.js';
3
3
  import '../../client/client.types.js';
4
4
  import '../../permissions/permissions.types.js';
5
5
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"names":["subcommand"],"mappings":";;;;;;AAwBA,SAAS,sCAAA,CACR,MAAA,EACA,OAAA,EACA,WAAA,EAIU;AACV,EAAA,IAAI,EAAE,aAAA,IAAiB,OAAA,CAAA,EAAU,OAAO,KAAA;AACxC,EAAA,IAAI,CAAC,WAAA,CAAY,kBAAA,EAAmB,EAAG,OAAO,KAAA;AAE9C,EAAA,MAAM,EAAE,SAAQ,GAAI,WAAA;AAEpB,EAAA,MAAM,cAAA,GAAiB,OAAA,CAAQ,aAAA,CAAc,KAAK,CAAA;AAClD,EAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,kBAAA,CAAmB,KAAK,CAAA;AAClD,EAAA,IAAI,CAAC,gBAAgB,OAAO,KAAA;AAE5B,EAAA,IAAI,SAAA,EAAW;AACd,I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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;AAAA,QACrB,MAAA;AAAA,QACA,SAAA;AAAA,QACA,WAAA,CAAY;AAAA,OACb;AACA,MAAA,IAAI,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 {\n\tBaseContextCommandData,\n\tComponentContext,\n\tSlashCommandData,\n\tTriviousClient,\n\ttype ContextCommandData,\n\ttype Event,\n} from \"#typings\";\nimport {\n\tApplicationCommandType,\n\tButtonInteraction,\n\tChatInputCommandInteraction,\n\tGuildMember,\n\tMessageContextMenuCommandInteraction,\n\tModalSubmitInteraction,\n\tUserContextMenuCommandInteraction,\n} from \"discord.js\";\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\n/**\n * Check if the command is a subcommand and validate whether the member can run the command based on subcommand permissions\n */\nfunction validateMemberPermissionsForSubcommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData | BaseContextCommandData,\n\tinteraction:\n\t\t| ChatInputCommandInteraction\n\t\t| MessageContextMenuCommandInteraction\n\t\t| UserContextMenuCommandInteraction\n): boolean {\n\tif (!(\"subcommands\" in command)) return false;\n\tif (!interaction.isChatInputCommand()) return false;\n\n\tconst { options } = interaction;\n\n\tconst subcommandName = options.getSubcommand(false);\n\tconst groupName = options.getSubcommandGroup(false);\n\tif (!subcommandName) return false;\n\n\tif (groupName) {\n\t\tconst group = command.subcommandGroups?.get(groupName);\n\t\tif (!group) return false;\n\n\t\tconst subcommand = group.subcommands.get(subcommandName);\n\t\tif (!subcommand) return false;\n\n\t\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember)[0];\n\t}\n\n\tconst subcommand = command.subcommands?.get(subcommandName);\n\tif (!subcommand) return false;\n\n\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember)[0];\n}\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 =\n\t\t\t\tvalidateMemberPermissionsForSubcommand(client, command, interaction) ||\n\t\t\t\tcanMemberRunCommand(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
+ {"version":3,"sources":["../../../../src/features/events/presets/interactionCreate.ts"],"names":["subcommand"],"mappings":";;;;;;AAuBA,SAAS,sCAAA,CACR,MAAA,EACA,OAAA,EACA,WAAA,EAIU;AACV,EAAA,IAAI,EAAE,aAAA,IAAiB,OAAA,CAAA,EAAU,OAAO,KAAA;AACxC,EAAA,IAAI,CAAC,WAAA,CAAY,kBAAA,EAAmB,EAAG,OAAO,KAAA;AAE9C,EAAA,MAAM,EAAE,SAAQ,GAAI,WAAA;AAEpB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IAAI,IAAA,IAAQ,IAAA,CAAK,QAAA,CAAS,SAAS,CAAA,EAAG;AAEtC,MAAA,MAAM,SAAA,GAAY,MAAA,CAAO,MAAA,CAAO,UAAA,CAAW,IAAI,UAAU,CAAA;AAEzD,MAAA,IAAI,CAAC,SAAA,EAAW;AACf,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;AAAA,QACrB,MAAA;AAAA,QACA,SAAA;AAAA,QACA,WAAA,CAAY;AAAA,OACb;AACA,MAAA,IAAI,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 {\n\tComponentContext,\n\tSlashCommandData,\n\tTriviousClient,\n\ttype ContextCommandData,\n\ttype Event,\n} from \"#typings\";\nimport {\n\tApplicationCommandType,\n\tButtonInteraction,\n\tChatInputCommandInteraction,\n\tGuildMember,\n\tMessageContextMenuCommandInteraction,\n\tModalSubmitInteraction,\n\tUserContextMenuCommandInteraction,\n} from \"discord.js\";\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\n/**\n * Check if the command is a subcommand and validate whether the member can run the command based on subcommand permissions\n */\nfunction validateMemberPermissionsForSubcommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData | ContextCommandData,\n\tinteraction:\n\t\t| ChatInputCommandInteraction\n\t\t| MessageContextMenuCommandInteraction\n\t\t| UserContextMenuCommandInteraction\n): boolean {\n\tif (!(\"subcommands\" in command)) return false;\n\tif (!interaction.isChatInputCommand()) return false;\n\n\tconst { options } = interaction;\n\n\tconst subcommandName = options.getSubcommand(false);\n\tconst groupName = options.getSubcommandGroup(false);\n\tif (!subcommandName) return false;\n\n\tif (groupName) {\n\t\tconst group = command.subcommandGroups?.get(groupName);\n\t\tif (!group) return false;\n\n\t\tconst subcommand = group.subcommands.get(subcommandName);\n\t\tif (!subcommand) return false;\n\n\t\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember)[0];\n\t}\n\n\tconst subcommand = command.subcommands?.get(subcommandName);\n\tif (!subcommand) return false;\n\n\treturn canMemberRunCommand(client, subcommand, interaction.member as GuildMember)[0];\n}\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 =\n\t\t\t\tvalidateMemberPermissionsForSubcommand(client, command, interaction) ||\n\t\t\t\tcanMemberRunCommand(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,4 +1,4 @@
1
- import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../commands.types-lx3T1lsC.js';
2
2
  import 'discord.js';
3
3
  import '../client/client.types.js';
4
4
  import '../permissions/permissions.types.js';
@@ -1,4 +1,4 @@
1
1
  import 'discord.js';
2
- export { j as Module } from '../../modules.types-BUvtZD_e.js';
2
+ export { M as Module } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../client/client.types.js';
4
4
  import '../permissions/permissions.types.js';
@@ -1,4 +1,4 @@
1
- import { T as TriviousClient } from '../../modules.types-BUvtZD_e.js';
1
+ import { T as TriviousClient } from '../../commands.types-lx3T1lsC.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
1
  import { GuildMember, User } from 'discord.js';
2
- import { T as TriviousClient, a as BaseCommandData, e as Component } from '../../modules.types-BUvtZD_e.js';
2
+ import { T as TriviousClient, a as BaseCommandData, d as Component } from '../../commands.types-lx3T1lsC.js';
3
3
  import '../client/client.types.js';
4
4
  import './permissions.types.js';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { createActionRow, createEmbed } from './features/builders/utility.builders.js';
2
+ export { createMessageComponentCommand, createSlashCommand, createSubcommand, createSubcommandGroup, createUserComponentCommand } from './features/commands/builders.commands.js';
2
3
  export { handleSlashCommand, interactionReply } from './features/commands/methods.commands.js';
3
4
  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-BUvtZD_e.js';
5
+ export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CommandFlags, c as CommandFunction, d as Component, e as ComponentContext, f as ComponentFlags, g as ComponentInteraction, h as ContextCommandData, E as Event, M as Module, S as SlashCommandData, i as SlashSubcommandData, j as SlashSubcommandGroupData, T as TriviousClient } from './commands.types-lx3T1lsC.js';
5
6
  export { ComponentCustomId, ComponentTag } from './features/customId/customid.types.js';
6
7
  export { CommandPermissionValues } from './features/permissions/permissions.types.js';
7
8
  import 'discord.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './features/builders/utility.builders.js';
2
+ export * from './features/commands/builders.commands.js';
2
3
  export * from './features/commands/methods.commands.js';
3
4
  export * from './features/customId/methods.customid.js';
4
5
  export * from './shared/typings.js';
@@ -2,7 +2,7 @@ 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-BUvtZD_e.js';
5
+ import '../commands.types-lx3T1lsC.js';
6
6
  import 'discord.js';
7
7
  import '../features/client/client.types.js';
8
8
  import '../features/permissions/permissions.types.js';
@@ -1,5 +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-BUvtZD_e.js';
2
+ export { B as BaseChatInputCommandData, a as BaseCommandData, C as ChatInputCommandContext, b as CommandFlags, c as CommandFunction, d as Component, e as ComponentContext, f as ComponentFlags, g as ComponentInteraction, h as ContextCommandData, E as Event, M as Module, S as SlashCommandData, i as SlashSubcommandData, j as SlashSubcommandGroupData, T as TriviousClient } from '../commands.types-lx3T1lsC.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';
@@ -1,4 +1,4 @@
1
- import { a as BaseCommandData, S as SlashCommandData } from '../modules.types-BUvtZD_e.js';
1
+ import { a as BaseCommandData, S as SlashCommandData } from '../commands.types-lx3T1lsC.js';
2
2
  import 'discord.js';
3
3
  import '../features/client/client.types.js';
4
4
  import '../features/permissions/permissions.types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trivious",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "discord-bot",