reciple 5.6.0 → 6.0.0-dev.2

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/cjs/bin.js +9 -10
  2. package/dist/cjs/index.js +7 -6
  3. package/dist/cjs/reciple/classes/RecipleClient.js +87 -181
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +6 -4
  6. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +14 -22
  7. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +137 -0
  8. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +60 -0
  9. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +193 -0
  10. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  11. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  12. package/dist/cjs/reciple/logger.js +10 -8
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/util.js +10 -1
  15. package/dist/types/index.d.ts +7 -6
  16. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  17. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +2 -2
  18. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +12 -12
  19. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +20 -0
  20. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  21. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +79 -0
  22. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +3 -2
  23. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  24. package/dist/types/reciple/types/builders.d.ts +13 -13
  25. package/dist/types/reciple/types/commands.d.ts +2 -2
  26. package/dist/types/reciple/types/paramOptions.d.ts +8 -19
  27. package/dist/types/reciple/util.d.ts +2 -0
  28. package/package.json +21 -16
  29. package/dist/cjs/reciple/modules.js +0 -113
  30. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  31. package/dist/types/reciple/modules.d.ts +0 -64
  32. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
@@ -1,7 +1,7 @@
1
1
  import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties, MessageCommandData } from '../../types/builders';
2
2
  import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
3
3
  import { BaseCommandExecuteData, CommandHaltData } from '../../types/commands';
4
- import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
4
+ import { MessageCommandOptionManager } from '../managers/MessageCommandOptionManager';
5
5
  import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
6
6
  import { Command } from 'fallout-utility';
7
7
  /**
@@ -80,7 +80,7 @@ export declare class MessageCommandBuilder<T = unknown> implements SharedCommand
80
80
  halt?: MessageCommandHaltFunction<T>;
81
81
  execute: MessageCommandExecuteFunction<T>;
82
82
  metadata?: T;
83
- constructor(data?: Partial<Omit<MessageCommandData<T>, "type">>);
83
+ constructor(data?: Partial<Omit<MessageCommandData<T>, 'type'>>);
84
84
  /**
85
85
  * Sets the command name
86
86
  * @param name Command name
@@ -26,20 +26,20 @@ export declare type SlashCommandHaltFunction<T = unknown> = CommandHaltFunction<
26
26
  * Slash command execute function
27
27
  */
28
28
  export declare type SlashCommandExecuteFunction<T = unknown> = CommandExecuteFunction<CommandBuilderType.SlashCommand, T>;
