trivious 1.6.18 → 2.0.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.
Files changed (128) hide show
  1. package/README.md +53 -66
  2. package/dist/{core/builders/util.builders.d.ts → features/builders/utility.builders.d.ts} +0 -9
  3. package/dist/{core/builders/util.builders.js → features/builders/utility.builders.js} +2 -2
  4. package/dist/features/builders/utility.builders.js.map +1 -0
  5. package/dist/features/client/client.types.d.ts +85 -0
  6. package/dist/features/client/client.types.js +3 -0
  7. package/dist/{shared/typings/client.js.map → features/client/client.types.js.map} +1 -1
  8. package/dist/features/client/deploy.client.d.ts +7 -0
  9. package/dist/features/client/deploy.client.js +43 -0
  10. package/dist/features/client/deploy.client.js.map +1 -0
  11. package/dist/features/client/trivious.client.d.ts +3 -0
  12. package/dist/features/client/trivious.client.js +62 -0
  13. package/dist/features/client/trivious.client.js.map +1 -0
  14. package/dist/features/commands/commands.types.d.ts +3 -0
  15. package/dist/features/commands/commands.types.js +3 -0
  16. package/dist/{shared/typings/commands.js.map → features/commands/commands.types.js.map} +1 -1
  17. package/dist/features/commands/methods.commands.d.ts +13 -0
  18. package/dist/features/commands/methods.commands.js +70 -0
  19. package/dist/features/commands/methods.commands.js.map +1 -0
  20. package/dist/features/commands/registry.commands.d.ts +7 -0
  21. package/dist/features/commands/registry.commands.js +84 -0
  22. package/dist/features/commands/registry.commands.js.map +1 -0
  23. package/dist/features/components/components.types.d.ts +3 -0
  24. package/dist/features/components/components.types.js +10 -0
  25. package/dist/features/components/components.types.js.map +1 -0
  26. package/dist/features/components/registry.components.d.ts +7 -0
  27. package/dist/features/components/registry.components.js +23 -0
  28. package/dist/features/components/registry.components.js.map +1 -0
  29. package/dist/features/customId/customid.types.d.ts +13 -0
  30. package/dist/features/customId/customid.types.js +3 -0
  31. package/dist/features/customId/customid.types.js.map +1 -0
  32. package/dist/features/customId/methods.customid.d.ts +20 -0
  33. package/dist/features/customId/methods.customid.js +24 -0
  34. package/dist/features/customId/methods.customid.js.map +1 -0
  35. package/dist/features/events/events.types.d.ts +3 -0
  36. package/dist/features/events/events.types.js +3 -0
  37. package/dist/{shared/typings/events.js.map → features/events/events.types.js.map} +1 -1
  38. package/dist/features/events/presets/clientReady.d.ts +11 -0
  39. package/dist/{core/events → features/events/presets}/clientReady.js +1 -1
  40. package/dist/features/events/presets/clientReady.js.map +1 -0
  41. package/dist/features/events/presets/interactionCreate.d.ts +10 -0
  42. package/dist/features/events/presets/interactionCreate.js +49 -0
  43. package/dist/features/events/presets/interactionCreate.js.map +1 -0
  44. package/dist/features/events/registry.events.d.ts +8 -0
  45. package/dist/features/events/registry.events.js +45 -0
  46. package/dist/features/events/registry.events.js.map +1 -0
  47. package/dist/features/modules/modules.types.d.ts +3 -0
  48. package/dist/features/modules/modules.types.js +3 -0
  49. package/dist/{shared/typings/module.js.map → features/modules/modules.types.js.map} +1 -1
  50. package/dist/features/modules/registry.modules.d.ts +8 -0
  51. package/dist/features/modules/registry.modules.js +30 -0
  52. package/dist/features/modules/registry.modules.js.map +1 -0
  53. package/dist/features/structure/index.structure.d.ts +10 -0
  54. package/dist/features/structure/index.structure.js +51 -0
  55. package/dist/features/structure/index.structure.js.map +1 -0
  56. package/dist/index.d.ts +6 -5
  57. package/dist/index.js +4 -10
  58. package/dist/modules.types-Bn4HfuVk.d.ts +165 -0
  59. package/dist/shared/registries.d.ts +26 -0
  60. package/dist/shared/registries.js +25 -0
  61. package/dist/shared/registries.js.map +1 -0
  62. package/dist/shared/typings.d.ts +4 -0
  63. package/dist/shared/typings.js +9 -0
  64. package/dist/shared/typings.js.map +1 -0
  65. package/dist/utility/errors.d.ts +15 -0
  66. package/dist/utility/errors.js +24 -0
  67. package/dist/utility/errors.js.map +1 -0
  68. package/dist/utility/functions.d.ts +4 -0
  69. package/dist/utility/functions.js +32 -0
  70. package/dist/utility/functions.js.map +1 -0
  71. package/package.json +7 -3
  72. package/dist/core/builders/util.builders.js.map +0 -1
  73. package/dist/core/client/trivious.client.d.ts +0 -6
  74. package/dist/core/client/trivious.client.js +0 -115
  75. package/dist/core/client/trivious.client.js.map +0 -1
  76. package/dist/core/commands/methods.command.d.ts +0 -6
  77. package/dist/core/commands/methods.command.js +0 -90
  78. package/dist/core/commands/methods.command.js.map +0 -1
  79. package/dist/core/events/clientReady.d.ts +0 -14
  80. package/dist/core/events/clientReady.js.map +0 -1
  81. package/dist/core/events/interactionCreate.d.ts +0 -14
  82. package/dist/core/events/interactionCreate.js +0 -84
  83. package/dist/core/events/interactionCreate.js.map +0 -1
  84. package/dist/core/registry/command.registry.d.ts +0 -6
  85. package/dist/core/registry/command.registry.js +0 -54
  86. package/dist/core/registry/command.registry.js.map +0 -1
  87. package/dist/core/registry/component.registry.d.ts +0 -6
  88. package/dist/core/registry/component.registry.js +0 -41
  89. package/dist/core/registry/component.registry.js.map +0 -1
  90. package/dist/core/registry/event.registry.d.ts +0 -6
  91. package/dist/core/registry/event.registry.js +0 -71
  92. package/dist/core/registry/event.registry.js.map +0 -1
  93. package/dist/core/registry/index.d.ts +0 -22
  94. package/dist/core/registry/index.js +0 -39
  95. package/dist/core/registry/index.js.map +0 -1
  96. package/dist/core/registry/module.registry.d.ts +0 -6
  97. package/dist/core/registry/module.registry.js +0 -55
  98. package/dist/core/registry/module.registry.js.map +0 -1
  99. package/dist/index-DbWA_10I.d.ts +0 -439
  100. package/dist/shared/typings/client.d.ts +0 -74
  101. package/dist/shared/typings/client.js +0 -3
  102. package/dist/shared/typings/commands.d.ts +0 -6
  103. package/dist/shared/typings/commands.js +0 -3
  104. package/dist/shared/typings/components.d.ts +0 -6
  105. package/dist/shared/typings/components.js +0 -10
  106. package/dist/shared/typings/components.js.map +0 -1
  107. package/dist/shared/typings/events.d.ts +0 -6
  108. package/dist/shared/typings/events.js +0 -3
  109. package/dist/shared/typings/index.d.ts +0 -6
  110. package/dist/shared/typings/index.js +0 -9
  111. package/dist/shared/typings/index.js.map +0 -1
  112. package/dist/shared/typings/module.d.ts +0 -6
  113. package/dist/shared/typings/module.js +0 -3
  114. package/dist/shared/typings/permissions.d.ts +0 -16
  115. package/dist/shared/typings/permissions.js +0 -13
  116. package/dist/shared/typings/permissions.js.map +0 -1
  117. package/dist/shared/typings/registry.d.ts +0 -51
  118. package/dist/shared/typings/registry.js +0 -61
  119. package/dist/shared/typings/registry.js.map +0 -1
  120. package/dist/shared/utility/components.utility.d.ts +0 -6
  121. package/dist/shared/utility/components.utility.js +0 -17
  122. package/dist/shared/utility/components.utility.js.map +0 -1
  123. package/dist/shared/utility/functions.d.ts +0 -60
  124. package/dist/shared/utility/functions.js +0 -81
  125. package/dist/shared/utility/functions.js.map +0 -1
  126. package/dist/shared/utility/permissions.utility.d.ts +0 -6
  127. package/dist/shared/utility/permissions.utility.js +0 -12
  128. package/dist/shared/utility/permissions.utility.js.map +0 -1
