reciple 4.0.0 → 4.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.
@@ -171,7 +171,7 @@ class RecipleClient extends discord_js_1.Client {
171
171
  const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
172
172
  if (!command)
173
173
  return;
174
- const commandOptions = (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
174
+ const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
175
175
  const executeData = {
176
176
  message: message,
177
177
  options: commandOptions,
@@ -72,7 +72,7 @@ export declare class RecipleConfig {
72
72
  /**
73
73
  * Parse the config file
74
74
  */
75
- parseConfig(): RecipleConfig;
75
+ parseConfig(): this;
76
76
  /**
77
77
  * Returns the parsed config file
78
78
  */
@@ -1,9 +1,8 @@
1
+ import { CommandBuilderType, CommandExecuteFunction, CommandHaltFunction } from '../../types/builders';
1
2
  import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
2
3
  import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
3
- import { Awaitable, Message, PermissionResolvable } from 'discord.js';
4
4
  import { Command as CommandMessage } from 'fallout-utility';
5
- import { CommandBuilderType } from '../../types/builders';
6
- import { HaltedCommandData } from '../../types/commands';
5
+ import { Message, PermissionResolvable } from 'discord.js';
7
6
  import { RecipleClient } from '../RecipleClient';
8
7
  /**
9
8
  * Execute data for message command
@@ -40,68 +39,68 @@ export declare class MessageCommandBuilder {
40
39
  requiredMemberPermissions: PermissionResolvable[];
41
40
  allowExecuteInDM: boolean;
42
41
  allowExecuteByBots: boolean;
43
- halt?: (haltData: HaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>;
44
- execute: (executeData: MessageCommandExecuteData) => void;
42
+ halt?: CommandHaltFunction<this>;
43
+ execute: CommandExecuteFunction<this>;
45
44
  /**
46
45
  * Sets the command name
47
46
  * @param name Command name
48
47
  */
49
- setName(name: string): MessageCommandBuilder;
48
+ setName(name: string): this;
50
49
  /**
51
50
  * Sets the command description
52
51
  * @param description Command description
53
52
  */
54
- setDescription(description: string): MessageCommandBuilder;
53
+ setDescription(description: string): this;
55
54
  /**
56
55
  * Sets the execute cooldown for this command.
57
56
  * - `0` means no cooldown
58
57
  * @param cooldown Command cooldown in milliseconds
59
58
  */
60
- setCooldown(cooldown: number): MessageCommandBuilder;
59
+ setCooldown(cooldown: number): this;
61
60
  /**
62
61
  * Add aliases to the command
63
62
  * @param aliases Command aliases
64
63
  */
65
- addAliases(...aliases: string[]): MessageCommandBuilder;
64
+ addAliases(...aliases: string[]): this;
66
65
  /**
67
66
  * Set required bot permissions to execute the command
68
67
  * @param permissions Bot's required permissions
69
68
  */
70
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): MessageCommandBuilder;
69
+ setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
71
70
  /**
72
71
  * Set required permissions to execute the command
73
72
  * @param permissions User's return permissions
74
73
  */
75
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): MessageCommandBuilder;
74
+ setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
76
75
  /**
77
76
  * Set if command can be executed in dms
78
77
  * @param allowExecuteInDM `true` if the command can execute in DMs
79
78
  */
80
- setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
79
+ setAllowExecuteInDM(allowExecuteInDM: boolean): this;
81
80
  /**
82
81
  * Allow command to be executed by bots
83
82
  * @param allowExecuteByBots `true` if the command can be executed by bots
84
83
  */
85
- setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
84
+ setAllowExecuteByBots(allowExecuteByBots: boolean): this;
86
85
  /**
87
86
  * Function when the command is interupted
88
87
  * @param halt Function to execute when command is halted
89
88
  */
90
- setHalt(halt?: (haltData: HaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>): MessageCommandBuilder;
89
+ setHalt(halt?: CommandHaltFunction<this>): this;
91
90
  /**
92
91
  * Function when the command is executed
93
92
  * @param execute Function to execute when the command is called
94
93
  */
95
- setExecute(execute: (executeData: MessageCommandExecuteData) => void): MessageCommandBuilder;
94
+ setExecute(execute: CommandExecuteFunction<this>): this;
96
95
  /**
97
96
  * Add option to the command
98
97
  * @param option Message option builder
99
98
  */
100
- addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
99
+ addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): this;
101
100
  /**
102
101
  * Validate options before executing
103
102
  * @param validateOptions `true` if the command options needs to be validated before executing
104
103
  */
105
- setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
104
+ setValidateOptions(validateOptions: boolean): this;
106
105
  }
107
- export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: CommandMessage): MessageCommandOptionManager;
106
+ export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: CommandMessage): Promise<MessageCommandOptionManager>;
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
13
+ const builders_1 = require("../../types/builders");
4
14
  const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