29
- export declare type SlashCommandSubcommandsOnlyBuilder<T = unknown> = Omit<SlashCommandBuilder<T>, "addBooleanOption" | "addUserOption" | "addChannelOption" | "addRoleOption" | "addAttachmentOption" | "addMentionableOption" | "addStringOption" | "addIntegerOption" | "addNumberOption">;
30
- export declare type SlashCommandOptionsOnlyBuilder<T = unknown> = Omit<SlashCommandBuilder<T>, "addSubcommand" | "addSubcommandGroup">;
29
+ export declare type SlashCommandSubcommandsOnlyBuilder<T = unknown> = Omit<SlashCommandBuilder<T>, 'addBooleanOption' | 'addUserOption' | 'addChannelOption' | 'addRoleOption' | 'addAttachmentOption' | 'addMentionableOption' | 'addStringOption' | 'addIntegerOption' | 'addNumberOption'>;
30
+ export declare type SlashCommandOptionsOnlyBuilder<T = unknown> = Omit<SlashCommandBuilder<T>, 'addSubcommand' | 'addSubcommandGroup'>;
31
31
  export interface SlashCommandBuilder<T = unknown> extends DiscordJsSlashCommandBuilder {
32
32
  addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
33
33
  addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
34
- addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
35
- addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
36
- addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
37
- addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
38
- addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
39
- addMentionableOption(input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
40
- addStringOption(input: SlashCommandStringOption | Omit<SlashCommandStringOption, 'setAutocomplete'> | Omit<SlashCommandStringOption, 'addChoices'> | ((builder: SlashCommandStringOption) => SlashCommandStringOption | Omit<SlashCommandStringOption, 'setAutocomplete'> | Omit<SlashCommandStringOption, 'addChoices'>)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
41
- addIntegerOption(input: SlashCommandIntegerOption | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | Omit<SlashCommandIntegerOption, 'addChoices'> | ((builder: SlashCommandIntegerOption) => SlashCommandIntegerOption | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | Omit<SlashCommandIntegerOption, 'addChoices'>)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
42
- addNumberOption(input: SlashCommandNumberOption | Omit<SlashCommandNumberOption, 'setAutocomplete'> | Omit<SlashCommandNumberOption, 'addChoices'> | ((builder: SlashCommandNumberOption) => SlashCommandNumberOption | Omit<SlashCommandNumberOption, 'setAutocomplete'> | Omit<SlashCommandNumberOption, 'addChoices'>)): Omit<this, "addSubcommand" | "addSubcommandGroup">;
34
+ addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
35
+ addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
36
+ addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
37
+ addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
38
+ addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
39
+ addMentionableOption(input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
40
+ addStringOption(input: SlashCommandStringOption | Omit<SlashCommandStringOption, 'setAutocomplete'> | Omit<SlashCommandStringOption, 'addChoices'> | ((builder: SlashCommandStringOption) => SlashCommandStringOption | Omit<SlashCommandStringOption, 'setAutocomplete'> | Omit<SlashCommandStringOption, 'addChoices'>)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
41
+ addIntegerOption(input: SlashCommandIntegerOption | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | Omit<SlashCommandIntegerOption, 'addChoices'> | ((builder: SlashCommandIntegerOption) => SlashCommandIntegerOption | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | Omit<SlashCommandIntegerOption, 'addChoices'>)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
42
+ addNumberOption(input: SlashCommandNumberOption | Omit<SlashCommandNumberOption, 'setAutocomplete'> | Omit<SlashCommandNumberOption, 'addChoices'> | ((builder: SlashCommandNumberOption) => SlashCommandNumberOption | Omit<SlashCommandNumberOption, 'setAutocomplete'> | Omit<SlashCommandNumberOption, 'addChoices'>)): Omit<this, 'addSubcommand' | 'addSubcommandGroup'>;
43
43
  }
44
44
  /**
45
45
  * Reciple builder for slash command
@@ -52,7 +52,7 @@ export declare class SlashCommandBuilder<T = unknown> extends DiscordJsSlashComm
52
52
  halt?: SlashCommandHaltFunction<T>;
53
53
  execute: SlashCommandExecuteFunction<T>;
54
54
  metadata?: T;
55
- constructor(data?: Partial<Omit<SlashCommandData<T>, "type">>);
55
+ constructor(data?: Partial<Omit<SlashCommandData<T>, 'type'>>);
56
56
  setCooldown(cooldown: number): this;
57
57
  setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
58
58
  setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
@@ -0,0 +1,20 @@
1
+ import { ApplicationCommand, ApplicationCommandData, ContextMenuCommandBuilder, GuildResolvable, RESTPostAPIApplicationCommandsJSONBody, SlashCommandBuilder as DiscordJsSlashCommandBuilder } from 'discord.js';
2
+ import { AnySlashCommandBuilder } from '../../types/builders';
3
+ import { RecipleClient } from '../RecipleClient';
4
+ export declare type ApplicationCommandBuilder = AnySlashCommandBuilder | ContextMenuCommandBuilder | DiscordJsSlashCommandBuilder;
5
+ export declare class ApplicationCommandManager {
6
+ readonly client: RecipleClient;
7
+ get commands(): import("discord.js").ApplicationCommandManager<ApplicationCommand<{
8
+ guild: GuildResolvable;
9
+ }>, {
10
+ guild: GuildResolvable;
11
+ }, null> | undefined;
12
+ constructor(client: RecipleClient);
13
+ set(commands: (ApplicationCommandBuilder | ApplicationCommandData)[], guilds?: GuildResolvable[]): Promise<void>;
14
+ add(command: ApplicationCommandBuilder | ApplicationCommandData, guilds?: GuildResolvable[]): Promise<void>;
15
+ remove(command: string | ApplicationCommand, guilds?: GuildResolvable[]): Promise<void>;
16
+ edit(command: string | ApplicationCommand, newCommand: ApplicationCommandBuilder | ApplicationCommandData, guilds?: GuildResolvable[]): Promise<void>;
17
+ get(command: ApplicationCommandData | ApplicationCommandBuilder | string, guild?: GuildResolvable): ApplicationCommand | undefined;
18
+ fetch(commandId: string, guild?: GuildResolvable): Promise<ApplicationCommand>;
19
+ protected parseCommands(commands: (ApplicationCommandData | ApplicationCommandBuilder | RESTPostAPIApplicationCommandsJSONBody)[], setPermissions?: boolean): (ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody)[];
20
+ }
@@ -0,0 +1,37 @@
1
+ import { ApplicationCommandData, Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
+ import { AnyCommandBuilder, AnyCommandData, AnySlashCommandBuilder, CommandBuilderType, MessageCommandData, SlashCommandData } from '../../types/builders';
3
+ import { MessageCommandBuilder } from '../builders/MessageCommandBuilder';
4
+ import { SlashCommandBuilder } from '../builders/SlashCommandBuilder';
5
+ import { RecipleClient } from '../RecipleClient';
6
+ import { ApplicationCommandBuilder } from './ApplicationCommandManager';
7
+ export interface ClientCommandManagerOptions {
8
+ client: RecipleClient;
9
+ messageCommands?: (MessageCommandBuilder | MessageCommandData)[];
10
+ slashCommands?: (AnySlashCommandBuilder | SlashCommandData)[];
11
+ }
12
+ export declare class ClientCommandManager {
13
+ readonly client: RecipleClient;
14
+ readonly slashCommands: Collection<string, AnySlashCommandBuilder>;
15
+ readonly messageCommands: Collection<string, MessageCommandBuilder>;
16
+ readonly additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
17
+ get applicationCommandsSize(): number;
18
+ constructor(options: ClientCommandManagerOptions);
19
+ /**
20
+ * Add command to command manager
21
+ * @param commands Any command data or builder
22
+ */
23
+ add(...commands: RestOrArray<AnyCommandBuilder | AnyCommandData>): this;
24
+ /**
25
+ * Get command builder by name or alias if it's a message command
26
+ * @param command Command name
27
+ * @param type Command type
28
+ */
29
+ get(command: string, type?: undefined): AnyCommandBuilder | undefined;
30
+ get(command: string, type?: CommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
31
+ get(command: string, type?: CommandBuilderType.SlashCommand): SlashCommandBuilder | undefined;
32
+ /**
33
+ * Register application commands
34
+ * @param guilds Register application commands to guilds
35
+ */
36
+ registerApplicationCommands(...guilds: RestOrArray<GuildResolvable>): Promise<this>;
37
+ }
@@ -0,0 +1,79 @@
1
+ import { Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
+ import { AnyCommandBuilder, AnyCommandData } from '../../types/builders';
3
+ import { ModuleManagerResolveFilesOptions } from '../../types/paramOptions';
4
+ import { RecipleClient } from '../RecipleClient';
5
+ /**
6
+ * Reciple script object
7
+ */
8
+ export interface RecipleScript {
9
+ /**
10
+ * Supported reciple versions
11
+ */
12
+ versions: string | string[];
13
+ /**
14
+ * Module commands
15
+ */
16
+ commands?: (AnyCommandBuilder | AnyCommandData)[];
17
+ /**
18
+ * Action on module start
19
+ * @param client Bot client
20
+ */
21
+ onStart(client: RecipleClient<false>): boolean | Promise<boolean>;
22
+ /**
23
+ * Action on bot ready
24
+ * @param client Bot client
25
+ */
26
+ onLoad?(client: RecipleClient<true>): void | Promise<void>;
27
+ }
28
+ /**
29
+ * Reciple module object
30
+ */
31
+ export interface RecipleModule {
32
+ /**
33
+ * Module Id
34
+ */
35
+ id: string;
36
+ /**
37
+ * Module script
38
+ */
39
+ script: RecipleScript;
40
+ /**
41
+ * Module local information
42
+ */
43
+ info: {
44
+ /**
45
+ * Module file name
46
+ */
47
+ filename?: string;
48
+ /**
49
+ * Module local file path
50
+ */
51
+ path?: string;
52
+ };
53
+ }
54
+ export interface ResolvedModule extends RecipleModule {
55
+ commands: AnyCommandBuilder[];
56
+ }
57
+ export interface ResolvedScriptCommands {
58
+ script: RecipleScript;
59
+ commands: AnyCommandBuilder[];
60
+ }
61
+ export interface ClientModuleManagerOptions {
62
+ client: RecipleClient;
63
+ modules?: (RecipleModule & {
64
+ id?: string;
65
+ })[];
66
+ }
67
+ export declare class ClientModuleManager {
68
+ readonly client: RecipleClient;
69
+ readonly modules: Collection<string, ResolvedModule>;
70
+ constructor(options: ClientModuleManagerOptions);
71
+ startModulesFromFiles(options: ModuleManagerResolveFilesOptions): Promise<ResolvedModule[]>;
72
+ resolveModulesFromFiles(options: ModuleManagerResolveFilesOptions): Promise<ResolvedModule[]>;
73
+ resolveScriptCommands(...modules: RestOrArray<RecipleScript>): ResolvedScriptCommands[];
74
+ loadAll(registerApplicationCommands?: boolean, ...registerApplicationCommandsGuilds: RestOrArray<GuildResolvable>): Promise<void>;
75
+ startModule(mod: ResolvedModule): Promise<void>;
76
+ resolveModule(mod: RecipleModule, disabeVersionCheck?: boolean): ResolvedModule;
77
+ getModuleFiles(...folders: RestOrArray<string>): Promise<string[]>;
78
+ static getModuleDisplayId(mod: RecipleModule): string;
79
+ }
@@ -1,5 +1,5 @@
1
1
  import { Guild, RestOrArray, TextBasedChannel, User } from 'discord.js';
2
- import { CommandBuilderType } from '../types/builders';
2
+ import { CommandBuilderType } from '../../types/builders';
3
3
  /**
4
4
  * cooled-down user object interface
5
5
  */
@@ -43,8 +43,9 @@ export declare class CommandCooldownManager extends Array<CooledDownUser> {
43
43
  * Remove cooldown from specific user, channel or guild
44
44
  * @param options Remove cooldown data options
45
45
  * @param limit Remove cooldown data limit
46
+ * @returns Returns the removed values
46
47
  */
47
- remove(options: Partial<CooledDownUser>, limit?: number): void;
48
+ remove(options: Partial<CooledDownUser>, limit?: number): CooledDownUser[];
48
49
  /**
49
50
  * Check if the given user is cooled-down
50
51
  * @param options Options to identify if user is on cooldown
@@ -1,4 +1,4 @@
1
- import { MessageCommandValidatedOption } from './builders/MessageCommandBuilder';
1
+ import { MessageCommandValidatedOption } from '../builders/MessageCommandBuilder';
2
2
  import { RestOrArray } from 'discord.js';
3
3
  /**
4
4
  * Validated message options manager
@@ -88,12 +88,12 @@ export interface SharedCommandBuilderProperties<T = unknown> {
88
88
  * Function when the command is interupted
89
89
  * @param halt Function to execute when command is halted
90
90
  */
91
- setHalt(halt?: this["halt"]): this;
91
+ setHalt(halt?: this['halt']): this;
92
92
  /**
93
93
  * Function when the command is executed
94
94
  * @param execute Function to execute when the command is called
95
95
  */
96
- setExecute(execute: this["execute"]): this;
96
+ setExecute(execute: this['execute']): this;
97
97
  /**
98
98
  * Set a command metadata
99
99
  * @param metadata Command metadata
@@ -110,7 +110,7 @@ export interface SharedCommandDataProperties {
110
110
  /**
111
111
  * Slash command object data interface
112
112
  */
113
- export interface SlashCommandData<T = unknown> extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties<T>, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute" | "setMetadata" | "halt" | "execute">> {
113
+ export interface SlashCommandData<T = unknown> extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties<T>, 'setCooldown' | 'setRequiredBotPermissions' | 'setRequiredMemberPermissions' | 'setHalt' | 'setExecute' | 'setMetadata' | 'halt' | 'execute'>> {
114
114
  type: CommandBuilderType.SlashCommand;
115
115
  nameLocalizations?: LocalizationMap;
116
116
  descriptionLocalizations?: LocalizationMap;
@@ -124,7 +124,7 @@ export interface SlashCommandData<T = unknown> extends SharedCommandDataProperti
124
124
  halt?: SlashCommandHaltFunction<T>;
125
125
  execute: SlashCommandExecuteFunction<T>;
126
126
  }
127
- export interface SharedSlashCommandOptionData<V = string | number> extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
127
+ export interface SharedSlashCommandOptionData<V = string | number> extends SharedCommandDataProperties, Pick<SlashCommandData, 'nameLocalizations' | 'descriptionLocalizations'> {
128
128
  choices?: {
129
129
  name: string;
130
130
  nameLocalizations?: LocalizationMap;
@@ -133,13 +133,13 @@ export interface SharedSlashCommandOptionData<V = string | number> extends Share
133
133
  autocomplete?: boolean;
134
134
  required?: boolean;
135
135
  }
136
- export interface SlashCommandAttachmentOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
136
+ export interface SlashCommandAttachmentOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
137
137
  type: ApplicationCommandOptionType.Attachment;
138
138
  }
139
- export interface SlashCommandBooleanOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
139
+ export interface SlashCommandBooleanOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
140
140
  type: ApplicationCommandOptionType.Boolean;
141
141
  }
142
- export interface SlashCommandChannelOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
142
+ export interface SlashCommandChannelOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
143
143
  type: ApplicationCommandOptionType.Channel;
144
144
  channelTypes?: ApplicationCommandOptionAllowedChannelTypes[];
145
145
  }
@@ -148,7 +148,7 @@ export interface SlashCommandIntegerOptionData extends SharedSlashCommandOptionD
148
148
  minValue?: number;
149
149
  maxValue?: number;
150
150
  }
151
- export interface SlashCommandMentionableOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
151
+ export interface SlashCommandMentionableOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
152
152
  type: ApplicationCommandOptionType.Mentionable;
153
153
  }
154
154
  export interface SlashCommandNumberOptionData extends SharedSlashCommandOptionData<number> {
@@ -156,7 +156,7 @@ export interface SlashCommandNumberOptionData extends SharedSlashCommandOptionDa
156
156
  minValue?: number;
157
157
  maxValue?: number;
158
158
  }
159
- export interface SlashCommandRoleOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
159
+ export interface SlashCommandRoleOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
160
160
  type: ApplicationCommandOptionType.Role;
161
161
  }
162
162
  export interface SlashCommandStringOptionData extends SharedSlashCommandOptionData<string> {
@@ -164,21 +164,21 @@ export interface SlashCommandStringOptionData extends SharedSlashCommandOptionDa
164
164
  minLength?: number;
165
165
  maxLength?: number;
166
166
  }
167
- export interface SlashCommandUserOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
167
+ export interface SlashCommandUserOptionData extends Omit<SharedSlashCommandOptionData, 'choices' | 'autocomplete'> {
168
168
  type: ApplicationCommandOptionType.User;
169
169
  }
170
- export interface SlashCommandSubCommandData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
170
+ export interface SlashCommandSubCommandData extends SharedCommandDataProperties, Pick<SlashCommandData, 'nameLocalizations' | 'descriptionLocalizations'> {
171
171
  type: ApplicationCommandOptionType.Subcommand;
172
172
  options: (AnySlashCommandOptionsOnlyOptionData | AnySlashCommandOptionsOnlyOptionBuilder)[];
173
173
  }
174
- export interface SlashCommandSubCommandGroupData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
174
+ export interface SlashCommandSubCommandGroupData extends SharedCommandDataProperties, Pick<SlashCommandData, 'nameLocalizations' | 'descriptionLocalizations'> {
175
175
  type: ApplicationCommandOptionType.SubcommandGroup;
176
176
  options: (SlashCommandSubCommandData | SlashCommandSubcommandBuilder)[];
177
177
  }
178
178
  /**
179
179
  * Message command object data interface
180
180
  */
181
- export interface MessageCommandData<T = unknown> extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties<T>, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute" | "setMetadata" | "halt" | "execute">> {
181
+ export interface MessageCommandData<T = unknown> extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties<T>, 'setCooldown' | 'setRequiredBotPermissions' | 'setRequiredMemberPermissions' | 'setHalt' | 'setExecute' | 'setMetadata' | 'halt' | 'execute'>> {
182
182
  type: CommandBuilderType.MessageCommand;
183
183
  aliases?: string[];
184
184
  validateOptions?: boolean;
@@ -1,7 +1,7 @@
1
1
  import { MessageCommandExecuteData, MessageCommandHaltData } from '../classes/builders/MessageCommandBuilder';
2
2
  import { SlashCommandExecuteData, SlashCommandHaltData } from '../classes/builders/SlashCommandBuilder';
3
- import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
4
- import { CooledDownUser } from '../classes/CommandCooldownManager';
3
+ import { MessageCommandOptionManager } from '../classes/managers/MessageCommandOptionManager';
4
+ import { CooledDownUser } from '../classes/managers/CommandCooldownManager';
5
5
  import { RecipleClient } from '../classes/RecipleClient';
6
6
  import { CommandBuilderType } from '../types/builders';
7
7
  /**
@@ -1,8 +1,6 @@
1
- import { ApplicationCommandBuilder } from '../registerApplicationCommands';
2
- import { ApplicationCommandData, PermissionsBitField } from 'discord.js';
1
+ import { RecipleModule, RecipleScript } from '../classes/managers/ClientModuleManager';
3
2
  import { ConfigCommandPermissions } from '../classes/RecipleConfig';
4
- import { RecipleModule, RecipleScript } from '../modules';
5
- import { RecipleClient } from '../classes/RecipleClient';
3
+ import { PermissionsBitField } from 'discord.js';
6
4
  import { AnyCommandBuilder } from './builders';
7
5
  export interface RecipleClientAddModuleOptions {
8
6
  /**
@@ -16,21 +14,7 @@ export interface RecipleClientAddModuleOptions {
16
14
  /**
17
15
  * Module optional info
18
16
  */
19
- moduleInfo?: RecipleModule["info"];
20
- }
21
- export interface RegisterApplicationCommandsOptions {
22
- /**
23
- * Bot client
24
- */
25
- client: RecipleClient;
26
- /**
27
- * Commands to register
28
- */
29
- commands: (ApplicationCommandData | ApplicationCommandBuilder)[];
30
- /**
31
- * Set guild to not register commands globally
32
- */
33
- guilds?: string | string[];
17
+ moduleInfo?: RecipleModule['info'];
34
18
  }
35
19
  export interface UserHasCommandPermissionsOptions {
36
20
  /**
@@ -49,3 +33,8 @@ export interface UserHasCommandPermissionsOptions {
49
33
  commands: ConfigCommandPermissions[];
50
34
  };
51
35
  }
36
+ export interface ModuleManagerResolveFilesOptions {
37
+ files: string[];
38
+ disabeVersionCheck?: boolean;
39
+ dontSkipError?: boolean;
40
+ }
@@ -1,3 +1,4 @@
1
+ import { AnyCommandBuilder } from './types/builders';
1
2
  /**
2
3
  * Check if an object is a class
3
4
  * @param object Object to identify
@@ -8,3 +9,4 @@ export declare function isClass<T = any>(object: any): object is T;
8
9
  * @param content Warning content
9
10
  */
10
11
  export declare function deprecationWarning(content: string | Error): void;
12
+ export declare function validateCommandBuilder(command: AnyCommandBuilder): boolean;
package/package.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "5.6.0",
4
- "bin": "dist/cjs/bin.js",
3
+ "version": "6.0.0-dev.2",
4
+ "bin": "./dist/cjs/bin.js",
5
5
  "license": "GPL-3.0",
6
- "main": "dist/cjs/index.js",
7
- "typings": "dist/types/index.d.ts",
6
+ "main": "./dist/cjs/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "module": "./dist/mjs/index.js",
8
9
  "author": "FalloutStudios",
9
10
  "description": "Handler for Discord.js",
10
11
  "homepage": "https://reciple.js.org",
12
+ "exports": {
13
+ "require": "./dist/cjs/index.js",
14
+ "import": "./dist/mjs/index.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
11
17
  "keywords": [
12
18
  "Discord",
13
19
  "Discord.js handler",
14
- "Reciple",
15
- "Slash command handler",
16
- "Message command handler"
20
+ "Reciple"
17
21
  ],
18
22
  "contributors": [
19
23
  "GhexterCortes"
@@ -22,10 +26,11 @@
22
26
  "url": "https://github.com/FalloutStudios/reciple/issues"
23
27
  },
24
28
  "scripts": {
29
+ "format": "yarn prettier --write src",
25
30
  "clean": "yarn exec rimraf dist",
26
- "build": "yarn clean && yarn exec tsc",
31
+ "build": "yarn clean && yarn format && yarn exec tsc",
27
32
  "build:publish": "yarn build && yarn docs && yarn npm publish",
28
- "build:publish-prerelease": "yarn build && yarn npm publish --tag pre",
33
+ "build:publish-dev": "yarn build && yarn npm publish --tag dev",
29
34
  "test": "yarn build && yarn workspace test start",
30
35
  "docs": "yarn exec docgen --typescript true -c ./docs/index.json -o ./docs/docs.json -i src/index.ts",
31
36
  "watch": "yarn exec tsc --watch --noEmit"
@@ -41,7 +46,6 @@
41
46
  "files": [
42
47
  "dist",
43
48
  "resource",
44
- "package.json",
45
49
  "LICENSE",
46
50
  "README.md"
47
51
  ],
@@ -49,21 +53,22 @@
49
53
  "chalk": "4.1.2",
50
54
  "commander": "^9.4.1",
51
55
  "dotenv": "^16.0.3",
52
- "fallout-utility": "^1.5.2",
53
- "semver": "^7.3.8",
56
+ "fallout-utility": "^1.5.4",
57
+ "semver": "^7.3.7",
54
58
  "wildcard-match": "^5.1.2",
55
- "yaml": "^2.1.3"
59
+ "yaml": "^2.1.1"
56
60
  },
57
61
  "devDependencies": {
58
62
  "@discordjs/docgen": "^0.12.1",
59
- "@types/node": "^18.8.3",
63
+ "@types/node": "^18.11.0",
60
64
  "@types/semver": "^7.3.12",
61
- "discord.js": "^14.5.0",
65
+ "discord.js": "^14.6.0",
66
+ "prettier": "2.7.1",
62
67
  "rimraf": "^3.0.2",
63
68
  "typescript": "^4.8.4"
64
69
  },
65
70
  "peerDependencies": {
66
- "discord.js": "^14.1.0"
71
+ "discord.js": "^14.5.0"
67
72
  },
68
73
  "workspaces": [
69
74
  "test"
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getModules = void 0;
30
- const builders_1 = require("./types/builders");
31
- const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
32
- const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
33
- const discord_js_1 = require("discord.js");
34
- const version_1 = require("./version");
35
- const fs_1 = require("fs");
36
- const wildcard_match_1 = __importDefault(require("wildcard-match"));
37
- const flags_1 = require("./flags");
38
- const path_1 = __importDefault(require("path"));
39
- /**
40
- * Load modules from folder
41
- * @param client Reciple client
42
- * @param folder Modules folder
43
- */
44
- async function getModules(client, folder) {
45
- const response = { commands: [], modules: [] };
46
- const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
47
- if (!(0, fs_1.existsSync)(modulesDir))
48
- (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
49
- const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
50
- const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
51
- return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
52
- });
53
- for (const script of scripts) {
54
- const modulePath = path_1.default.join(modulesDir, script);
55
- const commands = [];
56
- let module_;
57
- try {
58
- const reqMod = await Promise.resolve().then(() => __importStar(require(modulePath)));
59
- module_ = reqMod?.default !== undefined ? reqMod.default : reqMod;
60
- if (typeof module_ !== 'object')
61
- throw new Error(`Module ${modulePath} is not an object`);
62
- if (!client.config.disableVersionCheck && !module_?.versions?.length)
63
- throw new Error(`${modulePath} does not have supported versions.`);
64
- const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
65
- if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
66
- throw new Error(`${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ') ?? 'none');
67
- if (!await Promise.resolve(module_.onStart(client)).catch(() => false))
68
- throw new Error(script + ' onStart returned false or undefined.');
69
- if (module_.commands) {
70
- for (const command of module_.commands) {
71
- if (command.type === builders_1.CommandBuilderType.MessageCommand) {
72
- commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
73
- }
74
- else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
75
- commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
76
- }
77
- }
78
- }
79
- }
80
- catch (error) {
81
- if (client.isClientLogsEnabled()) {
82
- client.logger.error(`Failed to load module ${script}`);
83
- client.logger.error(error);
84
- }
85
- continue;
86
- }
87
- response.commands.push(...commands.filter((c) => {
88
- if (!c.name) {
89
- if (client.isClientLogsEnabled())
90
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
91
- return false;
92
- }
93
- if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
94
- if (client.isClientLogsEnabled())
95
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
96
- return false;
97
- }
98
- return true;
99
- }));
100
- response.modules.push({
101
- script: module_,
102
- info: {
103
- filename: script,
104
- versions: (0, discord_js_1.normalizeArray)([module_.versions]),
105
- path: modulePath
106
- }
107
- });
108
- if (client.isClientLogsEnabled())
109
- client.logger.info(`Loaded module ${modulePath}`);
110
- }
111
- return response;
112
- }
113
- exports.getModules = getModules;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerApplicationCommands = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
6
- /**
7
- * Register application commands
8
- * @param options Register application commands options
9
- */
10
- async function registerApplicationCommands(options) {
11
- const client = options.client;
12
- const guilds = (0, discord_js_1.normalizeArray)([options.guilds]);
13
- const commands = options.commands ?? client.commands.slashCommands.toJSON().map(cmd => {
14
- if (cmd?.toJSON === undefined)
15
- return (cmd);
16
- if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && client.config.commands.slashCommand.setRequiredPermissions) {
17
- const permissions = client.config.commands.slashCommand.permissions.enabled
18
- ? client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions
19
- : undefined;
20
- if (permissions) {
21
- cmd.setRequiredMemberPermissions(...permissions);
22
- if (client.isClientLogsEnabled())
23
- client.logger.debug(`Set required permissions for ${cmd.name}`);
24
- }
25
- }
26
- return cmd.toJSON();
27
- }) ?? [];
28
- if (!client.isReady())
29
- throw new Error('Client is not ready');
30
- if (!guilds || !guilds?.length) {
31
- client.application?.commands.set(commands).then(() => {
32
- if (client.isClientLogsEnabled())
33
- client.logger.warn('No guilds were specified for application commands. Registered application commands globally.');
34
- });
35
- }
36
- else {
37
- if (client.isClientLogsEnabled())
38
- client.logger.warn(`Registering ${commands.length} application commands to ${guilds.length} guild(s).`);
39
- for (const guild of guilds) {
40
- if (!guild)
41
- continue;
42
- client.application?.commands.set(commands, guild).then(() => {
43
- if (client.isClientLogsEnabled())
44
- client.logger.warn(`Registered ${commands.length} application command(s) for ${guild}.`);
45
- });
46
- }
47
- }
48
- }
49
- exports.registerApplicationCommands = registerApplicationCommands;