@@ -0,0 +1,165 @@
1
+ import { Client, Collection, ApplicationCommandType, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandSubcommandBuilder, ChatInputCommandInteraction, SlashCommandSubcommandGroupBuilder, ContextMenuCommandInteraction, ContextMenuCommandBuilder, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AnySelectMenuInteraction, ButtonInteraction, ModalSubmitInteraction, ClientEvents } from 'discord.js';
2
+ import { TriviousClientOptions } from './features/client/client.types.js';
3
+
4
+ declare class TriviousClient extends Client {
5
+ trivious: TriviousClientOptions;
6
+ readonly stores: {
7
+ commands: {
8
+ chatInput: Collection<string, SlashCommandData>;
9
+ context: Collection<string, BaseContextCommandData>;
10
+ };
11
+ components: Collection<string, Component>;
12
+ events: Collection<string, Event>;
13
+ modules: Collection<string, Module>;
14
+ };
15
+ constructor(options: TriviousClientOptions);
16
+ /**
17
+ * Register, deploy and log into the bot.
18
+ *
19
+ * @throws {TriviousError} If invalid bot token
20
+ */
21
+ start(): Promise<void>;
22
+ register(): Promise<void>;
23
+ deploy(): Promise<void>;
24
+ }
25
+
26
+ type ChatInputCommandContext = "SlashCommand" | "SlashSubcommand" | "SlashSubcommandGroup";
27
+ type CommandFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
28
+ type ChatInputCommandFunction = (client: TriviousClient, interaction: ChatInputCommandInteraction) => Promise<void>;
29
+ type ContextMenuCommandFunction<T extends ContextMenuCommandInteraction> = (client: TriviousClient, interaction: T) => Promise<void>;
30
+ /**
31
+ * Base Trivious command data
32
+ *
33
+ * @param context The command context
34
+ * @param commandType ApplicationCommandType
35
+ * @param active Whether or not to register and recognise the command
36
+ * @param flags Command behaviour modifiers
37
+ */
38
+ interface BaseCommandData {
39
+ active: boolean;
40
+ flags?: CommandFlags[];
41
+ }
42
+ /**
43
+ * Base Trivious chat input command data
44
+ *
45
+ * @param context The chat input command context
46
+ * @param commandType ApplicationCommandType.ChatInput
47
+ */
48
+ interface BaseChatInputCommandData extends BaseCommandData {
49
+ context: ChatInputCommandContext;
50
+ commandType: ApplicationCommandType.ChatInput;
51
+ }
52
+ /**
53
+ * Base Trivious context command data
54
+ *
55
+ * @param commandType ApplicationCommandType.Message | ApplicationCommandType.User
56
+ */
57
+ interface BaseContextCommandData extends BaseCommandData {
58
+ commandType: ApplicationCommandType.Message | ApplicationCommandType.User;
59
+ }
60
+ /**
61
+ * Trivious slash command data
62
+ *
63
+ * @param context SlashCommand
64
+ * @param commandType ApplicationCommandType.ChatInput
65
+ * @param data The slash command builder
66
+ * @param subcommands Collection of Subcommands, cannot co-exist with `subcommandGroups`
67
+ * @param subcommandGroups Collection of subcommand Groups, cannot co-exist with `subcommands`
68
+ * @param run Function for when the command is executed, not required if the command has subcommands or subcommand groups unless you intend to have extra behaviour
69
+ */
70
+ interface SlashCommandData extends BaseChatInputCommandData {
71
+ context: "SlashCommand";
72
+ data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
73
+ subcommands?: Collection<string, SlashSubcommandData<true, "command">>;
74
+ subcommandGroups?: Collection<string, SlashSubcommandGroupData<true>>;
75
+ run?: ChatInputCommandFunction;
76
+ }
77
+ /**
78
+ * Trivious slash subcommand group data
79
+ *
80
+ * @param data The slash subcommand group builder
81
+ * @param subcommands Collection of Subcommands
82
+ */
83
+ interface SlashSubcommandGroupData<Processed extends boolean = false> {
84
+ context: "SlashSubcommandGroup";
85
+ data: SlashCommandSubcommandGroupBuilder;
86
+ subcommands: Collection<string, SlashSubcommandData<boolean, "group">>;
87
+ parent?: Processed extends true ? SlashCommandData : SlashCommandData | undefined;
88
+ }
89
+ /**
90
+ * Trivious slash subcommand data
91
+ *
92
+ * @param context SlashSubcommand
93
+ * @param commandType ApplicationCommandType.ChatInput
94
+ * @param data The slash subcommand builder
95
+ * @param execute Function for when the subcommand is executed
96
+ */
97
+ interface SlashSubcommandData<Processed extends boolean = false, Parent extends "command" | "group" = "command"> extends BaseChatInputCommandData {
98
+ context: "SlashSubcommand";
99
+ data: SlashCommandSubcommandBuilder;
100
+ execute: ChatInputCommandFunction;
101
+ parent?: Processed extends true ? Parent extends "command" ? SlashCommandData : SlashSubcommandGroupData<true> : Parent extends "command" ? SlashCommandData | undefined : SlashSubcommandGroupData<false> | undefined;
102
+ }
103
+ /**
104
+ * Trivious message command data
105
+ *
106
+ * @param context MessageContextCommand
107
+ * @param commandType ApplicationCommandType.Message
108
+ * @param data The context menu builder
109
+ * @param execute Function for when the message command is executed
110
+ */
111
+ interface MessageCommandData extends BaseContextCommandData {
112
+ commandType: ApplicationCommandType.Message;
113
+ data: ContextMenuCommandBuilder;
114
+ execute: ContextMenuCommandFunction<MessageContextMenuCommandInteraction>;
115
+ }
116
+ /**
117
+ * Trivious user command data
118
+ *
119
+ * @param context UserContextCommand
120
+ * @param commandType ApplicationCommandType.User
121
+ * @param data The context menu builder
122
+ * @param execute Function for when the user command is executed
123
+ */
124
+ interface UserCommandData extends BaseContextCommandData {
125
+ commandType: ApplicationCommandType.User;
126
+ data: ContextMenuCommandBuilder;
127
+ execute: ContextMenuCommandFunction<UserContextMenuCommandInteraction>;
128
+ }
129
+ type ContextCommandData = MessageCommandData | UserCommandData;
130
+
131
+ type ComponentFlags = "Cached" | "DeferReply" | "EphemeralReply" | "ExpectModal";
132
+ type ComponentInteraction = AnySelectMenuInteraction | ButtonInteraction | ModalSubmitInteraction;
133
+ declare enum ComponentContext {
134
+ Button = 0,
135
+ SelectMenu = 1,
136
+ Modal = 2
137
+ }
138
+ /**
139
+ * Trivious component
140
+ * @param component The component type
141
+ * @param identifier The unique identifier inside the custom id
142
+ * @param flags The component flags
143
+ * @param execute Component handler
144
+ */
145
+ interface Component {
146
+ component: ComponentContext;
147
+ identifier: string;
148
+ flags?: ComponentFlags[];
149
+ execute: (client: TriviousClient, interaction: ComponentInteraction) => Promise<void>;
150
+ }
151
+
152
+ interface Event<K extends keyof ClientEvents = keyof ClientEvents> {
153
+ name: K;
154
+ once?: boolean;
155
+ execute: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void> | void;
156
+ }
157
+
158
+ interface Module {
159
+ name: string;
160
+ events: {
161
+ [K in keyof ClientEvents]?: (client: TriviousClient, ...args: ClientEvents[K]) => Promise<void>;
162
+ };
163
+ }
164
+
165
+ export { type BaseCommandData 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 CommandFlags as a, type ChatInputCommandFunction as b, type ContextMenuCommandFunction as c, type BaseChatInputCommandData as d, type BaseContextCommandData as e, type SlashSubcommandGroupData as f, type SlashSubcommandData as g, type ContextCommandData as h, type ComponentFlags as i, type ComponentInteraction as j, ComponentContext as k, type Component as l, type Module as m };
@@ -0,0 +1,26 @@
1
+ import registerCommands from '../features/commands/registry.commands.js';
2
+ import registerComponents from '../features/components/registry.components.js';
3
+ import registerEvents, { bindEvents } from '../features/events/registry.events.js';
4
+ import registerModules, { bindModules } from '../features/modules/registry.modules.js';
5
+ import '../modules.types-Bn4HfuVk.js';
6
+ import 'discord.js';
7
+ import '../features/client/client.types.js';
8
+
9
+ declare const _default: {
10
+ readonly commands: {
11
+ readonly register: typeof registerCommands;
12
+ };
13
+ readonly components: {
14
+ readonly register: typeof registerComponents;
15
+ };
16
+ readonly events: {
17
+ readonly register: typeof registerEvents;
18
+ readonly bind: typeof bindEvents;
19
+ };
20
+ readonly modules: {
21
+ readonly register: typeof registerModules;
22
+ readonly bind: typeof bindModules;
23
+ };
24
+ };
25
+
26
+ export { _default as default };
@@ -0,0 +1,25 @@
1
+ import registerCommands from '../features/commands/registry.commands.js';
2
+ import registerComponents from '../features/components/registry.components.js';
3
+ import registerEvents, { bindEvents } from '../features/events/registry.events.js';
4
+ import registerModules, { bindModules } from '../features/modules/registry.modules.js';
5
+
6
+ var registries_default = {
7
+ commands: {
8
+ register: registerCommands
9
+ },
10
+ components: {
11
+ register: registerComponents
12
+ },
13
+ events: {
14
+ register: registerEvents,
15
+ bind: bindEvents
16
+ },
17
+ modules: {
18
+ register: registerModules,
19
+ bind: bindModules
20
+ }
21
+ };
22
+
23
+ export { registries_default as default };
24
+ //# sourceMappingURL=registries.js.map
25
+ //# sourceMappingURL=registries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/shared/registries.ts"],"names":[],"mappings":";;;;;AAKA,IAAO,kBAAA,GAAQ;AAAA,EACd,QAAA,EAAU;AAAA,IACT,QAAA,EAAU;AAAA,GACX;AAAA,EACA,UAAA,EAAY;AAAA,IACX,QAAA,EAAU;AAAA,GACX;AAAA,EACA,MAAA,EAAQ;AAAA,IACP,QAAA,EAAU,cAAA;AAAA,IACV,IAAA,EAAM;AAAA,GACP;AAAA,EACA,OAAA,EAAS;AAAA,IACR,QAAA,EAAU,eAAA;AAAA,IACV,IAAA,EAAM;AAAA;AAER","file":"registries.js","sourcesContent":["import registerCommands from \"src/features/commands/registry.commands.js\";\nimport registerComponents from \"src/features/components/registry.components.js\";\nimport registerEvents, { bindEvents } from \"src/features/events/registry.events.js\";\nimport registerModules, { bindModules } from \"src/features/modules/registry.modules.js\";\n\nexport default {\n\tcommands: {\n\t\tregister: registerCommands,\n\t},\n\tcomponents: {\n\t\tregister: registerComponents,\n\t},\n\tevents: {\n\t\tregister: registerEvents,\n\t\tbind: bindEvents,\n\t},\n\tmodules: {\n\t\tregister: registerModules,\n\t\tbind: bindModules,\n\t},\n} as const;\n"]}
@@ -0,0 +1,4 @@
1
+ export { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure } from '../features/client/client.types.js';
2
+ export { d as BaseChatInputCommandData, B as BaseCommandData, e as BaseContextCommandData, C as ChatInputCommandContext, b as ChatInputCommandFunction, a as CommandFlags, l as Component, k as ComponentContext, i as ComponentFlags, j as ComponentInteraction, h as ContextCommandData, c as ContextMenuCommandFunction, E as Event, M as MessageCommandData, m as Module, S as SlashCommandData, g as SlashSubcommandData, f as SlashSubcommandGroupData, T as TriviousClient, U as UserCommandData } from '../modules.types-Bn4HfuVk.js';
3
+ export { ComponentCustomId, ComponentTag } from '../features/customId/customid.types.js';
4
+ import 'discord.js';
@@ -0,0 +1,9 @@
1
+ export * from '../features/client/client.types.js';
2
+ export { default as TriviousClient } from '../features/client/trivious.client.js';
3
+ export * from '../features/commands/commands.types.js';
4
+ export * from '../features/components/components.types.js';
5
+ export * from '../features/customId/customid.types.js';
6
+ export * from '../features/events/events.types.js';
7
+ export * from '../features/modules/modules.types.js';
8
+ //# sourceMappingURL=typings.js.map
9
+ //# sourceMappingURL=typings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"typings.js","sourcesContent":[]}
@@ -0,0 +1,15 @@
1
+ import { B as BaseCommandData, S as SlashCommandData } from '../modules.types-Bn4HfuVk.js';
2
+ import 'discord.js';
3
+ import '../features/client/client.types.js';
4
+
5
+ declare class TriviousError extends Error {
6
+ readonly field?: string;
7
+ readonly cause?: string;
8
+ constructor(message: string, cause?: string);
9
+ }
10
+ declare class CommandError extends Error {
11
+ readonly commandName?: string;
12
+ constructor(message: string, command: Partial<BaseCommandData | SlashCommandData>);
13
+ }
14
+
15
+ export { CommandError, TriviousError };
@@ -0,0 +1,24 @@
1
+ class TriviousError extends Error {
2
+ field;
3
+ cause;
4
+ constructor(message, cause) {
5
+ message = `[Trivious] ${message}`;
6
+ super(message);
7
+ this.message = message;
8
+ this.cause = cause;
9
+ this.name = "TriviousError";
10
+ }
11
+ }
12
+ class CommandError extends Error {
13
+ commandName;
14
+ constructor(message, command) {
15
+ message = `[Trivious] ${message}`;
16
+ super(message);
17
+ this.name = "CommandError";
18
+ if ("data" in command) this.commandName = command.data?.name;
19
+ }
20
+ }
21
+
22
+ export { CommandError, TriviousError };
23
+ //# sourceMappingURL=errors.js.map
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utility/errors.ts"],"names":[],"mappings":"AAEO,MAAM,sBAAsB,KAAA,CAAM;AAAA,EAC/B,KAAA;AAAA,EACA,KAAA;AAAA,EAET,WAAA,CAAY,SAAiB,KAAA,EAAgB;AAC5C,IAAA,OAAA,GAAU,cAAc,OAAO,CAAA,CAAA;AAC/B,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AAAA,EACb;AACD;AAEO,MAAM,qBAAqB,KAAA,CAAM;AAAA,EAC9B,WAAA;AAAA,EAET,WAAA,CAAY,SAAiB,OAAA,EAAsD;AAClF,IAAA,OAAA,GAAU,cAAc,OAAO,CAAA,CAAA;AAC/B,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAEZ,IAAA,IAAI,MAAA,IAAU,OAAA,EAAS,IAAA,CAAK,WAAA,GAAc,QAAQ,IAAA,EAAM,IAAA;AAAA,EAGzD;AACD","file":"errors.js","sourcesContent":["import { BaseCommandData, SlashCommandData } from \"src/features/commands/commands.types.js\";\n\nexport class TriviousError extends Error {\n\treadonly field?: string;\n\treadonly cause?: string;\n\n\tconstructor(message: string, cause?: string) {\n\t\tmessage = `[Trivious] ${message}`;\n\t\tsuper(message);\n\n\t\tthis.message = message;\n\t\tthis.cause = cause;\n\t\tthis.name = \"TriviousError\";\n\t}\n}\n\nexport class CommandError extends Error {\n\treadonly commandName?: string;\n\n\tconstructor(message: string, command: Partial<BaseCommandData | SlashCommandData>) {\n\t\tmessage = `[Trivious] ${message}`;\n\t\tsuper(message);\n\n\t\tthis.name = \"CommandError\";\n\n\t\tif (\"data\" in command) this.commandName = command.data?.name;\n\t\t// if (this.commandContext && this.commandName)\n\t\t// \tthis.cause = `Error in ${this.commandContext} '${this.commandName}'`;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ declare function importFile<T>(filePath: string): Promise<T | null>;
2
+ declare function exists(path: string): Promise<boolean>;
3
+
4
+ export { exists, importFile };
@@ -0,0 +1,32 @@
1
+ import { promises } from 'fs';
2
+ import { pathToFileURL } from 'url';
3
+
4
+ async function importFile(filePath) {
5
+ try {
6
+ const { default: file } = await import(pathToFileURL(filePath).href);
7
+ if (!file) return null;
8
+ const imports = file.default || file;
9
+ if (typeof imports === "function" && imports.prototype) {
10
+ return new imports();
11
+ }
12
+ if (typeof imports == "object") {
13
+ if (Object.keys(imports).length === 0) return null;
14
+ return imports;
15
+ }
16
+ return null;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ async function exists(path) {
22
+ try {
23
+ await promises.access(path);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ export { exists, importFile };
31
+ //# sourceMappingURL=functions.js.map
32
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utility/functions.ts"],"names":["fs"],"mappings":";;;AAGA,eAAsB,WAAc,QAAA,EAAqC;AACxE,EAAA,IAAI;AACH,IAAA,MAAM,EAAE,SAAS,IAAA,EAAK,GAAI,MAAM,OAAO,aAAA,CAAc,QAAQ,CAAA,CAAE,IAAA,CAAA;AAC/D,IAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAElB,IAAA,MAAM,OAAA,GAAU,KAAK,OAAA,IAAW,IAAA;AAEhC,IAAA,IAAI,OAAO,OAAA,KAAY,UAAA,IAAc,OAAA,CAAQ,SAAA,EAAW;AACvD,MAAA,OAAO,IAAI,OAAA,EAAQ;AAAA,IACpB;AAEA,IAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC/B,MAAA,IAAI,OAAO,IAAA,CAAK,OAAO,CAAA,CAAE,MAAA,KAAW,GAAG,OAAO,IAAA;AAC9C,MAAA,OAAO,OAAA;AAAA,IACR;AAEA,IAAA,OAAO,IAAA;AAAA,EACR,CAAA,CAAA,MAAQ;AACP,IAAA,OAAO,IAAA;AAAA,EACR;AACD;AAEA,eAAsB,OAAO,IAAA,EAAc;AAC1C,EAAA,IAAI;AACH,IAAA,MAAMA,QAAA,CAAG,OAAO,IAAI,CAAA;AACpB,IAAA,OAAO,IAAA;AAAA,EACR,CAAA,CAAA,MAAQ;AACP,IAAA,OAAO,KAAA;AAAA,EACR;AACD","file":"functions.js","sourcesContent":["import { promises as fs } from \"fs\";\nimport { pathToFileURL } from \"url\";\n\nexport async function importFile<T>(filePath: string): Promise<T | null> {\n\ttry {\n\t\tconst { default: file } = await import(pathToFileURL(filePath).href);\n\t\tif (!file) return null;\n\n\t\tconst imports = file.default || file;\n\n\t\tif (typeof imports === \"function\" && imports.prototype) {\n\t\t\treturn new imports() as T;\n\t\t}\n\n\t\tif (typeof imports == \"object\") {\n\t\t\tif (Object.keys(imports).length === 0) return null;\n\t\t\treturn imports as T;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport async function exists(path: string) {\n\ttry {\n\t\tawait fs.access(path);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trivious",
3
- "version": "1.6.18",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "discord-bot",
@@ -51,23 +51,27 @@
51
51
  "prepare": "npm run build"
52
52
  },
53
53
  "devDependencies": {
54
+ "@eslint/js": "^9.39.1",
54
55
  "@semantic-release/changelog": "^6.0.3",
55
56
  "@semantic-release/git": "^10.0.1",
56
57
  "@semantic-release/github": "^12.0.2",
57
58
  "@semantic-release/npm": "^13.1.2",
58
59
  "@types/node": "^24.10.1",
59
- "@typescript-eslint/eslint-plugin": "^8.47.0",
60
- "@typescript-eslint/parser": "^8.47.0",
60
+ "@typescript-eslint/eslint-plugin": "^8.57.0",
61
+ "@typescript-eslint/parser": "^8.57.0",
61
62
  "@vitest/coverage-v8": "^4.0.13",
62
63
  "dotenv": "^17.2.3",
63
64
  "eslint": "^9.39.1",
64
65
  "eslint-config-prettier": "^10.1.8",
66
+ "eslint-plugin-import": "^2.32.0",
67
+ "eslint-plugin-prettier": "^5.5.5",
65
68
  "jsdoc": "^4.0.5",
66
69
  "prettier": "^3.6.2",
67
70
  "semantic-release": "^25.0.2",
68
71
  "tsc-alias": "^1.8.16",
69
72
  "tsup": "^8.5.1",
70
73
  "typescript": "^5.9.3",
74
+ "typescript-eslint": "^8.57.0",
71
75
  "vitest": "^4.0.13"
72
76
  },
73
77
  "dependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/core/builders/util.builders.ts"],"names":[],"mappings":";;AAgBO,SAAS,mBAA+D,QAAA,EAAe;AAC7F,EAAA,OAAO,IAAI,gBAAA,EAAoB,CAAE,aAAA,CAAc,GAAG,QAAQ,CAAA;AAC3D;AASO,SAAS,YAAY,IAAA,EAA6B;AACxD,EAAA,OAAO,IAAI,aAAa,IAAI,CAAA;AAC7B","file":"util.builders.js","sourcesContent":["import {\n\tActionRowBuilder,\n\tAPIEmbed,\n\tEmbedBuilder,\n\tEmbedData,\n\tMessageActionRowComponentBuilder,\n} from \"discord.js\";\n\n/**\n * Utility action row builder\n *\n * @export\n * @template {MessageActionRowComponentBuilder} T\n * @param {...T[]} builders\n * @returns {*}\n */\nexport function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]) {\n\treturn new ActionRowBuilder<T>().setComponents(...builders);\n}\n\n/**\n * Utility embed builder\n *\n * @export\n * @param {?(EmbedData | APIEmbed)} [data]\n * @returns {*}\n */\nexport function createEmbed(data?: EmbedData | APIEmbed) {\n\treturn new EmbedBuilder(data);\n}\n"]}
@@ -1,6 +0,0 @@
1
- export { T as default } from '../../index-DbWA_10I.js';
2
- import 'discord.js';
3
- import '../../shared/typings/permissions.js';
4
- import '../../shared/typings/client.js';
5
- import '../../shared/typings/registry.js';
6
- import '../builders/util.builders.js';
@@ -1,115 +0,0 @@
1
- import { Client, REST, Routes } from 'discord.js';
2
- import { registries } from '../registry/index.js';
3
- import { exists } from '../../shared/utility/functions.js';
4
- import path from 'node:path';
5
- import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
6
- import { createHash } from 'node:crypto';
7
-
8
- class TriviousClient extends Client {
9
- /**
10
- * Client registries.
11
- *
12
- * @public
13
- * @readonly
14
- * @type {*}
15
- */
16
- registries = registries();
17
- /**
18
- * Client copy of the constructor options.
19
- *
20
- * @private
21
- * @type {TriviousClientOptions}
22
- */
23
- _options;
24
- /**
25
- * Creates an instance of TriviousClient.
26
- *
27
- * @constructor
28
- * @param {TriviousClientOptions} options
29
- */
30
- constructor(options) {
31
- super(options);
32
- this._options = options;
33
- }
34
- /**
35
- * Load all registries.
36
- *
37
- * @async
38
- * @returns {*}
39
- */
40
- async register() {
41
- const { registries: registries2 } = this;
42
- await registries2.loadAll(this._options);
43
- console.log(
44
- `[Trivious] Loaded all registries (${registries2.commands.get().size} commands, ${registries2.events.get().size} events, ${registries2.components.get().size} components, ${registries2.modules.get().size} modules)`
45
- );
46
- }
47
- /**
48
- * Login and start the bot.
49
- *
50
- * @async
51
- * @returns {*}
52
- */
53
- async start() {
54
- if (!process.env[this._options.tokenReference]) {
55
- if (process.env.NODE_ENV !== "production") return;
56
- else throw new Error("[Trivious] Invalid token reference");
57
- }
58
- await this.register();
59
- await this.deploy();
60
- this.registries.bind(this);
61
- await this.login(process.env[this._options.tokenReference]);
62
- }
63
- /**
64
- * Deploy all commands.
65
- *
66
- * @async
67
- * @returns {*}
68
- */
69
- async deploy() {
70
- const { commandHashConfig } = this._options;
71
- const clientId = process.env[this._options.clientIdReference];
72
- const token = process.env[this._options.tokenReference];
73
- if (!clientId || !token) throw new Error("[Trivious] Invalid clientId or token reference");
74
- const commands = Array.from(this.registries.commands.get().values());
75
- const body = [
76
- ...commands.map(
77
- (command) => "data" in command ? command.data.toJSON() : null
78
- )
79
- ].filter((c) => c !== null);
80
- if (commandHashConfig && commandHashConfig.enabled) {
81
- const hashFile = path.join(commandHashConfig.filePath || "data", "commands.hash");
82
- const newHash = createHash("sha256").update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString()).digest("hex");
83
- let oldHash = "";
84
- if (await exists(hashFile)) oldHash = readFileSync(hashFile, "utf-8");
85
- if (newHash === oldHash) {
86
- console.debug(`[Trivious] No changes in commands found, skipping deployment`);
87
- return;
88
- }
89
- const hashDirectory = path.dirname(hashFile);
90
- if (!existsSync(hashDirectory)) {
91
- mkdirSync(hashDirectory, { recursive: true });
92
- }
93
- writeFileSync(hashFile, newHash, { encoding: "utf-8" });
94
- console.debug(`[Trivious] Created new command hash: ${hashFile}`);
95
- }
96
- const rest = new REST({ version: "10" }).setToken(token);
97
- await rest.put(Routes.applicationCommands(clientId), { body });
98
- console.log(`[Trivious] Deployed ${body.length} commands`);
99
- }
100
- /**
101
- * Set the roles tied to a permission level.
102
- *
103
- * @param {Record<string, PermissionLevel>} roles
104
- */
105
- setRolePermissions(roles) {
106
- this._options.rolePermissions = roles;
107
- }
108
- get rolePermissions() {
109
- return this._options.rolePermissions ?? {};
110
- }
111
- }
112
-
113
- export { TriviousClient as default };
114
- //# sourceMappingURL=trivious.client.js.map
115
- //# sourceMappingURL=trivious.client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/core/client/trivious.client.ts"],"names":["registries"],"mappings":";;;;;;;AAqBA,MAAO,uBAAqC,MAAA,CAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzC,aAAa,UAAA,EAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QAAA,GAAW;AAChB,IAAA,MAAM,EAAE,UAAA,EAAAA,WAAAA,EAAW,GAAI,IAAA;AACvB,IAAA,MAAMA,WAAAA,CAAW,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA;AACtC,IAAA,OAAA,CAAQ,GAAA;AAAA,MACP,CAAA,kCAAA,EAAqCA,YAAW,QAAA,CAAS,GAAA,GAAM,IAAI,CAAA,WAAA,EAAcA,WAAAA,CAAW,MAAA,CAAO,GAAA,EAAI,CAAE,IAAI,CAAA,SAAA,EAAYA,WAAAA,CAAW,UAAA,CAAW,GAAA,EAAI,CAAE,IAAI,gBAAgBA,WAAAA,CAAW,OAAA,CAAQ,GAAA,EAAI,CAAE,IAAI,CAAA,SAAA;AAAA,KACvM;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,KAAA,GAAQ;AACb,IAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,IAAA,CAAK,QAAA,CAAS,cAAc,CAAA,EAAG;AAC/C,MAAA,IAAI,OAAA,CAAQ,GAAA,CAAI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EAAwC;AAC1D,IAAA,IAAA,CAAK,SAAS,eAAA,GAAkB,KAAA;AAAA,EACjC;AAAA,EAEA,IAAI,eAAA,GAAkB;AACrB,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,eAAA,IAAmB,EAAC;AAAA,EAC1C;AACD","file":"trivious.client.js","sourcesContent":["import { Client, REST, Routes } from \"discord.js\";\nimport { registries } from \"../registry/index.js\";\nimport {\n\tTriviousClientOptions,\n\tPermissionLevel,\n\tSlashCommand,\n\tContextMenuCommand,\n} from \"src/shared/typings/index.js\";\nimport { exists } from \"src/shared/utility/functions.js\";\nimport path from \"node:path\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\n\n/**\n * Trivious base client.\n *\n * @export\n * @class TriviousClient\n * @typedef {TriviousClient}\n * @extends {Client}\n */\nexport default class TriviousClient extends Client {\n\t/**\n\t * Client registries.\n\t *\n\t * @public\n\t * @readonly\n\t * @type {*}\n\t */\n\treadonly registries = registries();\n\t/**\n\t * Client copy of the constructor options.\n\t *\n\t * @private\n\t * @type {TriviousClientOptions}\n\t */\n\treadonly _options: TriviousClientOptions;\n\n\t/**\n\t * Creates an instance of TriviousClient.\n\t *\n\t * @constructor\n\t * @param {TriviousClientOptions} options\n\t */\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis._options = options;\n\t}\n\n\t/**\n\t * Load all registries.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync register() {\n\t\tconst { registries } = this;\n\t\tawait registries.loadAll(this._options);\n\t\tconsole.log(\n\t\t\t`[Trivious] Loaded all registries (${registries.commands.get().size} commands, ${registries.events.get().size} events, ${registries.components.get().size} components, ${registries.modules.get().size} modules)`\n\t\t);\n\t}\n\n\t/**\n\t * Login and start the bot.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync start() {\n\t\tif (!process.env[this._options.tokenReference]) {\n\t\t\tif (process.env.NODE_ENV !== \"production\") return;\n\t\t\telse throw new Error(\"[Trivious] Invalid token reference\");\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\tthis.registries.bind(this);\n\t\tawait this.login(process.env[this._options.tokenReference]);\n\t}\n\n\t/**\n\t * Deploy all commands.\n\t *\n\t * @async\n\t * @returns {*}\n\t */\n\tasync deploy() {\n\t\tconst { commandHashConfig } = this._options;\n\t\tconst clientId = process.env[this._options.clientIdReference];\n\t\tconst token = process.env[this._options.tokenReference];\n\t\tif (!clientId || !token) throw new Error(\"[Trivious] Invalid clientId or token reference\");\n\n\t\tconst commands = Array.from(this.registries.commands.get().values());\n\t\tconst body = [\n\t\t\t...commands.map(command =>\n\t\t\t\t\"data\" in command ? (command as SlashCommand | ContextMenuCommand).data.toJSON() : null\n\t\t\t),\n\t\t].filter(c => c !== null);\n\n\t\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\t\tconst hashFile = path.join(commandHashConfig.filePath || \"data\", \"commands.hash\");\n\t\t\tconst newHash = createHash(\"sha256\")\n\t\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t\t.digest(\"hex\");\n\n\t\t\tlet oldHash = \"\";\n\n\t\t\tif (await exists(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\t\t\tif (newHash === oldHash) {\n\t\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst hashDirectory = path.dirname(hashFile);\n\t\t\tif (!existsSync(hashDirectory)) {\n\t\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t\t}\n\n\t\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t\t}\n\n\t\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\t\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\t\tconsole.log(`[Trivious] Deployed ${body.length} commands`);\n\t}\n\n\t/**\n\t * Set the roles tied to a permission level.\n\t *\n\t * @param {Record<string, PermissionLevel>} roles\n\t */\n\tsetRolePermissions(roles: Record<string, PermissionLevel>) {\n\t\tthis._options.rolePermissions = roles;\n\t}\n\n\tget rolePermissions() {\n\t\treturn this._options.rolePermissions ?? {};\n\t}\n}\n"]}
@@ -1,6 +0,0 @@
1
- import 'discord.js';
2
- export { p as handleSlashCommand, o as interactionReply, v as verifyGuildPermission } from '../../index-DbWA_10I.js';
3
- import '../../shared/typings/permissions.js';
4
- import '../../shared/typings/registry.js';
5
- import '../../shared/typings/client.js';
6
- import '../builders/util.builders.js';
@@ -1,90 +0,0 @@
1
- import { PermissionLevel } from '../../index.js';
2
- import { hasPermission } from '../../shared/utility/functions.js';
3
-
4
- async function interactionReply(data) {
5
- const { interaction, flags, options } = data;
6
- if (!("reply" in interaction)) {
7
- throw new Error(`Cannot reply to interaction type ${typeof interaction}`);
8
- }
9
- const ephemeral = flags?.includes("EphemeralReply");
10
- const followUp = flags?.includes("FollowUp");
11
- let newOptions = options;
12
- if (flags?.includes("ClearAll")) {
13
- newOptions.files = [];
14
- newOptions.embeds = [];
15
- newOptions.components = [];
16
- newOptions.content = "";
17
- newOptions = options;
18
- }
19
- if (ephemeral) newOptions.flags = ["Ephemeral"];
20
- if (interaction.replied || interaction.deferred) {
21
- if (followUp) await interaction.followUp(newOptions);
22
- else await interaction.editReply(newOptions);
23
- } else {
24
- await interaction.reply(newOptions);
25
- }
26
- }
27
- async function verifyGuildPermission(client, interaction, command, requiredPermission, doReply = true) {
28
- if (!interaction.inGuild()) return true;
29
- if (command.flags && command.flags.includes("OwnerOnly")) {
30
- requiredPermission = PermissionLevel.BOT_OWNER;
31
- }
32
- const member = interaction.member;
33
- const memberHasPermission = hasPermission(client, { permission: requiredPermission, member });
34
- if (!memberHasPermission && doReply) {
35
- await interactionReply({
36
- flags: command.flags,
37
- interaction,
38
- options: {
39
- content: `You do not have permission to run this command, required permission: \`${PermissionLevel[requiredPermission]}\``
40
- }
41
- });
42
- }
43
- return memberHasPermission;
44
- }
45
- async function handleSlashCommand(client, command, interaction) {
46
- const { options } = interaction;
47
- const hasPerm = await verifyGuildPermission(
48
- client,
49
- interaction,
50
- command,
51
- command.permission || PermissionLevel.USER,
52
- true
53
- );
54
- if (command.flags?.includes("DeferReply")) {
55
- await interactionReply({
56
- flags: command.flags,
57
- interaction,
58
- options: { content: "Processing command..." }
59
- });
60
- }
61
- if ("run" in command && command.run && hasPerm) {
62
- await command.run(client, interaction);
63
- }
64
- if (!hasPerm) return;
65
- if (!options.getSubcommand(false) || !("subcommands" in command)) return;
66
- const subcommandName = options.getSubcommand();
67
- const subcommand = command.subcommands.get(subcommandName);
68
- if (!subcommand) {
69
- await interactionReply({
70
- flags: command.flags,
71
- interaction,
72
- options: {
73
- content: "This subcommand no longer exists or is not registered."
74
- }
75
- });
76
- return;
77
- }
78
- if (subcommand.flags?.includes("DeferReply") && !subcommand.flags.includes("ModalResponse")) {
79
- await interactionReply({
80
- flags: subcommand.flags,
81
- interaction,
82
- options: { content: "Processing command..." }
83
- });
84
- }
85
- await subcommand.execute(client, interaction);
86
- }
87
-
88
- export { handleSlashCommand, interactionReply, verifyGuildPermission };
89
- //# sourceMappingURL=methods.command.js.map
90
- //# sourceMappingURL=methods.command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/core/commands/methods.command.ts"],"names":[],"mappings":";;;AA6BA,eAAsB,iBAAiB,IAAA,EAIpC;AACF,EAAA,MAAM,EAAE,WAAA,EAAa,KAAA,EAAO,OAAA,EAAQ,GAAI,IAAA;AACxC,EAAA,IAAI,EAAE,WAAW,WAAA,CAAA,EAAc;AAC9B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iCAAA,EAAoC,OAAO,WAAW,CAAA,CAAE,CAAA;AAAA,EACzE;AAEA,EAAA,MAAM,SAAA,GAAY,KAAA,EAAO,QAAA,CAAS,gBAAgB,CAAA;AAClD,EAAA,MAAM,QAA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CAAQ,KAAA;AAAA,MACf,WAAA;AAAA,MACA,OAAA,EAAS;AAAA,QACR,OAAA,EAAS;AAAA;AACV,KACA,CAAA;AACD,IAAA;AAAA,EACD;AAGA,EAAA,IAAI,UAAA,CAAW,KAAA,EAAO,QAAA,CAAS,YAAY,CAAA,IAAK,CAAC,UAAA,CAAW,KAAA,CAAM,QAAA,CAAS,eAAe,CAAA,EAAG;AAC5F,IAAA,MAAM,gBAAA,CAAiB;AAAA,MACtB,OAAO,UAAA,CAAW,KAAA;AAAA,MAClB,WAAA;AAAA,MACA,OAAA,EAAS,EAAE,OAAA,EAAS,uBAAA;AAAwB,KAC5C,CAAA;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,CAAW,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAC7C","file":"methods.command.js","sourcesContent":["import {\n\tCacheType,\n\tChatInputCommandInteraction,\n\tGuildMember,\n\tInteraction,\n\tInteractionEditReplyOptions,\n\tInteractionReplyOptions,\n\tMessagePayload,\n} from \"discord.js\";\nimport {\n\tCommand,\n\tCommandFlags,\n\tPermissionLevel,\n\tSlashCommand,\n\tSlashSubcommand,\n\tTriviousClient,\n} from \"src/index.js\";\nimport { hasPermission } from \"src/shared/utility/functions.js\";\n\n/**\n * Reply to a command, respecting whether it has been deferred or already replied to.\n *\n * @export\n * @async\n * @param {Command} command\n * @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction\n * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options\n * @returns {*}\n */\nexport async function interactionReply(data: {\n\tflags?: (\"ClearAll\" | \"FollowUp\" | CommandFlags)[];\n\tinteraction: Interaction<CacheType>;\n\toptions: MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions;\n}) {\n\tconst { interaction, flags, options } = data;\n\tif (!(\"reply\" in interaction)) {\n\t\tthrow new Error(`Cannot reply to interaction type ${typeof interaction}`);\n\t}\n\n\tconst ephemeral = flags?.includes(\"EphemeralReply\");\n\tconst followUp = flags?.includes(\"FollowUp\");\n\n\tlet newOptions = options as InteractionReplyOptions;\n\tif (flags?.includes(\"ClearAll\")) {\n\t\tnewOptions.files = [];\n\t\tnewOptions.embeds = [];\n\t\tnewOptions.components = [];\n\t\tnewOptions.content = \"\";\n\n\t\tnewOptions = options as InteractionReplyOptions;\n\t}\n\n\tif (ephemeral) newOptions.flags = [\"Ephemeral\"];\n\tif (interaction.replied || interaction.deferred) {\n\t\tif (followUp) await interaction.followUp(newOptions);\n\t\telse await interaction.editReply(newOptions as InteractionEditReplyOptions);\n\t} else {\n\t\tawait interaction.reply(newOptions);\n\t}\n}\n\n/**\n * Compare a permission level to the guild member's permission level.\n *\n * @export\n * @async\n * @param {TriviousClient} client\n * @param {ChatInputCommandInteraction | ContextMenuCommandInteraction} interaction\n * @param {Command} command\n * @param {PermissionLevel} requiredPermission\n * @param {boolean} [doReply=true]\n * @returns {unknown}\n */\nexport async function verifyGuildPermission(\n\tclient: TriviousClient,\n\tinteraction: Interaction<CacheType>,\n\tcommand: Command,\n\trequiredPermission: PermissionLevel,\n\tdoReply: boolean = true\n) {\n\tif (!interaction.inGuild()) return true;\n\n\tif (command.flags && command.flags.includes(\"OwnerOnly\")) {\n\t\trequiredPermission = PermissionLevel.BOT_OWNER;\n\t}\n\n\tconst member = interaction.member as GuildMember;\n\tconst memberHasPermission = hasPermission(client, { permission: requiredPermission, member });\n\n\tif (!memberHasPermission && doReply) {\n\t\tawait interactionReply({\n\t\t\tflags: command.flags,\n\t\t\tinteraction,\n\t\t\toptions: {\n\t\t\t\tcontent: `You do not have permission to run this command, required permission: \\`${PermissionLevel[requiredPermission]}\\``,\n\t\t\t},\n\t\t});\n\t}\n\n\treturn memberHasPermission;\n}\n\n/**\n * Handle execution of a slash command.\n *\n * @export\n * @async\n * @param {TriviousClient} client\n * @param {(SlashCommand | SlashSubcommand)} command\n * @param {ChatInputCommandInteraction} interaction\n * @returns {*}\n */\nexport async function handleSlashCommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommand,\n\tinteraction: ChatInputCommandInteraction\n) {\n\tconst { options } = interaction;\n\n\tconst hasPerm = await verifyGuildPermission(\n\t\tclient,\n\t\tinteraction,\n\t\tcommand,\n\t\tcommand.permission || PermissionLevel.USER,\n\t\ttrue\n\t);\n\n\tif (command.flags?.includes(\"DeferReply\")) {\n\t\tawait interactionReply({\n\t\t\tflags: command.flags,\n\t\t\tinteraction,\n\t\t\toptions: { content: \"Processing command...\" },\n\t\t});\n\t}\n\n\tif (\"run\" in command && command.run && hasPerm) {\n\t\tawait command.run(client, interaction);\n\t}\n\n\tif (!hasPerm) return;\n\n\t// skip subcommand processing and respect command flags\n\tif (!options.getSubcommand(false) || !(\"subcommands\" in command)) return;\n\n\tconst subcommandName = options.getSubcommand();\n\tconst subcommand = command.subcommands!.get(subcommandName) as SlashSubcommand | undefined;\n\n\tif (!subcommand) {\n\t\tawait interactionReply({\n\t\t\tflags: command.flags,\n\t\t\tinteraction,\n\t\t\toptions: {\n\t\t\t\tcontent: \"This subcommand no longer exists or is not registered.\",\n\t\t\t},\n\t\t});\n\t\treturn;\n\t}\n\n\t// respect subcommand flags over command flags\n\tif (subcommand.flags?.includes(\"DeferReply\") && !subcommand.flags.includes(\"ModalResponse\")) {\n\t\tawait interactionReply({\n\t\t\tflags: subcommand.flags,\n\t\t\tinteraction,\n\t\t\toptions: { content: \"Processing command...\" },\n\t\t});\n\t}\n\n\tawait subcommand.execute(client, interaction);\n}\n"]}
@@ -1,14 +0,0 @@
1
- import * as discord_js from 'discord.js';
2
- import { T as TriviousClient } from '../../index-DbWA_10I.js';
3
- import '../../shared/typings/permissions.js';
4
- import '../../shared/typings/registry.js';
5
- import '../../shared/typings/client.js';
6
- import '../builders/util.builders.js';
7
-
8
- declare const _default: {
9
- name: "clientReady";
10
- once: true;
11
- execute: (client: TriviousClient, _: discord_js.Client<true>) => Promise<void>;
12
- };
13
-
14
- export { _default as default };