@guardbot/framework 1.1.3 → 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.
package/build/index.d.ts CHANGED
@@ -1,30 +1,33 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { Client, PermissionResolvable, InteractionContextType, ApplicationIntegrationType, LocalizationMap, ApplicationCommandOptionData, ToAPIApplicationCommandOptions, ChatInputCommandInteraction, AutocompleteInteraction, Message, ContextMenuCommandInteraction, CommandInteraction, PermissionsString, Interaction, Collection, ClientEvents, ModalSubmitInteraction, ClientOptions, MessageCollectorOptions, InteractionCollectorOptions } from 'discord.js';
2
+ import { PermissionResolvable, LocalizationMap, APIApplicationCommandOption, SlashCommandOptionsOnlyBuilder, Message, CommandInteraction, PermissionsString, ChatInputCommandInteraction, AutocompleteInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, ClientEvents, Collection, ModalSubmitInteraction, MessageCollectorOptions, InteractionCollectorOptions, ClientOptions, Client } from 'discord.js';
3
3
  export { SlashCommandAttachmentOption as AttachmentOption, SlashCommandBooleanOption as BooleanOption, SlashCommandChannelOption as ChannelOption, SlashCommandIntegerOption as IntegerOption, SlashCommandMentionableOption as MentionableOption, SlashCommandNumberOption as NumberOption, SlashCommandRoleOption as RoleOption, SlashCommandStringOption as StringOption, SlashCommandSubcommandBuilder as SubcommandBuilder, SlashCommandSubcommandGroupBuilder as SubcommandGroupBuilder, SlashCommandUserOption as UserOption } from 'discord.js';
4
4
  import EventEmitter from 'events';
5
5
 
6
- declare class FrameworkClient<Ready extends boolean = boolean> extends Client<Ready> {
7
- rootDir: string;
8
- prefix: string;
9
- developers: string[];
10
- constructor(frameworkOptions: FrameworkClientOptions);
11
- start(token: string): Promise<void>;
12
- }
13
-
6
+ declare const CommandTypes: readonly ["Slash", "Message", "ContextMessage", "ContextUser"];
7
+ declare const CommandContexts: readonly ["Guild", "BotDM", "PrivateChannel", 0, 1, 2];
8
+ declare const IntegrationTypes: readonly ["GuildInstall", "UserInstall", 0, 1];
9
+ declare const CommandScopes: readonly ["default", "guild", "global"];
10
+ declare const MessageCommandContexts: readonly ["Guild", "BotDM"];
11
+ type CommandType = typeof CommandTypes[number];
12
+ type CommandContext = typeof CommandContexts[number];
13
+ type IntegrationType = typeof IntegrationTypes[number];
14
+ type CommandScope = typeof CommandScopes[number];
15
+ type Result$2 = unknown | void;
16
+ type MessageCommandContext = typeof MessageCommandContexts[number];
14
17
  interface BaseCommandOptions {
15
18
  /** The Name of the Command */
16
19
  name: string;
17
20
  /** The Description of the Command */
18
21
  description: string;
19
22
  /** The Type of the Command */
20
- commandType: 'Slash' | 'Message' | 'ContextMessage' | 'ContextUser';
23
+ commandType: CommandType;
21
24
  /** The Cooldown of the Command (in MS) */
22
25
  cooldown?: number;
23
26
  /** Permissions required by the User to use this Command */
24
27
  memberPermissions?: PermissionResolvable;
25
28
  /** Permissions required by the Application Client to execute this Command */
26
29
  clientPermissions?: PermissionResolvable;
27
- /** Whether this command is Disbaled */
30
+ /** Whether this command is Disabled */
28
31
  disabled?: boolean;
29
32
  }
