reciple 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +22 -6
  2. package/bin/bin.js +3 -3
  3. package/bin/index.d.ts +3 -3
  4. package/bin/index.js +3 -3
  5. package/bin/reciple/classes/CommandCooldownManager.d.ts +15 -1
  6. package/bin/reciple/classes/CommandCooldownManager.js +12 -1
  7. package/bin/reciple/classes/MessageCommandOptionManager.d.ts +10 -0
  8. package/bin/reciple/classes/MessageCommandOptionManager.js +6 -0
  9. package/bin/reciple/classes/RecipleClient.d.ts +49 -15
  10. package/bin/reciple/classes/RecipleClient.js +66 -24
  11. package/bin/reciple/classes/RecipleConfig.d.ts +14 -1
  12. package/bin/reciple/classes/RecipleConfig.js +10 -2
  13. package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +24 -9
  14. package/bin/reciple/classes/builders/InteractionCommandBuilder.js +22 -7
  15. package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +36 -12
  16. package/bin/reciple/classes/builders/MessageCommandBuilder.js +60 -37
  17. package/bin/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +7 -0
  18. package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +7 -0
  19. package/bin/reciple/logger.d.ts +11 -0
  20. package/bin/reciple/logger.js +19 -3
  21. package/bin/reciple/modules.d.ts +11 -3
  22. package/bin/reciple/modules.js +4 -2
  23. package/bin/reciple/permissions.d.ts +8 -3
  24. package/bin/reciple/permissions.js +12 -8
  25. package/bin/reciple/registerInteractionCommands.d.ts +4 -3
  26. package/bin/reciple/registerInteractionCommands.js +7 -5
  27. package/bin/reciple/types/builders.d.ts +13 -4
  28. package/bin/reciple/types/builders.js +3 -0
  29. package/bin/reciple/types/commands.d.ts +20 -14
  30. package/bin/reciple/types/commands.js +3 -0
  31. package/bin/reciple/types/paramOptions.d.ts +14 -7
  32. package/bin/reciple/version.d.ts +6 -5
  33. package/bin/reciple/version.js +5 -3
  34. package/package.json +26 -21
  35. package/resource/reciple.yml +20 -17
package/README.md CHANGED
@@ -1,15 +1,22 @@
1
1
  <h1 align="center">
2
2
  <img src="https://i.imgur.com/DWM0tJL.png" width="50%">
3
3
  <br>
4
- <img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/FalloutStudios/Reciple">
5
- <img alt="GitHub" src="https://img.shields.io/github/license/FalloutStudios/Reciple">
6
- <a href="https://www.codefactor.io/repository/github/falloutstudios/reciple/overview/main"><img src="https://www.codefactor.io/repository/github/falloutstudios/reciple/badge/main" alt="CodeFactor"></a>
7
4
  </h1>
8
5
 
9
- A simple Dicord.js command handler that just works.
6
+ <h3 align="center">
7
+ <a href="https://npmjs.org/package/reciple">
8
+ <img src="https://img.shields.io/npm/v/reciple?label=latest%20npm%20release%20">
9
+ </a>
10
+ <a href="https://github.com/FalloutStudios/Reciple/blob/main/LICENSE">
11
+ <img src="https://img.shields.io/github/license/FalloutStudios/Reciple">
12
+ </a>
13
+ <a href="https://www.codefactor.io/repository/github/falloutstudios/reciple/overview/main">
14
+ <img src="https://www.codefactor.io/repository/github/falloutstudios/reciple/badge/main">
15
+ </a>
10
16
 