5
15
  const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
6
- const builders_1 = require("../../types/builders");
7
16
  /**
8
17
  * Reciple builder for message command
9
18
  */
@@ -147,36 +156,38 @@ class MessageCommandBuilder {
147
156
  }
148
157
  exports.MessageCommandBuilder = MessageCommandBuilder;
149
158
  function validateMessageCommandOptions(builder, options) {
150
- const args = options.args || [];
151
- const required = builder.options.filter(o => o.required);
152
- const optional = builder.options.filter(o => !o.required);
153
- const allOptions = [...required, ...optional];
154
- const result = [];
155
- let i = 0;
156
- for (const option of allOptions) {
157
- const arg = args[i];
158
- const value = {
159
- name: option.name,
160
- value: arg !== null && arg !== void 0 ? arg : undefined,
161
- required: option.required,
162
- invalid: false,
163
- missing: false
164
- };
165
- if (arg == undefined && option.required) {
166
- value.missing = true;
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ const args = options.args || [];
161
+ const required = builder.options.filter(o => o.required);
162
+ const optional = builder.options.filter(o => !o.required);
163
+ const allOptions = [...required, ...optional];
164
+ const result = [];
165
+ let i = 0;
166
+ for (const option of allOptions) {
167
+ const arg = args[i];
168
+ const value = {
169
+ name: option.name,
170
+ value: arg !== null && arg !== void 0 ? arg : undefined,
171
+ required: option.required,
172
+ invalid: false,
173
+ missing: false
174
+ };
175
+ if (arg == undefined && option.required) {
176
+ value.missing = true;
177
+ result.push(value);
178
+ continue;
179
+ }
180
+ if (arg == undefined && !option.required) {
181
+ result.push(value);
182
+ continue;
183
+ }
184
+ const validate = option.validator ? yield Promise.resolve(option.validator(arg)) : true;
185
+ if (!validate)
186
+ value.invalid = true;
167
187
  result.push(value);
168
- continue;
188
+ i++;
169
189
  }
170
- if (arg == undefined && !option.required) {
171
- result.push(value);
172
- continue;
173
- }
174
- const validate = option.validator ? option.validator(arg) : true;
175
- if (!validate)
176
- value.invalid = true;
177
- result.push(value);
178
- i++;
179
- }
180
- return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
190
+ return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
191
+ });
181
192
  }
182
193
  exports.validateMessageCommandOptions = validateMessageCommandOptions;
@@ -1,3 +1,4 @@
1
+ import { Awaitable } from 'discord.js';
1
2
  /**
2
3
  * Option builder for MessageCommandBuilder
3
4
  */
@@ -5,25 +6,25 @@ export declare class MessageCommandOptionBuilder {
5
6
  name: string;
6
7
  description: string;
7
8
  required: boolean;
8
- validator: (value: string) => boolean;
9
+ validator: (value: string) => Awaitable<boolean>;
9
10
  /**
10
11
  * Set command option name
11
12
  * @param name Option name
12
13
  */
13
- setName(name: string): MessageCommandOptionBuilder;
14
+ setName(name: string): this;
14
15
  /**
15
16
  * Set command option description
16
17
  * @param description Option description
17
18
  */
18
- setDescription(description: string): MessageCommandOptionBuilder;
19
+ setDescription(description: string): this;
19
20
  /**
20
21
  * Set if this option is required
21
22
  * @param required `true` if this option is required
22
23
  */
23
- setRequired(required: boolean): MessageCommandOptionBuilder;
24
+ setRequired(required: boolean): this;
24
25
  /**
25
26
  * Set your custom function to validate given value for this option
26
27
  * @param validator Custom function to validate value given for this option
27
28
  */
28
- setValidator(validator: (value: string) => boolean): MessageCommandOptionBuilder;
29
+ setValidator(validator: (value: string) => Awaitable<boolean>): this;
29
30
  }