30
33
  interface BaseAppCommandOptions extends BaseCommandOptions {
@@ -34,26 +37,27 @@ interface BaseAppCommandOptions extends BaseCommandOptions {
34
37
  * - `guild` - In only Guild Commands
35
38
  * - `global` - In only Global Commands
36
39
  */
37
- commandScope: 'default' | 'guild' | 'global';
40
+ commandScope: CommandScope;
38
41
  /**
39
42
  * Where this Application Command can be used
40
43
  * - `Guild` | `(0)` - In Guilds
41
44
  * - `BotDM` | `(1)` - In Application DMs
42
45
  * - `PrivateChannel` | `(2)` - In Other's DMs & Group DMs
43
46
  */
44
- commandContexts?: (InteractionContextType | keyof typeof InteractionContextType)[];
47
+ commandContexts?: CommandContext[];
45
48
  /**
46
49
  * Where this Application Command can be integrated
47
50
  * - `GuildInstall` | `(0)` - App is installable to servers
48
51
  * - `UserInstall` | `(1)` - App is installable to users
49
52
  */
50
- integrationTypes?: (ApplicationIntegrationType | keyof typeof ApplicationIntegrationType)[];
53
+ integrationTypes?: IntegrationType[];
51
54
  /** The Name Localizations of the Command */
52
55
  nameLocalizations?: LocalizationMap;
53
56
  /** The Description Localizations of the Command */
54
57
  descriptionLocalizations?: LocalizationMap;
55
58
  }
56
- interface MessageCommandOptions$1 extends BaseCommandOptions {
59
+ type InferMessage<C> = (C extends MessageCommandContext[] ? 'Guild' extends C[number] ? 'BotDM' extends C[number] ? Message<boolean> : Message<true> : Message<false> : Message<boolean>);
60
+ interface MessageCommandOptions$1<C extends MessageCommandContext[] | undefined = ['Guild']> extends BaseCommandOptions {
57
61
  commandType: 'Message';
58
62
  /** The Aliases of the Command */
59
63
  aliases?: string[];
@@ -62,53 +66,110 @@ interface MessageCommandOptions$1 extends BaseCommandOptions {
62
66
  /** Whether the command is Developer Only */
63
67
  devOnly?: boolean;
64
68
  /**
65
- * Where this Application Command can be used
69
+ * Where this Message Command can be used
66
70
  * - `BotDM` - In Application DMs
67
71
  * - `Guild` - In Guilds
68
72
  */
69
- contexts?: ('BotDM' | 'Guild')[];
70
- execute: (client: FrameworkClient<true>, message: Message, args: string[]) => Promise<unknown>;
73
+ contexts?: C;
74
+ execute: (client: FrameworkClient<true>, message: InferMessage<C>, args: string[]) => Promise<Result$2> | Result$2;
71
75
  }
76
+ type SlashOptionsInput = (APIApplicationCommandOption[] | {
77
+ toJSON(): APIApplicationCommandOption;
78
+ }[] | ((builder: SlashCommandOptionsOnlyBuilder) => SlashCommandOptionsOnlyBuilder));
72
79
  interface SlashCommandOptions$1 extends BaseAppCommandOptions {
73
80
  commandType: 'Slash';
74
81
  /** The Application Command Options of this Command */
75
- options?: (ApplicationCommandOptionData | ToAPIApplicationCommandOptions)[];
76
- execute: (client: FrameworkClient<true>, interaction: ChatInputCommandInteraction) => Promise<unknown>;
77
- autocomplete?: (client: FrameworkClient<true>, interaction: AutocompleteInteraction) => Promise<unknown>;
82
+ options?: SlashOptionsInput;
83
+ execute: (client: FrameworkClient<true>, interaction: ChatInputCommandInteraction<'cached'>) => Promise<Result$2> | Result$2;
84
+ autocomplete?: (client: FrameworkClient<true>, interaction: AutocompleteInteraction<'cached'>) => Promise<Result$2> | Result$2;
78
85
  }
79
- interface ContextCommandOptions extends BaseAppCommandOptions {
80
- commandType: 'ContextMessage' | 'ContextUser';
81
- execute: (client: FrameworkClient<true>, interaction: ContextMenuCommandInteraction) => Promise<unknown>;
86
+ interface ContextMessageCommandOptions extends Omit<BaseAppCommandOptions, 'description'> {
87
+ commandType: 'ContextMessage';
88
+ /** The Description of the Command */
89
+ description?: string;
90
+ execute: (client: FrameworkClient<true>, interaction: MessageContextMenuCommandInteraction<'cached'>) => Promise<Result$2> | Result$2;
82
91
  }
83
- interface BaseCommand {
92
+ interface ContextUserCommandOptions extends Omit<BaseAppCommandOptions, 'description'> {
93
+ commandType: 'ContextUser';
94
+ /** The Description of the Command */
95
+ description?: string;
96
+ execute: (client: FrameworkClient<true>, interaction: UserContextMenuCommandInteraction<'cached'>) => Promise<Result$2> | Result$2;
97
+ }
98
+ type ContextCommandOptions = (ContextMessageCommandOptions | ContextUserCommandOptions);
99
+ interface BaseCommandMeta {
84
100
  id: string;
85
101
  filepath: string;
86
102
  disabled: boolean;
87
103
  }
88
- type FrameworkSlashCommand = SlashCommandOptions$1 & BaseCommand;
89
- type FrameworkContextCommand = ContextCommandOptions & BaseCommand;
90
- type FrameworkMessageCommand = MessageCommandOptions$1 & BaseCommand & {
104
+ type FrameworkSlashCommand = SlashCommandOptions$1 & BaseCommandMeta & {
105
+ options: APIApplicationCommandOption[];
106
+ };
107
+ type FrameworkMessageCommand = MessageCommandOptions$1 & BaseCommandMeta & {
91
108
  devOnly: boolean;
92
- contexts: ('BotDM' | 'Guild')[];
109
+ contexts: MessageCommandContext[];
93
110
  };
111
+ type FrameworkContextCommand = ContextCommandOptions & BaseCommandMeta;
94
112
  type FrameworkCommand = (FrameworkSlashCommand | FrameworkMessageCommand | FrameworkContextCommand);
95
- interface CommandModuleHandler {
113
+ type CommandMiddleware = (context: Message | CommandInteraction, command: FrameworkCommand) => Promise<boolean> | boolean;
114
+ interface CommandCustomHandlers {
96
115
  onCooldown?: (context: Message | CommandInteraction, command: FrameworkCommand, expirationTime: Date) => any;
97
116
  onMemberPermissions?: (context: Message, command: FrameworkCommand, missingPermissions: PermissionsString[]) => any;
98
117
  onClientPermissions?: (context: Message | CommandInteraction, command: FrameworkCommand, missingPermissions: PermissionsString[]) => any;
99
- MessageCommandInterceptor?: (message: Message) => Promise<boolean>;
100
- InteractionCommandInterceptor?: (interaction: Interaction) => Promise<boolean>;
101
118
  }
102
- type CommandHandlerName = keyof Omit<CommandModuleHandler, 'MessageCommandInterceptor' | 'InteractionCommandInterceptor'>;
119
+
120
+ type Result$1 = unknown | void;
121
+ interface ListenerOptions<T extends keyof ClientEvents = keyof ClientEvents> {
122
+ /** Name of the Listener */
123
+ name: T;
124
+ /** Whether to execute only once */
125
+ once?: boolean;
126
+ /** Whether the Listener is disabled */
127
+ disabled?: boolean;
128
+ /** Handles the execution of the Listener */
129
+ execute: (...args: ClientEvents[T]) => Promise<Result$1> | Result$1;
130
+ }
131
+ interface BaseListenerMeta {
132
+ id: string;
133
+ filepath: string;
134
+ }
135
+ interface FrameworkListener<T extends keyof ClientEvents = keyof ClientEvents> extends BaseListenerMeta {
136
+ name: T;
137
+ once: boolean;
138
+ disabled: boolean;
139
+ execute: (...args: ClientEvents[T]) => Promise<Result$1> | Result$1;
140
+ _execute?: (...args: ClientEvents[T]) => Promise<Result$1> | Result$1;
141
+ }
142
+
143
+ type Result = unknown | void;
144
+ interface AutocompleterOptions {
145
+ /** Name of the Autocompleter */
146
+ name: string;
147
+ /** Whether the Autocompleter is disabled */
148
+ disabled?: boolean;
149
+ /** Command Names the Autocompleter applies to */
150
+ commands?: string[];
151
+ /** Handle the execution of the Autocompleter */
152
+ execute: (client: FrameworkClient<true>, interaction: AutocompleteInteraction<'cached'>, command: FrameworkSlashCommand, value: string) => Promise<Result> | Result;
153
+ }
154
+ interface BaseAutocompleterMeta {
155
+ id: string;
156
+ filepath: string;
157
+ }
158
+ interface FrameworkAutocompleter extends BaseAutocompleterMeta {
159
+ name: string;
160
+ disabled: boolean;
161
+ commands?: string[];
162
+ execute: (client: FrameworkClient<true>, interaction: AutocompleteInteraction<'cached'>, command: FrameworkSlashCommand, value: string) => Promise<Result> | Result;
163
+ }
103
164
 
104
165
  /**
105
- * @class AutocompleteModule
106
- * @fires AutocompleteModule#execute
107
- * @fires AutocompleteModule#success
108
- * @fires AutocompleteModule#error
109
- * @fires AutocompleteModule#unknown
166
+ * @class AutocompletersModule
167
+ * @fires AutocompletersModule#execute
168
+ * @fires AutocompletersModule#success
169
+ * @fires AutocompletersModule#error
170
+ * @fires AutocompletersModule#unknown
110
171
  */
111
- declare class AutocompleteModule extends EventEmitter {
172
+ declare class AutocompletersModule extends EventEmitter {
112
173
  private client;
113
174
  constructor(client: FrameworkClient);
114
175
  load(filepath: string, reload?: boolean): Promise<boolean>;
@@ -136,11 +197,12 @@ declare class ListenerModule {
136
197
  */
137
198
  declare class CommandsModule extends EventEmitter {
138
199
  private client;
139
- private handler;
200
+ private handlers;
201
+ private middleware?;
202
+ private prefixRegex?;
140
203
  constructor(client: FrameworkClient);
141
- setHandler<K extends CommandHandlerName>(key: K, callback: NonNullable<CommandModuleHandler[K]>): NonNullable<CommandModuleHandler[K]>;
142
- setMessageInterceptor(callback: (message: Message) => Promise<boolean>): (message: Message) => Promise<boolean>;
143
- setInteractionInterceptor(callback: (interaction: Interaction) => Promise<boolean>): (interaction: Interaction) => Promise<boolean>;
204
+ setHandler<K extends keyof CommandCustomHandlers>(key: K, callback: NonNullable<CommandCustomHandlers[K]>): boolean;
205
+ setMiddleware(callback: CommandMiddleware): boolean;
144
206
  load(filepath: string, reload?: boolean): Promise<boolean>;
145
207
  loadAll(): Promise<void>;
146
208
  reload(id: string): Promise<void>;
@@ -156,54 +218,10 @@ declare class CommandsModule extends EventEmitter {
156
218
  private _getCommandData;
157
219
  }
158
220
 
159
- interface ListenerOptions<T extends keyof ClientEvents = keyof ClientEvents> {
160
- /** Name of the Listener. */
161
- name: T;
162
- /** Wheather to execute the function only Once. */
163
- once?: boolean;
164
- /** Whether the Listener is disabled. */
165
- disabled?: boolean;
166
- /** Handles the execution of the Listener */
167
- execute: (...args: ClientEvents[T]) => Promise<boolean>;
168
- }
169
- interface FrameworkListener<T extends keyof ClientEvents = keyof ClientEvents> {
170
- id: string;
171
- filepath: string;
172
- name: T;
173
- once: boolean;
174
- disabled: boolean;
175
- execute: (...args: ClientEvents[T]) => Promise<boolean>;
176
- _execute?: (...args: ClientEvents[T]) => Promise<boolean>;
177
- }
178
-
179
- interface FrameworkClientOptions {
180
- clientOptions: ClientOptions;
181
- rootDir?: string;
182
- developers?: string[];
183
- prefix?: string;
184
- registerOnStart?: boolean;
185
- guildsToRegister?: string[];
186
- }
187
- interface AutocompleterOptions {
188
- /** Name of the Autocompleter. */
189
- name: string;
190
- /** Whether the Autocompleter is disabled. */
191
- disabled?: boolean;
192
- /** Handle the execution of the Autocompleter. */
193
- execute: (client: FrameworkClient<true>, interaction: AutocompleteInteraction, command: FrameworkSlashCommand, value: string) => Promise<unknown>;
194
- }
195
- interface FrameworkAutocompleter {
196
- id: string;
197
- filepath: string;
198
- name: string;
199
- disabled: boolean;
200
- execute: (client: FrameworkClient<true>, interaction: AutocompleteInteraction, command: FrameworkSlashCommand, value: string) => Promise<unknown>;
201
- }
202
221
  type ModalCollectorOptions = InteractionCollectorOptions<ModalSubmitInteraction>;
203
222
  interface AwaitMemberResponseOptions extends MessageCollectorOptions {
204
223
  deleteMessage?: boolean;
205
224
  }
206
-
207
225
  declare module 'discord.js' {
208
226
  interface ClientEvents {
209
227
  buttonInteraction: [interaction: ButtonInteraction];
@@ -212,15 +230,15 @@ declare module 'discord.js' {
212
230
  }
213
231
  interface Client {
214
232
  prefix: string;
215
- developers: string[];
216
- autocomplete: Collection<string, FrameworkAutocompleter>;
233
+ developers: readonly string[];
217
234
  aliases: Collection<string, string>;
218
235
  commands: Collection<string, FrameworkCommand>;
219
236
  cooldowns: Collection<string, Collection<string, number>>;
220
237
  events: Collection<string, FrameworkListener<keyof ClientEvents>>;
221
- autocompleteModule: AutocompleteModule;
238
+ autocompleters: Collection<string, FrameworkAutocompleter>;
222
239
  commandsModule: CommandsModule;
223
- listenerModule: ListenerModule;
240
+ listenersModule: ListenerModule;
241
+ autocompletersModule: AutocompletersModule;
224
242
  }
225
243
  interface Message {
226
244
  prefix: string;
@@ -231,18 +249,52 @@ declare module 'discord.js' {
231
249
  }
232
250
  }
233
251
 
252
+ interface FrameworkClientOptions {
253
+ clientOptions: ClientOptions;
254
+ developers?: readonly string[];
255
+ prefix?: string;
256
+ registerOnStart?: boolean;
257
+ guildsToRegister?: string[];
258
+ rootDir?: string;
259
+ commandsDir?: string;
260
+ listenersDir?: string;
261
+ autocompletersDir?: string;
262
+ }
263
+
264
+ declare class FrameworkClient<Ready extends boolean = boolean> extends Client<Ready> {
265
+ prefix: string;
266
+ developers: string[];
267
+ rootDir: string;
268
+ commandsDir: string;
269
+ listenersDir: string;
270
+ autocompletersDir: string;
271
+ private _inited;
272
+ autocompleters: Collection<string, FrameworkAutocompleter>;
273
+ events: Collection<string, FrameworkListener<keyof ClientEvents>>;
274
+ aliases: Collection<string, string>;
275
+ commands: Collection<string, FrameworkCommand>;
276
+ cooldowns: Collection<string, Collection<string, number>>;
277
+ commandsModule: CommandsModule;
278
+ listenersModule: ListenerModule;
279
+ autocompletersModule: AutocompletersModule;
280
+ constructor(frameworkOptions: FrameworkClientOptions);
281
+ init(): Promise<void>;
282
+ start(token: string): Promise<void>;
283
+ private routeInteractions;
284
+ }
285
+
234
286
  declare function Autocompleter(options: AutocompleterOptions): {
235
287
  id: string;
236
288
  name: string;
237
289
  disabled: boolean;
238
- execute: (client: FrameworkClient<true>, interaction: discord_js.AutocompleteInteraction, command: FrameworkSlashCommand, value: string) => Promise<unknown>;
290
+ execute: (client: FrameworkClient<true>, interaction: discord_js.AutocompleteInteraction<"cached">, command: FrameworkSlashCommand, value: string) => Promise<unknown> | unknown;
239
291
  };
240
292
 
241
293
  declare function ContextCommand(options: ContextCommandOptions): {
242
294
  id: string;
243
295
  name: string;
244
296
  description: string;
245
- commandType: "Slash" | "Message" | "ContextUser" | "ContextMessage";
297
+ commandType: "Slash" | "Message" | "ContextMessage" | "ContextUser";
246
298
  memberPermissions: discord_js.PermissionResolvable | undefined;
247
299
  clientPermissions: discord_js.PermissionResolvable | undefined;
248
300
  cooldown: number | undefined;
@@ -254,7 +306,7 @@ declare function MessageCommand(options: MessageCommandOptions): {
254
306
  id: string;
255
307
  name: string;
256
308
  description: string;
257
- commandType: "Slash" | "Message" | "ContextUser" | "ContextMessage";
309
+ commandType: "Slash" | "Message" | "ContextMessage" | "ContextUser";
258
310
  memberPermissions: discord_js.PermissionResolvable | undefined;
259
311
  clientPermissions: discord_js.PermissionResolvable | undefined;
260
312
  cooldown: number | undefined;
@@ -266,7 +318,7 @@ declare function SlashCommand(options: SlashCommandOptions): {
266
318
  id: string;
267
319
  name: string;
268
320
  description: string;
269
- commandType: "Slash" | "Message" | "ContextUser" | "ContextMessage";
321
+ commandType: "Slash" | "Message" | "ContextMessage" | "ContextUser";
270
322
  memberPermissions: discord_js.PermissionResolvable | undefined;
271
323
  clientPermissions: discord_js.PermissionResolvable | undefined;
272
324
  cooldown: number | undefined;
@@ -278,7 +330,7 @@ declare function Listener<T extends keyof ClientEvents>(options: ListenerOptions
278
330
  name: T;
279
331
  once: boolean;
280
332
  disabled: boolean;
281
- execute: (...args: ClientEvents[T]) => Promise<boolean>;
333
+ execute: (...args: ClientEvents[T]) => Promise<unknown> | unknown;
282
334
  };
283
335
 
284
- export { Autocompleter, type CommandHandlerName, type CommandModuleHandler, ContextCommand, type FrameworkAutocompleter, FrameworkClient, type FrameworkCommand, type FrameworkContextCommand, type FrameworkListener, type FrameworkMessageCommand, type FrameworkSlashCommand, Listener, MessageCommand, SlashCommand };
336
+ export { Autocompleter, ContextCommand, type FrameworkAutocompleter, FrameworkClient, type FrameworkCommand, type FrameworkContextCommand, type FrameworkListener, type FrameworkMessageCommand, type FrameworkSlashCommand, Listener, MessageCommand, SlashCommand };