reciple 2.0.0-pre.1 → 3.0.0-pre.1
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/README.md +10 -11
- package/bin/index.d.ts +2 -0
- package/bin/index.js +2 -0
- package/bin/reciple/classes/CommandCooldownManager.d.ts +16 -1
- package/bin/reciple/classes/CommandCooldownManager.js +15 -0
- package/bin/reciple/classes/RecipleClient.d.ts +5 -31
- package/bin/reciple/classes/RecipleClient.js +22 -28
- package/bin/reciple/classes/RecipleConfig.js +1 -1
- package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +4 -3
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +4 -3
- package/bin/reciple/modules.d.ts +1 -4
- package/bin/reciple/permissions.d.ts +3 -3
- package/bin/reciple/permissions.js +1 -1
- package/bin/reciple/types/builders.d.ts +4 -0
- package/bin/reciple/types/builders.js +2 -0
- package/bin/reciple/types/commands.d.ts +31 -0
- package/bin/reciple/types/commands.js +2 -0
- package/package.json +8 -5
- package/resource/reciple.yml +8 -4
package/README.md
CHANGED
|
@@ -12,48 +12,48 @@ A simple Dicord.js command handler that just works.
|
|
|
12
12
|
[](https://discord.gg/2CattJYNpw)
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
|
-
To install the bot, run the following command:
|
|
15
|
+
To install the bot, run the following command in your terminal:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
npm i reciple
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
You can initialize the bot to the current directory with the following command:
|
|
21
|
+
You can initialize the bot to the current directory with the following command in your terminal:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
24
|
npx reciple
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
It will ask you to continue if the directory is not empty
|
|
27
|
+
It will ask you to continue if the directory is not empty. Type `y` to continue. After the bot has been initialized, it will ask you for your bot token.
|
|
28
28
|
|
|
29
|
-
> You can
|
|
29
|
+
> You can change the token anytime you want
|
|
30
30
|
|
|
31
31
|
## Config
|
|
32
32
|
|
|
33
|
-
You can configure the bot
|
|
33
|
+
You can configure the bot in `reciple.yml` located in the bot's root directory.
|
|
34
34
|
|
|
35
35
|
### Token
|
|
36
36
|
|
|
37
|
-
You can directly change the token
|
|
37
|
+
You can directly change the token in `reciple.yml`.
|
|
38
38
|
|
|
39
39
|
```yml
|
|
40
40
|
token: "YOUR_TOKEN_HERE"
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Using environment variables is also supported
|
|
43
|
+
Using environment variables is also supported.
|
|
44
44
|
|
|
45
45
|
```yml
|
|
46
46
|
token: "env:TOKEN_VARIABLE"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You can override the token
|
|
49
|
+
You can override the given token using your terminal
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
52
|
npx reciple --token "YOUR_TOKEN_HERE"
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
##
|
|
56
|
-
To
|
|
55
|
+
## Starting the bot
|
|
56
|
+
To start the bot, run the following command:
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
59
|
npx reciple
|
|
@@ -62,5 +62,4 @@ npx reciple
|
|
|
62
62
|
> ## Fun Fact
|
|
63
63
|
> 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
64
|
|
|
65
|
-
# Save the Earth
|
|
66
65
|
[#letTheEarthBreathe](https://rebellion.global/)
|
package/bin/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from './reciple/classes/MessageCommandOptionManager';
|
|
|
4
4
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
5
5
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
6
6
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
7
|
+
export * from './reciple/types/builders';
|
|
8
|
+
export * from './reciple/types/commands';
|
|
7
9
|
export * from './reciple/permissions';
|
|
8
10
|
export * from './reciple/flags';
|
|
9
11
|
export * from './reciple/isIgnoredChannel';
|
package/bin/index.js
CHANGED
|
@@ -20,6 +20,8 @@ __exportStar(require("./reciple/classes/MessageCommandOptionManager"), exports);
|
|
|
20
20
|
__exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
|
|
21
21
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
22
22
|
__exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
|
|
23
|
+
__exportStar(require("./reciple/types/builders"), exports);
|
|
24
|
+
__exportStar(require("./reciple/types/commands"), exports);
|
|
23
25
|
__exportStar(require("./reciple/permissions"), exports);
|
|
24
26
|
__exportStar(require("./reciple/flags"), exports);
|
|
25
27
|
__exportStar(require("./reciple/isIgnoredChannel"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Guild, TextBasedChannel, User } from 'discord.js';
|
|
2
|
-
import { RecipleCommandBuilders } from '../
|
|
2
|
+
import { RecipleCommandBuilders } from '../types/builders';
|
|
3
3
|
export interface CooledDownUser {
|
|
4
4
|
user: User;
|
|
5
5
|
command: string;
|
|
@@ -13,9 +13,24 @@ export declare class CommandCooldownManager extends Array<CooledDownUser> {
|
|
|
13
13
|
* Alias for `CommandCooldownManager#push()`
|
|
14
14
|
*/
|
|
15
15
|
add(...options: CooledDownUser[]): number;
|
|
16
|
+
/**
|
|
17
|
+
* Remove cooldown from specific user, channel or guild
|
|
18
|
+
*/
|
|
16
19
|
remove(options: Partial<CooledDownUser>, limit?: number): void;
|
|
20
|
+
/**
|
|
21
|
+
* Check if the given user is cooled-down
|
|
22
|
+
*/
|
|
17
23
|
isCooledDown(options: Partial<Omit<CooledDownUser, 'expireTime'>>): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Clear non cooled-down users from this array
|
|
26
|
+
*/
|
|
18
27
|
clean(options?: Partial<Omit<CooledDownUser, 'expireTime'>>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get someone's cooldown data
|
|
30
|
+
*/
|
|
19
31
|
get(options: Partial<Omit<CooledDownUser, 'expireTime'>>): CooledDownUser | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Check if the options are valid
|
|
34
|
+
*/
|
|
20
35
|
static checkOptions(options: Partial<Omit<CooledDownUser, 'expireTime'>>, data: CooledDownUser): boolean;
|
|
21
36
|
}
|
|
@@ -8,6 +8,9 @@ class CommandCooldownManager extends Array {
|
|
|
8
8
|
add(...options) {
|
|
9
9
|
return this.push(...options);
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Remove cooldown from specific user, channel or guild
|
|
13
|
+
*/
|
|
11
14
|
remove(options, limit = 0) {
|
|
12
15
|
if (!Object.keys(options).length)
|
|
13
16
|
throw new TypeError('Provide atleast one option to remove cooldown data.');
|
|
@@ -23,6 +26,9 @@ class CommandCooldownManager extends Array {
|
|
|
23
26
|
i++;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if the given user is cooled-down
|
|
31
|
+
*/
|
|
26
32
|
isCooledDown(options) {
|
|
27
33
|
const data = this.get(options);
|
|
28
34
|
if (!data)
|
|
@@ -32,6 +38,9 @@ class CommandCooldownManager extends Array {
|
|
|
32
38
|
return false;
|
|
33
39
|
return true;
|
|
34
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Clear non cooled-down users from this array
|
|
43
|
+
*/
|
|
35
44
|
clean(options) {
|
|
36
45
|
for (const index in this) {
|
|
37
46
|
if (options && !CommandCooldownManager.checkOptions(options, this[index]))
|
|
@@ -41,9 +50,15 @@ class CommandCooldownManager extends Array {
|
|
|
41
50
|
this.slice(Number(index));
|
|
42
51
|
}
|
|
43
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Get someone's cooldown data
|
|
55
|
+
*/
|
|
44
56
|
get(options) {
|
|
45
57
|
return this.find(data => CommandCooldownManager.checkOptions(options, data));
|
|
46
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if the options are valid
|
|
61
|
+
*/
|
|
47
62
|
static checkOptions(options, data) {
|
|
48
63
|
var _a, _b;
|
|
49
64
|
if ((options === null || options === void 0 ? void 0 : options.user) && options.user.id !== data.user.id)
|
|
@@ -1,38 +1,12 @@
|
|
|
1
1
|
import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from './builders/InteractionCommandBuilder';
|
|
2
|
-
import { InteractionBuilder } from '../registerInteractionCommands';
|
|
3
2
|
import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from './builders/MessageCommandBuilder';
|
|
4
|
-
import {
|
|
3
|
+
import { InteractionBuilder } from '../registerInteractionCommands';
|
|
4
|
+
import { RecipleCommandBuilders } from '../types/builders';
|
|
5
|
+
import { CommandCooldownManager } from './CommandCooldownManager';
|
|
6
|
+
import { RecipleModule, RecipleScript } from '../modules';
|
|
5
7
|
import { Logger as ILogger } from 'fallout-utility';
|
|
6
8
|
import { Config } from './RecipleConfig';
|
|
7
|
-
import { CommandCooldownManager, CooledDownUser } from './CommandCooldownManager';
|
|
8
9
|
import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
|
|
9
|
-
import { RecipleCommandBuilders, RecipleModule, RecipleScript } from '../modules';
|
|
10
|
-
export declare type CommandHaltReason<Builder extends RecipleCommandBuilders> = RecipleHaltedCommandData<Builder>["reason"];
|
|
11
|
-
export declare type RecipleHaltedCommandData<Builder extends RecipleCommandBuilders> = CommandErrorData<Builder> | CommandCooldownData<Builder> | CommandInvalidArguments<Builder> | CommandMissingArguments<Builder> | CommandMissingMemberPermissions<Builder> | CommandMissingBotPermissions<Builder>;
|
|
12
|
-
export interface CommandHaltBaseData<Builder extends RecipleCommandBuilders> {
|
|
13
|
-
executeData: Builder extends InteractionCommandBuilder ? RecipleInteractionCommandExecuteData : RecipleMessageCommandExecuteData;
|
|
14
|
-
}
|
|
15
|
-
export interface CommandErrorData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
16
|
-
reason: 'ERROR';
|
|
17
|
-
error: any;
|
|
18
|
-
}
|
|
19
|
-
export interface CommandCooldownData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder>, CooledDownUser {
|
|
20
|
-
reason: 'COOLDOWN';
|
|
21
|
-
}
|
|
22
|
-
export interface CommandInvalidArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
23
|
-
reason: 'INVALID_ARGUMENTS';
|
|
24
|
-
invalidArguments: MessageCommandOptionManager;
|
|
25
|
-
}
|
|
26
|
-
export interface CommandMissingArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
27
|
-
reason: 'MISSING_ARGUMENTS';
|
|
28
|
-
missingArguments: MessageCommandOptionManager;
|
|
29
|
-
}
|
|
30
|
-
export interface CommandMissingMemberPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
31
|
-
reason: 'MISSING_MEMBER_PERMISSIONS';
|
|
32
|
-
}
|
|
33
|
-
export interface CommandMissingBotPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
34
|
-
reason: 'MISSING_BOT_PERMISSIONS';
|
|
35
|
-
}
|
|
36
10
|
export interface RecipleClientOptions extends ClientOptions {
|
|
37
11
|
config?: Config;
|
|
38
12
|
}
|
|
@@ -115,7 +89,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
115
89
|
/**
|
|
116
90
|
* Emits the "recipleReplyError" event
|
|
117
91
|
*/
|
|
118
|
-
private
|
|
92
|
+
private _replyError;
|
|
119
93
|
/**
|
|
120
94
|
* Error message when a command fails to execute
|
|
121
95
|
*/
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// If you're trying to understand this code, please, consider that
|
|
4
|
-
// at the time of writing this code, It was written the way humans
|
|
5
|
-
// can understand it but I transformed into a dog at Apr 12th 2022
|
|
6
|
-
// and accidentally made it unreadable for humans. So, if you're
|
|
7
|
-
// trying to understand this code, please, consider being a dog first.
|
|
2
|
+
// Not cool code
|
|
8
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -17,17 +12,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
17
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
13
|
exports.RecipleClient = void 0;
|
|
19
14
|
const registerInteractionCommands_1 = require("../registerInteractionCommands");
|
|
15
|
+
const permissions_1 = require("../permissions");
|
|
16
|
+
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
20
17
|
const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
|
|
18
|
+
const modules_1 = require("../modules");
|
|
21
19
|
const fallout_utility_1 = require("fallout-utility");
|
|
22
20
|
const RecipleConfig_1 = require("./RecipleConfig");
|
|
23
21
|
const isIgnoredChannel_1 = require("../isIgnoredChannel");
|
|
24
|
-
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
25
|
-
const permissions_1 = require("../permissions");
|
|
26
22
|
const version_1 = require("../version");
|
|
27
23
|
const logger_1 = require("../logger");
|
|
28
24
|
const discord_js_1 = require("discord.js");
|
|
29
|
-
const modules_1 = require("../modules");
|
|
30
|
-
;
|
|
31
25
|
class RecipleClient extends discord_js_1.Client {
|
|
32
26
|
constructor(options) {
|
|
33
27
|
var _a, _b, _c;
|
|
@@ -167,7 +161,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
167
161
|
client: this
|
|
168
162
|
};
|
|
169
163
|
if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions, this.config.permissions.messageCommands, command)) {
|
|
170
|
-
if (!command.allowExecuteInDM && message.channel.type ===
|
|
164
|
+
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM
|
|
171
165
|
|| !command.allowExecuteByBots
|
|
172
166
|
&& (message.author.bot || message.author.system)
|
|
173
167
|
|| (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
|
|
@@ -175,20 +169,20 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
175
169
|
if (command.validateOptions) {
|
|
176
170
|
if (commandOptions.some(o => o.invalid)) {
|
|
177
171
|
if (!(command === null || command === void 0 ? void 0 : command.halt) || !(yield command.halt({ executeData, reason: 'INVALID_ARGUMENTS', invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.invalid)) }))) {
|
|
178
|
-
message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this.
|
|
172
|
+
message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
179
173
|
}
|
|
180
174
|
return;
|
|
181
175
|
}
|
|
182
176
|
if (commandOptions.some(o => o.missing)) {
|
|
183
177
|
if (!command.halt || !(yield command.halt({ executeData, reason: 'MISSING_ARGUMENTS', missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.missing)) }))) {
|
|
184
|
-
message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(er => this.
|
|
178
|
+
message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
185
179
|
}
|
|
186
180
|
return;
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
190
184
|
if (!command.halt || !(yield command.halt({ executeData, reason: 'MISSING_BOT_PERMISSIONS' }))) {
|
|
191
|
-
message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this.
|
|
185
|
+
message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
192
186
|
}
|
|
193
187
|
return;
|
|
194
188
|
}
|
|
@@ -199,12 +193,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
199
193
|
guild: message.guild,
|
|
200
194
|
type: 'MESSAGE_COMMAND'
|
|
201
195
|
};
|
|
202
|
-
if (command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
196
|
+
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
203
197
|
this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
204
198
|
}
|
|
205
|
-
else if (command.cooldown) {
|
|
199
|
+
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
206
200
|
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: 'COOLDOWN' }, this.commandCooldowns.get(userCooldown))))) {
|
|
207
|
-
yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this.
|
|
201
|
+
yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
208
202
|
}
|
|
209
203
|
return;
|
|
210
204
|
}
|
|
@@ -220,7 +214,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
220
214
|
}
|
|
221
215
|
}
|
|
222
216
|
else if (!command.halt || !(yield command.halt({ executeData, reason: 'MISSING_MEMBER_PERMISSIONS' }))) {
|
|
223
|
-
message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this.
|
|
217
|
+
message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
224
218
|
}
|
|
225
219
|
});
|
|
226
220
|
}
|
|
@@ -230,7 +224,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
230
224
|
interactionCommandExecute(interaction) {
|
|
231
225
|
var _a, _b;
|
|
232
226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
if (!interaction ||
|
|
227
|
+
if (!interaction || interaction.type !== discord_js_1.InteractionType.ApplicationCommand || !this.isReady())
|
|
234
228
|
return;
|
|
235
229
|
const command = this.findCommand(interaction.commandName, 'INTERACTION_COMMAND');
|
|
236
230
|
if (!command)
|
|
@@ -243,9 +237,9 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
243
237
|
if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
|
|
244
238
|
if (!command || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
245
239
|
return;
|
|
246
|
-
if (interaction.guild && (0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
240
|
+
if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
247
241
|
if (!command.halt || !(yield command.halt({ executeData, reason: 'MISSING_BOT_PERMISSIONS' }))) {
|
|
248
|
-
yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this.
|
|
242
|
+
yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
249
243
|
}
|
|
250
244
|
return;
|
|
251
245
|
}
|
|
@@ -256,12 +250,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
256
250
|
guild: interaction.guild,
|
|
257
251
|
type: 'INTERACTION_COMMAND'
|
|
258
252
|
};
|
|
259
|
-
if (command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
253
|
+
if (this.config.commands.interactionCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
260
254
|
this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
261
255
|
}
|
|
262
|
-
else if (command.cooldown) {
|
|
256
|
+
else if (this.config.commands.interactionCommand.enableCooldown && command.cooldown) {
|
|
263
257
|
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: 'COOLDOWN' }, this.commandCooldowns.get(userCooldown))))) {
|
|
264
|
-
yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this.
|
|
258
|
+
yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
265
259
|
}
|
|
266
260
|
return;
|
|
267
261
|
}
|
|
@@ -277,7 +271,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
277
271
|
}
|
|
278
272
|
}
|
|
279
273
|
else if (!command.halt || !(yield command.halt({ executeData, reason: 'MISSING_MEMBER_PERMISSIONS' }))) {
|
|
280
|
-
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this.
|
|
274
|
+
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
281
275
|
}
|
|
282
276
|
});
|
|
283
277
|
}
|
|
@@ -310,7 +304,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
310
304
|
/**
|
|
311
305
|
* Emits the "recipleReplyError" event
|
|
312
306
|
*/
|
|
313
|
-
|
|
307
|
+
_replyError(error) {
|
|
314
308
|
this.emit('recipleReplyError', error);
|
|
315
309
|
}
|
|
316
310
|
/**
|
|
@@ -327,12 +321,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
327
321
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
328
322
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
329
323
|
return;
|
|
330
|
-
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this.
|
|
324
|
+
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
331
325
|
}
|
|
332
326
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
333
327
|
if (!this.config.commands.interactionCommand.replyOnError)
|
|
334
328
|
return;
|
|
335
|
-
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(er => this.
|
|
329
|
+
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
336
330
|
}
|
|
337
331
|
});
|
|
338
332
|
}
|
|
@@ -33,7 +33,7 @@ class RecipleConfig {
|
|
|
33
33
|
this.config = yaml_1.default.parse(defaultConfig);
|
|
34
34
|
if (this.config && this.config.token === 'TOKEN') {
|
|
35
35
|
this.config.token = this.askToken() || this.config.token;
|
|
36
|
-
(0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, 'TOKEN', this.config.token), 'utf-8');
|
|
36
|
+
(0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, ' TOKEN', ` ${this.config.token}`), 'utf-8');
|
|
37
37
|
}
|
|
38
38
|
return this;
|
|
39
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Awaitable, CommandInteraction, PermissionResolvable } from 'discord.js';
|
|
2
|
-
import {
|
|
2
|
+
import { RecipleHaltedCommandData } from '../../types/commands';
|
|
3
3
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
|
4
|
+
import { RecipleClient } from '../RecipleClient';
|
|
4
5
|
export interface RecipleInteractionCommandExecuteData {
|
|
5
6
|
interaction: CommandInteraction;
|
|
6
7
|
builder: InteractionCommandBuilder;
|
|
@@ -12,7 +13,7 @@ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
|
12
13
|
requiredBotPermissions: PermissionResolvable[];
|
|
13
14
|
RequiredUserPermissions: PermissionResolvable[];
|
|
14
15
|
allowExecuteInDM: boolean;
|
|
15
|
-
halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean>;
|
|
16
|
+
halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean | void>;
|
|
16
17
|
execute: (executeData: RecipleInteractionCommandExecuteData) => Awaitable<void>;
|
|
17
18
|
/**
|
|
18
19
|
* Sets the execute cooldown for this command.
|
|
@@ -26,7 +27,7 @@ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
|
26
27
|
/**
|
|
27
28
|
* Function when the command is interupted before execution
|
|
28
29
|
*/
|
|
29
|
-
setHalt(halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean>): InteractionCommandBuilder;
|
|
30
|
+
setHalt(halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean | void>): InteractionCommandBuilder;
|
|
30
31
|
/**
|
|
31
32
|
* Function when the command is executed
|
|
32
33
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
2
|
-
import { RecipleClient, RecipleHaltedCommandData } from '../RecipleClient';
|
|
3
2
|
import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
|
|
4
3
|
import { Awaitable, Message, PermissionResolvable } from 'discord.js';
|
|
4
|
+
import { RecipleHaltedCommandData } from '../../types/commands';
|
|
5
5
|
import { Command as CommandMessage } from 'fallout-utility';
|
|
6
|
+
import { RecipleClient } from '../RecipleClient';
|
|
6
7
|
export interface RecipleMessageCommandExecuteData {
|
|
7
8
|
message: Message;
|
|
8
9
|
options: MessageCommandOptionManager;
|
|
@@ -29,7 +30,7 @@ export declare class MessageCommandBuilder {
|
|
|
29
30
|
RequiredUserPermissions: PermissionResolvable[];
|
|
30
31
|
allowExecuteInDM: boolean;
|
|
31
32
|
allowExecuteByBots: boolean;
|
|
32
|
-
halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean>;
|
|
33
|
+
halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>;
|
|
33
34
|
execute: (executeData: RecipleMessageCommandExecuteData) => void;
|
|
34
35
|
/**
|
|
35
36
|
* Sets the command name
|
|
@@ -67,7 +68,7 @@ export declare class MessageCommandBuilder {
|
|
|
67
68
|
/**
|
|
68
69
|
* Function when the command is interupted before execution
|
|
69
70
|
*/
|
|
70
|
-
setHalt(halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean>): MessageCommandBuilder;
|
|
71
|
+
setHalt(halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>): MessageCommandBuilder;
|
|
71
72
|
/**
|
|
72
73
|
* Function when the command is executed
|
|
73
74
|
*/
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from './classes/builders/MessageCommandBuilder';
|
|
1
|
+
import { RecipleCommandBuilders } from './types/builders';
|
|
3
2
|
import { RecipleClient } from './classes/RecipleClient';
|
|
4
|
-
export declare type RecipleCommandBuilders = MessageCommandBuilder | InteractionCommandBuilder;
|
|
5
|
-
export declare type RecipleCommandBuildersExecuteData = RecipleInteractionCommandExecuteData | RecipleMessageCommandExecuteData;
|
|
6
3
|
export declare type LoadedModules = {
|
|
7
4
|
commands: RecipleCommandBuilders[];
|
|
8
5
|
modules: RecipleModule[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Guild, PermissionResolvable, PermissionsBitField } from 'discord.js';
|
|
2
|
+
import { RecipleCommandBuilders } from './types/builders';
|
|
2
3
|
import { Config } from './classes/RecipleConfig';
|
|
3
|
-
import { Guild, PermissionResolvable, Permissions } from 'discord.js';
|
|
4
4
|
/**
|
|
5
5
|
* Check if the user has permissions to execute the given command name
|
|
6
6
|
*/
|
|
7
|
-
export declare function userHasCommandPermissions(commandName: string, memberPermissions?:
|
|
7
|
+
export declare function userHasCommandPermissions(commandName: string, memberPermissions?: PermissionsBitField, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands'], builder?: RecipleCommandBuilders): boolean;
|
|
8
8
|
export declare function botHasExecutePermissions(guild?: Guild, requiredPermissions?: PermissionResolvable[]): boolean;
|
|
@@ -18,6 +18,6 @@ function botHasExecutePermissions(guild, requiredPermissions) {
|
|
|
18
18
|
var _a;
|
|
19
19
|
if (!(requiredPermissions === null || requiredPermissions === void 0 ? void 0 : requiredPermissions.length))
|
|
20
20
|
return true;
|
|
21
|
-
return (guild === null || guild === void 0 ? void 0 : guild.me) ? (_a = guild.me) === null || _a === void 0 ? void 0 : _a.permissions.has(requiredPermissions) : false;
|
|
21
|
+
return (guild === null || guild === void 0 ? void 0 : guild.members.me) ? (_a = guild.members.me) === null || _a === void 0 ? void 0 : _a.permissions.has(requiredPermissions) : false;
|
|
22
22
|
}
|
|
23
23
|
exports.botHasExecutePermissions = botHasExecutePermissions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from '../classes/builders/InteractionCommandBuilder';
|
|
2
|
+
import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
|
|
3
|
+
export declare type RecipleCommandBuilders = MessageCommandBuilder | InteractionCommandBuilder;
|
|
4
|
+
export declare type RecipleCommandBuildersExecuteData = RecipleInteractionCommandExecuteData | RecipleMessageCommandExecuteData;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from '../classes/builders/InteractionCommandBuilder';
|
|
2
|
+
import { RecipleMessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
|
|
3
|
+
import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
|
|
4
|
+
import { CooledDownUser } from '../classes/CommandCooldownManager';
|
|
5
|
+
import { RecipleCommandBuilders } from '../types/builders';
|
|
6
|
+
export declare type CommandHaltReason<Builder extends RecipleCommandBuilders> = RecipleHaltedCommandData<Builder>["reason"];
|
|
7
|
+
export declare type RecipleHaltedCommandData<Builder extends RecipleCommandBuilders> = CommandErrorData<Builder> | CommandCooldownData<Builder> | CommandInvalidArguments<Builder> | CommandMissingArguments<Builder> | CommandMissingMemberPermissions<Builder> | CommandMissingBotPermissions<Builder>;
|
|
8
|
+
export interface CommandHaltBaseData<Builder extends RecipleCommandBuilders> {
|
|
9
|
+
executeData: Builder extends InteractionCommandBuilder ? RecipleInteractionCommandExecuteData : RecipleMessageCommandExecuteData;
|
|
10
|
+
}
|
|
11
|
+
export interface CommandErrorData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
12
|
+
reason: 'ERROR';
|
|
13
|
+
error: any;
|
|
14
|
+
}
|
|
15
|
+
export interface CommandCooldownData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder>, CooledDownUser {
|
|
16
|
+
reason: 'COOLDOWN';
|
|
17
|
+
}
|
|
18
|
+
export interface CommandInvalidArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
19
|
+
reason: 'INVALID_ARGUMENTS';
|
|
20
|
+
invalidArguments: MessageCommandOptionManager;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandMissingArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
23
|
+
reason: 'MISSING_ARGUMENTS';
|
|
24
|
+
missingArguments: MessageCommandOptionManager;
|
|
25
|
+
}
|
|
26
|
+
export interface CommandMissingMemberPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
27
|
+
reason: 'MISSING_MEMBER_PERMISSIONS';
|
|
28
|
+
}
|
|
29
|
+
export interface CommandMissingBotPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
30
|
+
reason: 'MISSING_BOT_PERMISSIONS';
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0-pre.1",
|
|
4
|
+
"description": "Handler for Discord.js",
|
|
5
5
|
"author": "FalloutStudios",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://reciple.js.org",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/FalloutStudios/reciple/issues"
|
|
9
|
+
},
|
|
7
10
|
"license": "GPL-3.0",
|
|
8
11
|
"main": "bin/index.js",
|
|
9
12
|
"bin": {
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
38
|
"chalk": "4.1.2",
|
|
36
|
-
"commander": "^9.
|
|
39
|
+
"commander": "^9.4.0",
|
|
37
40
|
"dotenv": "^16.0.1",
|
|
38
41
|
"fallout-utility": "^1.4.2",
|
|
39
42
|
"semver": "^7.3.7",
|
|
@@ -43,7 +46,7 @@
|
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@types/node": "^18.0.3",
|
|
45
48
|
"@types/semver": "^7.3.10",
|
|
46
|
-
"discord.js": "^
|
|
49
|
+
"discord.js": "^14.0.2",
|
|
47
50
|
"typescript": "^4.7.4"
|
|
48
51
|
},
|
|
49
52
|
"peerDependencies": {
|
package/resource/reciple.yml
CHANGED
|
@@ -74,19 +74,23 @@ fileLogging:
|
|
|
74
74
|
logFilePath: './logs/latest.log'
|
|
75
75
|
|
|
76
76
|
# Client options
|
|
77
|
+
# Use an intent calculator like https://discord-intents-calculator.vercel.app/ to get valid intents
|
|
77
78
|
client:
|
|
78
|
-
intents:
|
|
79
|
-
- 'GUILDS'
|
|
80
|
-
- 'GUILD_MEMBERS'
|
|
81
|
-
- 'GUILD_MESSAGES'
|
|
79
|
+
intents: 33283
|
|
82
80
|
|
|
83
81
|
# Bot replies
|
|
84
82
|
messages:
|
|
85
83
|
notEnoughArguments: 'Not enough arguments.'
|
|
86
84
|
invalidArguments: 'Invalid argument(s) given.'
|
|
85
|
+
insufficientBotPerms:
|
|
86
|
+
content: 'Insufficient bot permissions.'
|
|
87
|
+
ephemeral: true
|
|
87
88
|
noPermissions:
|
|
88
89
|
content: 'You do not have permission to use this command.'
|
|
89
90
|
ephemeral: true
|
|
91
|
+
cooldown:
|
|
92
|
+
content: 'You cannot execute this command right now due to the cooldown.'
|
|
93
|
+
ephemeral: true
|
|
90
94
|
error:
|
|
91
95
|
content: 'An error occurred.'
|
|
92
96
|
ephemeral: true
|