@@ -1,7 +1,6 @@
1
- import { CommandBuilderType } from '../../types/builders';
2
- import { HaltedCommandData } from '../../types/commands';
1
+ import { CommandBuilderType, CommandExecuteFunction, CommandHaltFunction } from '../../types/builders';
3
2
  import { RecipleClient } from '../RecipleClient';
4
- import { Awaitable, ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
3
+ import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
5
4
  /**
6
5
  * Execute data for interaction command
7
6
  */
@@ -25,32 +24,32 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
25
24
  requiredBotPermissions: PermissionResolvable[];
26
25
  requiredMemberPermissions: PermissionResolvable[];
27
26
  allowExecuteInDM: boolean;
28
- halt?: (haltData: HaltedCommandData<SlashCommandBuilder>) => Awaitable<boolean | void>;
29
- execute: (executeData: SlashCommandExecuteData) => Awaitable<void>;
27
+ halt?: CommandHaltFunction<this>;
28
+ execute: CommandExecuteFunction<this>;
30
29
  /**
31
30
  * Sets the execute cooldown for this command.
32
31
  * - `0` means no cooldown
33
32
  * @param cooldown Command cooldown in milliseconds
34
33
  */
35
- setCooldown(cooldown: number): SlashCommandBuilder;
34
+ setCooldown(cooldown: number): this;
36
35
  /**
37
36
  * Set required bot permissions to execute the command
38
37
  * @param permissions Bot's required permissions
39
38
  */
40
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): SlashCommandBuilder;
39
+ setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
41
40
  /**
42
41
  * Set required permissions to execute the command
43
42
  * @param permissions User's return permissions
44
43
  */
45
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): SlashCommandBuilder;
44
+ setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
46
45
  /**
47
46
  * Function when the command is interupted
48
47
  * @param halt Function to execute when command is halted
49
48
  */
50
- setHalt(halt?: (haltData: HaltedCommandData<SlashCommandBuilder>) => Awaitable<boolean | void>): SlashCommandBuilder;
49
+ setHalt(halt?: CommandHaltFunction<this>): this;
51
50
  /**
52
51
  * Function when the command is executed
53
52
  * @param execute Function to execute when the command is called
54
53
  */
55
- setExecute(execute: (executeData: SlashCommandExecuteData) => void): SlashCommandBuilder;
54
+ setExecute(execute: CommandExecuteFunction<this>): this;
56
55
  }
@@ -1,5 +1,7 @@
1
+ import { Awaitable } from 'discord.js';
1
2
  import { MessageCommandBuilder, MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
2
3
  import { SlashCommandBuilder, SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
4
+ import { HaltedCommandData } from './commands';
3
5
  /**
4
6
  * Reciple command builders
5
7
  */
@@ -8,6 +10,14 @@ export declare type CommandBuilder = MessageCommandBuilder | SlashCommandBuilder
8
10
  * Reciple command builders execute data
9
11
  */
10
12
  export declare type CommandBuilderExecuteData = SlashCommandExecuteData | MessageCommandExecuteData;
13
+ /**
14
+ * Reciple command halt function
15
+ */
16
+ export declare type CommandHaltFunction<Builder extends CommandBuilder> = (haltData: HaltedCommandData<Builder>) => Awaitable<boolean | null | undefined | void>;
17
+ /**
18
+ * Reciple command execute function
19
+ */
20
+ export declare type CommandExecuteFunction<Builder extends CommandBuilder> = (executeData: Builder extends MessageCommandBuilder ? MessageCommandExecuteData : SlashCommandExecuteData) => Awaitable<void>;
11
21
  /**
12
22
  * Types of Reciple command builders
13
23
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "bin": "bin/bin.js",
5
5
  "license": "GPL-3.0",
6
6
  "main": "bin/index.js",