11
- # Join Discord
12
- [![Discord Invite](https://i.imgur.com/GffJByO.png)](https://discord.gg/2CattJYNpw)
17
+ A simple Dicord.js handler that just works.<h3>
18
+
19
+ ****
13
20
 
14
21
  ## Installation
15
22
  To install the bot, run the following command in your terminal:
@@ -51,6 +58,9 @@ You can override the given token using your terminal
51
58
  ```bash
52
59
  npx reciple --token "YOUR_TOKEN_HERE"
53
60
  ```
61
+ ```bash
62
+ npx reciple --token "env:TOKEN_VARIABLE"
63
+ ```
54
64
 
55
65
  ## Starting the bot
56
66
  To start the bot, run the following command:
@@ -62,4 +72,10 @@ npx reciple
62
72
  > ## Fun Fact
63
73
  > The name reciple is from a minecraft bug. The bug was a misspelling of the word `recipe`. [View Mojang Bug Report](https://bugs.mojang.com/browse/MC-225837)
64
74
 
75
+
76
+ # Join Discord
77
+ [![Discord Invite](https://i.imgur.com/GffJByO.png)](https://discord.gg/2CattJYNpw)
78
+
79
+ ****
80
+
65
81
  [#letTheEarthBreathe](https://rebellion.global/)
package/bin/bin.js CHANGED
@@ -11,12 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  var _a, _b;
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- const RecipleConfig_1 = require("./reciple/classes/RecipleConfig");
15
14
  const RecipleClient_1 = require("./reciple/classes/RecipleClient");
16
- const fs_1 = require("fs");
17
- const version_1 = require("./reciple/version");
15
+ const RecipleConfig_1 = require("./reciple/classes/RecipleConfig");
18
16
  const flags_1 = require("./reciple/flags");
17
+ const version_1 = require("./reciple/version");
19
18
  const fallout_utility_1 = require("fallout-utility");
19
+ const fs_1 = require("fs");
20
20
  require("dotenv/config");
21
21
  if (flags_1.flags.version) {
22
22
  console.log(`v${version_1.version}`);
package/bin/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export * from './reciple/classes/RecipleClient';
2
- export * from './reciple/classes/RecipleConfig';
3
1
  export * from './reciple/classes/CommandCooldownManager';
4
2
  export * from './reciple/classes/MessageCommandOptionManager';
3
+ export * from './reciple/classes/RecipleClient';
4
+ export * from './reciple/classes/RecipleConfig';
5
5
  export * from './reciple/classes/builders/InteractionCommandBuilder';
6
6
  export * from './reciple/classes/builders/MessageCommandBuilder';
7
7
  export * from './reciple/classes/builders/MessageCommandOptionBuilder';
8
8
  export * from './reciple/types/builders';
9
9
  export * from './reciple/types/commands';
10
10
  export * from './reciple/types/paramOptions';
11
- export * from './reciple/permissions';
12
11
  export * from './reciple/flags';
13
12
  export * from './reciple/logger';
14
13
  export * from './reciple/modules';
14
+ export * from './reciple/permissions';
15
15
  export * from './reciple/registerInteractionCommands';
16
16
  export * from './reciple/version';
package/bin/index.js CHANGED
@@ -14,19 +14,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./reciple/classes/RecipleClient"), exports);
18
- __exportStar(require("./reciple/classes/RecipleConfig"), exports);
19
17
  __exportStar(require("./reciple/classes/CommandCooldownManager"), exports);
20
18
  __exportStar(require("./reciple/classes/MessageCommandOptionManager"), exports);
19
+ __exportStar(require("./reciple/classes/RecipleClient"), exports);
20
+ __exportStar(require("./reciple/classes/RecipleConfig"), exports);
21
21
  __exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
22
22
  __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
23
23
  __exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
24
24
  __exportStar(require("./reciple/types/builders"), exports);
25
25
  __exportStar(require("./reciple/types/commands"), exports);
26
26
  __exportStar(require("./reciple/types/paramOptions"), exports);
27
- __exportStar(require("./reciple/permissions"), exports);
28
27
  __exportStar(require("./reciple/flags"), exports);
29
28
  __exportStar(require("./reciple/logger"), exports);
30
29
  __exportStar(require("./reciple/modules"), exports);
30
+ __exportStar(require("./reciple/permissions"), exports);
31
31
  __exportStar(require("./reciple/registerInteractionCommands"), exports);
32
32
  __exportStar(require("./reciple/version"), exports);
@@ -1,5 +1,8 @@
1
1
  import { RecipleCommandBuilderType } from '../types/builders';
2
2
  import { Guild, TextBasedChannel, User } from 'discord.js';
3
+ /**
4
+ * Object interface for cooled-down user
5
+ */
3
6
  export interface CooledDownUser {
4
7
  user: User;
5
8
  command: string;
@@ -8,29 +11,40 @@ export interface CooledDownUser {
8
11
  channel?: TextBasedChannel;
9
12
  expireTime: number;
10
13
  }
14
+ /**
15
+ * Stores cooled-down users
16
+ */
11
17
  export declare class CommandCooldownManager extends Array<CooledDownUser> {
12
18
  /**
13
19
  * Alias for `CommandCooldownManager#push()`
20
+ * @param options Cooled-down user data
14
21
  */
15
22
  add(...options: CooledDownUser[]): number;
16
23
  /**
17
24
  * Remove cooldown from specific user, channel or guild
25
+ * @param options Remove cooldown data options
26
+ * @param limit Remove cooldown data limit
18
27
  */
19
28
  remove(options: Partial<CooledDownUser>, limit?: number): void;
20
29
  /**
21
30
  * Check if the given user is cooled-down
31
+ * @param options Options to identify if user is on cooldown
22
32
  */
23
33
  isCooledDown(options: Partial<Omit<CooledDownUser, 'expireTime'>>): boolean;
24
34
  /**
25
- * Clear non cooled-down users from this array
35
+ * Purge non cooled-down users from this array
36
+ * @param options Clean cooldown options
26
37
  */
27
38
  clean(options?: Partial<Omit<CooledDownUser, 'expireTime'>>): void;
28
39
  /**
29
40
  * Get someone's cooldown data
41
+ * @param options Get cooldown data options
30
42
  */
31
43
  get(options: Partial<Omit<CooledDownUser, 'expireTime'>>): CooledDownUser | undefined;
32
44
  /**
33
45
  * Check if the options are valid
46
+ * @param options Options to validated
47
+ * @param data Cooled-down user data
34
48
  */
35
49
  static checkOptions(options: Partial<Omit<CooledDownUser, 'expireTime'>>, data: CooledDownUser): boolean;
36
50
  }
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandCooldownManager = void 0;
4
+ /**
5
+ * Stores cooled-down users
6
+ */
4
7
  class CommandCooldownManager extends Array {
5
8
  /**
6
9
  * Alias for `CommandCooldownManager#push()`
10
+ * @param options Cooled-down user data
7
11
  */
8
12
  add(...options) {
9
13
  return this.push(...options);
10
14
  }
11
15
  /**
12
16
  * Remove cooldown from specific user, channel or guild
17
+ * @param options Remove cooldown data options
18
+ * @param limit Remove cooldown data limit
13
19
  */
14
20
  remove(options, limit = 0) {
15
21
  if (!Object.keys(options).length)
@@ -28,6 +34,7 @@ class CommandCooldownManager extends Array {
28
34
  }
29
35
  /**
30
36
  * Check if the given user is cooled-down
37
+ * @param options Options to identify if user is on cooldown
31
38
  */
32
39
  isCooledDown(options) {
33
40
  const data = this.get(options);
@@ -39,7 +46,8 @@ class CommandCooldownManager extends Array {
39
46
  return true;
40
47
  }
41
48
  /**
42
- * Clear non cooled-down users from this array
49
+ * Purge non cooled-down users from this array
50
+ * @param options Clean cooldown options
43
51
  */
44
52
  clean(options) {
45
53
  for (const index in this) {
@@ -52,12 +60,15 @@ class CommandCooldownManager extends Array {
52
60
  }
53
61
  /**
54
62
  * Get someone's cooldown data
63
+ * @param options Get cooldown data options
55
64
  */
56
65
  get(options) {
57
66
  return this.find(data => CommandCooldownManager.checkOptions(options, data));
58
67
  }
59
68
  /**
60
69
  * Check if the options are valid
70
+ * @param options Options to validated
71
+ * @param data Cooled-down user data
61
72
  */
62
73
  static checkOptions(options, data) {
63
74
  var _a, _b;
@@ -1,13 +1,23 @@
1
1
  import { MessageCommandValidatedOption } from './builders/MessageCommandBuilder';
2
+ /**
3
+ * Validated message options manager
4
+ */
2
5
  export declare class MessageCommandOptionManager extends Array<MessageCommandValidatedOption> {
6
+ /**
7
+ * @param options Validated options
8
+ */
3
9
  constructor(options: MessageCommandValidatedOption[]);
4
10
  /**
5
11
  * Get the option info
12
+ * @param name Option name
13
+ * @param requied Is the option required
6
14
  */
7
15
  get(name: string, requied: true): MessageCommandValidatedOption;
8
16
  get(name: string, requied?: boolean): MessageCommandValidatedOption | null;
9
17
  /**
10
18
  * Get the option value
19
+ * @param name Option name
20
+ * @param requied Is the option required
11
21
  */
12
22
  getValue(name: string, requied: true): string;
13
23
  getValue(name: string, requied?: boolean): string | null;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MessageCommandOptionManager = void 0;
4
+ /**
5
+ * Validated message options manager
6
+ */
4
7
  class MessageCommandOptionManager extends Array {
8
+ /**
9
+ * @param options Validated options
10
+ */
5
11
  constructor(options) {
6
12
  super();
7
13
  this.push(...options);
@@ -1,16 +1,22 @@
1
- import { RecipleCommandBuilders, RecipleCommandBuilderType } from '../types/builders';
2
- import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from './builders/InteractionCommandBuilder';
3
- import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from './builders/MessageCommandBuilder';
4
- import { InteractionBuilder } from '../registerInteractionCommands';
5
- import { CommandCooldownManager } from './CommandCooldownManager';
6
- import { Logger as ILogger } from 'fallout-utility';
7
- import { AddModuleOptions } from '../types/paramOptions';
8
1
  import { RecipleModule } from '../modules';
2
+ import { ApplicationCommandBuilder } from '../registerInteractionCommands';
3
+ import { RecipleCommandBuilder, RecipleCommandBuilderType } from '../types/builders';
4
+ import { RecipleAddModuleOptions } from '../types/paramOptions';
5
+ import { InteractionCommandBuilder, InteractionCommandExecuteData } from './builders/InteractionCommandBuilder';
6
+ import { MessageCommandBuilder, MessageCommandExecuteData } from './builders/MessageCommandBuilder';
7
+ import { CommandCooldownManager } from './CommandCooldownManager';
9
8
  import { Config } from './RecipleConfig';
10
- import { ApplicationCommandData, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
9
+ import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
10
+ import { Logger as ILogger } from 'fallout-utility';
11
+ /**
12
+ * options for Reciple client
13
+ */
11
14
  export interface RecipleClientOptions extends ClientOptions {
12
15
  config?: Config;
13
16
  }
17
+ /**
18
+ * Reciple client commands object interface
19
+ */
14
20
  export interface RecipleClientCommands {
15
21
  messageCommands: {
16
22
  [commandName: string]: MessageCommandBuilder;
@@ -19,11 +25,17 @@ export interface RecipleClientCommands {
19
25
  [commandName: string]: InteractionCommandBuilder;
20
26
  };
21
27
  }
28
+ /**
29
+ * Reciple client events
30
+ */
22
31
  export interface RecipleClientEvents extends ClientEvents {
23
- recipleMessageCommandCreate: [executeData: RecipleMessageCommandExecuteData];
24
- recipleInteractionCommandCreate: [executeData: RecipleInteractionCommandExecuteData];
32
+ recipleMessageCommandCreate: [executeData: MessageCommandExecuteData];
33
+ recipleInteractionCommandCreate: [executeData: InteractionCommandExecuteData];
25
34
  recipleReplyError: [error: unknown];
26
35
  }
36
+ /**
37
+ * Create new Reciple client
38
+ */
27
39
  export interface RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
28
40
  on<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
29
41
  on<E extends string | symbol>(event: Exclude<E, keyof RecipleClientEvents>, listener: (...args: any) => Awaitable<void>): this;
@@ -40,14 +52,18 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
40
52
  export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
41
53
  config: Config;
42
54
  commands: RecipleClientCommands;
43
- otherApplicationCommandData: (InteractionBuilder | ApplicationCommandData)[];
55
+ otherApplicationCommandData: (ApplicationCommandBuilder | ApplicationCommandData)[];
44
56
  commandCooldowns: CommandCooldownManager;
45
57
  modules: RecipleModule[];
46
58
  logger: ILogger;
47
59
  version: string;
60
+ /**
61
+ * @param options Client options
62
+ */
48
63
  constructor(options: RecipleClientOptions);
49
64
  /**
50
65
  * Load modules from modules folder
66
+ * @param folder Modules folder
51
67
  */
52
68
  startModules(folder?: string): Promise<RecipleClient<Ready>>;
53
69
  /**
@@ -56,30 +72,39 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
56
72
  loadModules(): Promise<RecipleClient<Ready>>;
57
73
  /**
58
74
  * Add module
75
+ * @param options Module options
59
76
  */
60
- addModule(options: AddModuleOptions): Promise<void>;
77
+ addModule(options: RecipleAddModuleOptions): Promise<void>;
61
78
  /**
62
79
  * Add interaction or message command to client
80
+ * @param command Interaction/Message command builder
63
81
  */
64
- addCommand(command: RecipleCommandBuilders): RecipleClient<Ready>;
82
+ addCommand(command: RecipleCommandBuilder): RecipleClient<Ready>;
65
83
  /**
66
84
  * Listed to command executions
67
85
  */
68
86
  addCommandListeners(): RecipleClient<Ready>;
69
87
  /**
70
88
  * Execute a Message command
89
+ * @param message Message command executor
90
+ * @param prefix Message command prefix
71
91
  */
72
- messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecuteData>;
92
+ messageCommandExecute(message: Message, prefix?: string): Promise<void | MessageCommandExecuteData>;
73
93
  /**
74
94
  * Execute an Interaction command
95
+ * @param interaction Command Interaction
75
96
  */
76
- interactionCommandExecute(interaction: Interaction | CommandInteraction): Promise<void | RecipleInteractionCommandExecuteData>;
97
+ interactionCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | InteractionCommandExecuteData>;
77
98
  /**
78
99
  * Get a message from config
100
+ * @param messageKey Config messages key
101
+ * @param defaultMessage Default message when the key does not exists
79
102
  */
80
103
  getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
81
104
  /**
82
105
  * Get command builder by name or alias if it's a message command
106
+ * @param command Command name
107
+ * @param type Command type
83
108
  */
84
109
  findCommand(command: string, type: RecipleCommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
85
110
  findCommand(command: string, type: RecipleCommandBuilderType.InteractionCommand): InteractionCommandBuilder | undefined;
@@ -89,10 +114,19 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
89
114
  isClientLogsEnabled(): boolean;
90
115
  /**
91
116
  * Emits the "recipleReplyError" event
117
+ * @param error Received Error
92
118
  */
93
119
  private _replyError;
120
+ /**
121
+ * Executes command halt function
122
+ * @param command Halted command's builder
123
+ * @param haltData Halted command's data
124
+ */
125
+ private _haltCommand;
94
126
  /**
95
127
  * Error message when a command fails to execute
128
+ * @param err Received error
129
+ * @param command Interaction/Message command execute data
96
130
  */
97
131
  private _commandExecuteError;
98
132
  }
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // Not cool code
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,19 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
10
  };
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.RecipleClient = void 0;
14
- const builders_1 = require("../types/builders");
13
+ // Not cool code
14
+ const logger_1 = require("../logger");
15
+ const modules_1 = require("../modules");
15
16
  const permissions_1 = require("../permissions");
16
17
  const registerInteractionCommands_1 = require("../registerInteractionCommands");
18
+ const builders_1 = require("../types/builders");
19
+ const commands_1 = require("../types/commands");
20
+ const version_1 = require("../version");
21
+ const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
17
22
  const CommandCooldownManager_1 = require("./CommandCooldownManager");
18
23
  const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
19
- const fallout_utility_1 = require("fallout-utility");
20
- const commands_1 = require("../types/commands");
21
- const modules_1 = require("../modules");
22
24
  const RecipleConfig_1 = require("./RecipleConfig");
23
- const version_1 = require("../version");
24
- const logger_1 = require("../logger");
25
25
  const discord_js_1 = require("discord.js");
26
+ const fallout_utility_1 = require("fallout-utility");
26
27
  class RecipleClient extends discord_js_1.Client {
28
+ /**
29
+ * @param options Client options
30
+ */
27
31
  constructor(options) {
28
32
  var _a, _b, _c;
29
33
  super(options);
@@ -33,7 +37,7 @@ class RecipleClient extends discord_js_1.Client {
33
37
  this.commandCooldowns = new CommandCooldownManager_1.CommandCooldownManager();
34
38
  this.modules = [];
35
39
  this.version = version_1.version;
36
- this.logger = (0, logger_1.logger)(!!((_a = options.config) === null || _a === void 0 ? void 0 : _a.fileLogging.stringifyLoggedJSON), !!((_b = options.config) === null || _b === void 0 ? void 0 : _b.fileLogging.debugmode));
40
+ this.logger = (0, logger_1.createLogger)(!!((_a = options.config) === null || _a === void 0 ? void 0 : _a.fileLogging.stringifyLoggedJSON), !!((_b = options.config) === null || _b === void 0 ? void 0 : _b.fileLogging.debugmode));
37
41
  if (!options.config)
38
42
  throw new Error('Config is not defined.');
39
43
  this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
@@ -42,6 +46,7 @@ class RecipleClient extends discord_js_1.Client {
42
46
  }
43
47
  /**
44
48
  * Load modules from modules folder
49
+ * @param folder Modules folder
45
50
  */
46
51
  startModules(folder) {
47
52
  return __awaiter(this, void 0, void 0, function* () {
@@ -95,6 +100,7 @@ class RecipleClient extends discord_js_1.Client {
95
100
  }
96
101
  /**
97
102
  * Add module
103
+ * @param options Module options
98
104
  */
99
105
  addModule(options) {
100
106
  var _a;
@@ -125,6 +131,7 @@ class RecipleClient extends discord_js_1.Client {
125
131
  }
126
132
  /**
127
133
  * Add interaction or message command to client
134
+ * @param command Interaction/Message command builder
128
135
  */
129
136
  addCommand(command) {
130
137
  var _a;
@@ -151,6 +158,8 @@ class RecipleClient extends discord_js_1.Client {
151
158
  }
152
159
  /**
153
160
  * Execute a Message command
161
+ * @param message Message command executor
162
+ * @param prefix Message command prefix
154
163
  */
155
164
  messageCommandExecute(message, prefix) {
156
165
  var _a;
@@ -163,15 +172,19 @@ class RecipleClient extends discord_js_1.Client {
163
172
  const command = this.findCommand(parseCommand.command, builders_1.RecipleCommandBuilderType.MessageCommand);
164
173
  if (!command)
165
174
  return;
166
- const commandOptions = command.getCommandOptionValues(parseCommand);
175
+ const commandOptions = (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
167
176
  const executeData = {
168
177
  message: message,
169
- options: new MessageCommandOptionManager_1.MessageCommandOptionManager(commandOptions),
178
+ options: commandOptions,
170
179
  command: parseCommand,
171
180
  builder: command,
172
181
  client: this
173
182
  };
174
- if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions, this.config.commands.messageCommand.permissions, command)) {
183
+ if ((0, permissions_1.userHasCommandPermissions)({
184
+ builder: command,
185
+ memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
186
+ commandPermissions: this.config.commands.messageCommand.permissions
187
+ })) {
175
188
  if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM
176
189
  || !command.allowExecuteByBots
177
190
  && (message.author.bot || message.author.system)
@@ -185,14 +198,14 @@ class RecipleClient extends discord_js_1.Client {
185
198
  return;
186
199
  }
187
200
  if (commandOptions.some(o => o.missing)) {
188
- if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.missing)) }))) {
201
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.missing)) }))) {
189
202
  message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
190
203
  }
191
204
  return;
192
205
  }
193
206
  }
194
207
  if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
195
- if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
208
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
196
209
  message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
197
210
  }
198
211
  return;
@@ -208,7 +221,7 @@ class RecipleClient extends discord_js_1.Client {
208
221
  this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
209
222
  }
210
223
  else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
211
- if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
224
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
212
225
  yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
213
226
  }
214
227
  return;
@@ -216,27 +229,28 @@ class RecipleClient extends discord_js_1.Client {
216
229
  try {
217
230
  yield Promise.resolve(command.execute(executeData))
218
231
  .then(() => this.emit('recipleMessageCommandCreate', executeData))
219
- .catch((err) => __awaiter(this, void 0, void 0, function* () { return !command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
232
+ .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
220
233
  return executeData;
221
234
  }
222
235
  catch (err) {
223
- if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
236
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
224
237
  this._commandExecuteError(err, executeData);
225
238
  }
226
239
  }
227
240
  }
228
- else if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
241
+ else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
229
242
  message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
230
243
  }
231
244
  });
232
245
  }
233
246
  /**
234
247
  * Execute an Interaction command
248
+ * @param interaction Command Interaction
235
249
  */
236
250
  interactionCommandExecute(interaction) {
237
251
  var _a, _b;
238
252
  return __awaiter(this, void 0, void 0, function* () {
239
- if (!interaction || interaction.type !== discord_js_1.InteractionType.ApplicationCommand || !this.isReady())
253
+ if (!interaction || interaction.type !== discord_js_1.InteractionType.ApplicationCommand || !interaction.isChatInputCommand() || !this.isReady())
240
254
  return;
241
255
  const command = this.findCommand(interaction.commandName, builders_1.RecipleCommandBuilderType.InteractionCommand);
242
256
  if (!command)
@@ -246,11 +260,15 @@ class RecipleClient extends discord_js_1.Client {
246
260
  builder: command,
247
261
  client: this
248
262
  };
249
- if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.commands.interactionCommand.permissions, command)) {
263
+ if ((0, permissions_1.userHasCommandPermissions)({
264
+ builder: command,
265
+ memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
266
+ commandPermissions: this.config.commands.interactionCommand.permissions
267
+ })) {
250
268
  if (!command || (0, permissions_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
251
269
  return;
252
270
  if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
253
- if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
271
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
254
272
  yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
255
273
  }
256
274
  return;
@@ -266,7 +284,7 @@ class RecipleClient extends discord_js_1.Client {
266
284
  this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
267
285
  }
268
286
  else if (this.config.commands.interactionCommand.enableCooldown && command.cooldown) {
269
- if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
287
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
270
288
  yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
271
289
  }
272
290
  return;
@@ -274,22 +292,24 @@ class RecipleClient extends discord_js_1.Client {
274
292
  try {
275
293
  yield Promise.resolve(command.execute(executeData))
276
294
  .then(() => this.emit('recipleInteractionCommandCreate', executeData))
277
- .catch((err) => __awaiter(this, void 0, void 0, function* () { return !command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
295
+ .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
278
296
  return executeData;
279
297
  }
280
298
  catch (err) {
281
- if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
299
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
282
300
  this._commandExecuteError(err, executeData);
283
301
  }
284
302
  }
285
303
  }
286
- else if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
304
+ else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
287
305
  yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
288
306
  }
289
307
  });
290
308
  }
291
309
  /**
292
310
  * Get a message from config
311
+ * @param messageKey Config messages key
312
+ * @param defaultMessage Default message when the key does not exists
293
313
  */
294
314
  getMessage(messageKey, defaultMessage) {
295
315
  var _a, _b;
@@ -316,12 +336,34 @@ class RecipleClient extends discord_js_1.Client {
316
336
  }
317
337
  /**
318
338
  * Emits the "recipleReplyError" event
339
+ * @param error Received Error
319
340
  */
320
341
  _replyError(error) {
321
342
  this.emit('recipleReplyError', error);
322
343
  }
344
+ _haltCommand(command, haltData) {
345
+ var _a;
346
+ return __awaiter(this, void 0, void 0, function* () {
347
+ try {
348
+ return (_a = (command.halt
349
+ ? yield (command.builder == builders_1.RecipleCommandBuilderType.InteractionCommand
350
+ ? Promise.resolve(command.halt(haltData))
351
+ : Promise.resolve(command.halt(haltData))).catch(() => false)
352
+ : false)) !== null && _a !== void 0 ? _a : false;
353
+ }
354
+ catch (err) {
355
+ if (this.isClientLogsEnabled()) {
356
+ this.logger.error(`Halt command "${command.name}" execute error`);
357
+ this.logger.error(err);
358
+ }
359
+ return false;
360
+ }
361
+ });
362
+ }
323
363
  /**
324
364
  * Error message when a command fails to execute
365
+ * @param err Received error
366
+ * @param command Interaction/Message command execute data
325
367
  */
326
368
  _commandExecuteError(err, command) {
327
369
  return __awaiter(this, void 0, void 0, function* () {