reciple 2.0.2 → 3.0.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 +0 -6
- package/bin/index.d.ts +2 -1
- package/bin/index.js +2 -1
- package/bin/reciple/classes/CommandCooldownManager.d.ts +2 -2
- package/bin/reciple/classes/RecipleClient.d.ts +11 -10
- package/bin/reciple/classes/RecipleClient.js +61 -48
- package/bin/reciple/classes/RecipleConfig.d.ts +10 -12
- package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +4 -3
- package/bin/reciple/classes/builders/InteractionCommandBuilder.js +2 -1
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +4 -3
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +2 -1
- package/bin/reciple/modules.js +4 -2
- package/bin/reciple/permissions.d.ts +9 -2
- package/bin/reciple/permissions.js +18 -2
- package/bin/reciple/registerInteractionCommands.d.ts +4 -5
- package/bin/reciple/registerInteractionCommands.js +21 -18
- package/bin/reciple/types/builders.d.ts +4 -0
- package/bin/reciple/types/builders.js +6 -0
- package/bin/reciple/types/commands.d.ts +15 -8
- package/bin/reciple/types/commands.js +10 -0
- package/bin/reciple/types/paramOptions.d.ts +32 -0
- package/bin/reciple/types/paramOptions.js +2 -0
- package/package.json +14 -6
- package/resource/reciple.yml +23 -25
- package/bin/reciple/isIgnoredChannel.d.ts +0 -5
- package/bin/reciple/isIgnoredChannel.js +0 -16
package/README.md
CHANGED
|
@@ -17,12 +17,6 @@ To install the bot, run the following command in your terminal:
|
|
|
17
17
|
```bash
|
|
18
18
|
npm i reciple
|
|
19
19
|
```
|
|
20
|
-
```bash
|
|
21
|
-
yarn add reciple
|
|
22
|
-
```
|
|
23
|
-
```bash
|
|
24
|
-
pnpm add reciple
|
|
25
|
-
```
|
|
26
20
|
|
|
27
21
|
You can initialize the bot to the current directory with the following command in your terminal:
|
|
28
22
|
|
package/bin/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export * from './reciple/classes/RecipleClient';
|
|
2
2
|
export * from './reciple/classes/RecipleConfig';
|
|
3
|
+
export * from './reciple/classes/CommandCooldownManager';
|
|
3
4
|
export * from './reciple/classes/MessageCommandOptionManager';
|
|
4
5
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
5
6
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
6
7
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
7
8
|
export * from './reciple/types/builders';
|
|
8
9
|
export * from './reciple/types/commands';
|
|
10
|
+
export * from './reciple/types/paramOptions';
|
|
9
11
|
export * from './reciple/permissions';
|
|
10
12
|
export * from './reciple/flags';
|
|
11
|
-
export * from './reciple/isIgnoredChannel';
|
|
12
13
|
export * from './reciple/logger';
|
|
13
14
|
export * from './reciple/modules';
|
|
14
15
|
export * from './reciple/registerInteractionCommands';
|
package/bin/index.js
CHANGED
|
@@ -16,15 +16,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./reciple/classes/RecipleClient"), exports);
|
|
18
18
|
__exportStar(require("./reciple/classes/RecipleConfig"), exports);
|
|
19
|
+
__exportStar(require("./reciple/classes/CommandCooldownManager"), exports);
|
|
19
20
|
__exportStar(require("./reciple/classes/MessageCommandOptionManager"), exports);
|
|
20
21
|
__exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
|
|
21
22
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
22
23
|
__exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
|
|
23
24
|
__exportStar(require("./reciple/types/builders"), exports);
|
|
24
25
|
__exportStar(require("./reciple/types/commands"), exports);
|
|
26
|
+
__exportStar(require("./reciple/types/paramOptions"), exports);
|
|
25
27
|
__exportStar(require("./reciple/permissions"), exports);
|
|
26
28
|
__exportStar(require("./reciple/flags"), exports);
|
|
27
|
-
__exportStar(require("./reciple/isIgnoredChannel"), exports);
|
|
28
29
|
__exportStar(require("./reciple/logger"), exports);
|
|
29
30
|
__exportStar(require("./reciple/modules"), exports);
|
|
30
31
|
__exportStar(require("./reciple/registerInteractionCommands"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { RecipleCommandBuilderType } from '../types/builders';
|
|
1
2
|
import { Guild, TextBasedChannel, User } from 'discord.js';
|
|
2
|
-
import { RecipleCommandBuilders } from '../types/builders';
|
|
3
3
|
export interface CooledDownUser {
|
|
4
4
|
user: User;
|
|
5
5
|
command: string;
|
|
6
|
-
type:
|
|
6
|
+
type: RecipleCommandBuilderType;
|
|
7
7
|
guild?: Guild | null;
|
|
8
8
|
channel?: TextBasedChannel;
|
|
9
9
|
expireTime: number;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import { RecipleCommandBuilders, RecipleCommandBuilderType } from '../types/builders';
|
|
1
2
|
import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from './builders/InteractionCommandBuilder';
|
|
2
3
|
import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from './builders/MessageCommandBuilder';
|
|
3
4
|
import { InteractionBuilder } from '../registerInteractionCommands';
|
|
4
|
-
import { RecipleCommandBuilders } from '../types/builders';
|
|
5
5
|
import { CommandCooldownManager } from './CommandCooldownManager';
|
|
6
|
-
import { RecipleModule, RecipleScript } from '../modules';
|
|
7
6
|
import { Logger as ILogger } from 'fallout-utility';
|
|
7
|
+
import { AddModuleOptions } from '../types/paramOptions';
|
|
8
|
+
import { RecipleModule } from '../modules';
|
|
8
9
|
import { Config } from './RecipleConfig';
|
|
9
|
-
import {
|
|
10
|
+
import { ApplicationCommandData, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
|
|
10
11
|
export interface RecipleClientOptions extends ClientOptions {
|
|
11
12
|
config?: Config;
|
|
12
13
|
}
|
|
13
14
|
export interface RecipleClientCommands {
|
|
14
|
-
|
|
15
|
+
messageCommands: {
|
|
15
16
|
[commandName: string]: MessageCommandBuilder;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
+
interactionCommands: {
|
|
18
19
|
[commandName: string]: InteractionCommandBuilder;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -39,14 +40,14 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
|
|
|
39
40
|
export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
40
41
|
config: Config;
|
|
41
42
|
commands: RecipleClientCommands;
|
|
42
|
-
otherApplicationCommandData: (InteractionBuilder |
|
|
43
|
+
otherApplicationCommandData: (InteractionBuilder | ApplicationCommandData)[];
|
|
43
44
|
commandCooldowns: CommandCooldownManager;
|
|
44
45
|
modules: RecipleModule[];
|
|
45
46
|
logger: ILogger;
|
|
46
47
|
version: string;
|
|
47
48
|
constructor(options: RecipleClientOptions);
|
|
48
49
|
/**
|
|
49
|
-
* Load modules
|
|
50
|
+
* Load modules from modules folder
|
|
50
51
|
*/
|
|
51
52
|
startModules(folder?: string): Promise<RecipleClient<Ready>>;
|
|
52
53
|
/**
|
|
@@ -56,7 +57,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
56
57
|
/**
|
|
57
58
|
* Add module
|
|
58
59
|
*/
|
|
59
|
-
addModule(
|
|
60
|
+
addModule(options: AddModuleOptions): Promise<void>;
|
|
60
61
|
/**
|
|
61
62
|
* Add interaction or message command to client
|
|
62
63
|
*/
|
|
@@ -80,8 +81,8 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
80
81
|
/**
|
|
81
82
|
* Get command builder by name or alias if it's a message command
|
|
82
83
|
*/
|
|
83
|
-
findCommand(command: string, type:
|
|
84
|
-
findCommand(command: string, type:
|
|
84
|
+
findCommand(command: string, type: RecipleCommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
|
|
85
|
+
findCommand(command: string, type: RecipleCommandBuilderType.InteractionCommand): InteractionCommandBuilder | undefined;
|
|
85
86
|
/**
|
|
86
87
|
* Returns true if client logs is enabled
|
|
87
88
|
*/
|
|
@@ -11,14 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.RecipleClient = void 0;
|
|
14
|
-
const
|
|
14
|
+
const builders_1 = require("../types/builders");
|
|
15
15
|
const permissions_1 = require("../permissions");
|
|
16
|
+
const registerInteractionCommands_1 = require("../registerInteractionCommands");
|
|
16
17
|
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
17
18
|
const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
|
|
18
|
-
const modules_1 = require("../modules");
|
|
19
19
|
const fallout_utility_1 = require("fallout-utility");
|
|
20
|
+
const commands_1 = require("../types/commands");
|
|
21
|
+
const modules_1 = require("../modules");
|
|
20
22
|
const RecipleConfig_1 = require("./RecipleConfig");
|
|
21
|
-
const isIgnoredChannel_1 = require("../isIgnoredChannel");
|
|
22
23
|
const version_1 = require("../version");
|
|
23
24
|
const logger_1 = require("../logger");
|
|
24
25
|
const discord_js_1 = require("discord.js");
|
|
@@ -27,7 +28,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
27
28
|
var _a, _b, _c;
|
|
28
29
|
super(options);
|
|
29
30
|
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
30
|
-
this.commands = {
|
|
31
|
+
this.commands = { messageCommands: {}, interactionCommands: {} };
|
|
31
32
|
this.otherApplicationCommandData = [];
|
|
32
33
|
this.commandCooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
33
34
|
this.modules = [];
|
|
@@ -40,7 +41,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
40
41
|
this.logger.logFile(this.config.fileLogging.logFilePath, false);
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
|
-
* Load modules
|
|
44
|
+
* Load modules from modules folder
|
|
44
45
|
*/
|
|
45
46
|
startModules(folder) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,11 +80,15 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
79
80
|
}
|
|
80
81
|
if (this.isClientLogsEnabled()) {
|
|
81
82
|
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
82
|
-
this.logger.info(`${Object.keys(this.commands.
|
|
83
|
-
this.logger.info(`${Object.keys(this.commands.
|
|
83
|
+
this.logger.info(`${Object.keys(this.commands.messageCommands).length} message commands loaded.`);
|
|
84
|
+
this.logger.info(`${Object.keys(this.commands.interactionCommands).length} interaction commands loaded.`);
|
|
84
85
|
}
|
|
85
86
|
if (this.config.commands.interactionCommand.registerCommands) {
|
|
86
|
-
yield (0, registerInteractionCommands_1.registerInteractionCommands)(
|
|
87
|
+
yield (0, registerInteractionCommands_1.registerInteractionCommands)({
|
|
88
|
+
client: this,
|
|
89
|
+
commands: [...Object.values(this.commands.interactionCommands), ...this.otherApplicationCommandData],
|
|
90
|
+
guilds: this.config.commands.interactionCommand.guilds
|
|
91
|
+
});
|
|
87
92
|
}
|
|
88
93
|
return this;
|
|
89
94
|
});
|
|
@@ -91,9 +96,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
91
96
|
/**
|
|
92
97
|
* Add module
|
|
93
98
|
*/
|
|
94
|
-
addModule(
|
|
99
|
+
addModule(options) {
|
|
95
100
|
var _a;
|
|
96
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const { script } = options;
|
|
103
|
+
const registerCommands = options.registerInteractionCommands;
|
|
104
|
+
const info = options.moduleInfo;
|
|
97
105
|
this.modules.push({
|
|
98
106
|
script,
|
|
99
107
|
info: Object.assign({ filename: undefined, versions: typeof script.versions == 'string' ? [script.versions] : script.versions, path: undefined }, info)
|
|
@@ -107,9 +115,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
107
115
|
continue;
|
|
108
116
|
this.addCommand(command);
|
|
109
117
|
}
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
118
|
+
if (registerCommands)
|
|
119
|
+
yield (0, registerInteractionCommands_1.registerInteractionCommands)({
|
|
120
|
+
client: this,
|
|
121
|
+
commands: [...Object.values(this.commands.interactionCommands), ...this.otherApplicationCommandData],
|
|
122
|
+
guilds: this.config.commands.interactionCommand.guilds
|
|
123
|
+
});
|
|
113
124
|
});
|
|
114
125
|
}
|
|
115
126
|
/**
|
|
@@ -117,11 +128,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
117
128
|
*/
|
|
118
129
|
addCommand(command) {
|
|
119
130
|
var _a;
|
|
120
|
-
if (command.builder ===
|
|
121
|
-
this.commands.
|
|
131
|
+
if (command.builder === builders_1.RecipleCommandBuilderType.MessageCommand) {
|
|
132
|
+
this.commands.messageCommands[command.name] = command;
|
|
122
133
|
}
|
|
123
|
-
else if (command.builder ===
|
|
124
|
-
this.commands.
|
|
134
|
+
else if (command.builder === builders_1.RecipleCommandBuilderType.InteractionCommand) {
|
|
135
|
+
this.commands.interactionCommands[command.name] = command;
|
|
125
136
|
}
|
|
126
137
|
else if (this.isClientLogsEnabled()) {
|
|
127
138
|
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
@@ -146,10 +157,10 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
146
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
158
|
if (!message.content || !this.isReady())
|
|
148
159
|
return;
|
|
149
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
160
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
150
161
|
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
151
162
|
return;
|
|
152
|
-
const command = this.findCommand(parseCommand.command,
|
|
163
|
+
const command = this.findCommand(parseCommand.command, builders_1.RecipleCommandBuilderType.MessageCommand);
|
|
153
164
|
if (!command)
|
|
154
165
|
return;
|
|
155
166
|
const commandOptions = command.getCommandOptionValues(parseCommand);
|
|
@@ -160,28 +171,28 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
160
171
|
builder: command,
|
|
161
172
|
client: this
|
|
162
173
|
};
|
|
163
|
-
if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions, this.config.permissions
|
|
164
|
-
if (!command.allowExecuteInDM && message.channel.type ===
|
|
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)) {
|
|
175
|
+
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM
|
|
165
176
|
|| !command.allowExecuteByBots
|
|
166
177
|
&& (message.author.bot || message.author.system)
|
|
167
|
-
|| (0,
|
|
178
|
+
|| (0, permissions_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
|
|
168
179
|
return;
|
|
169
180
|
if (command.validateOptions) {
|
|
170
181
|
if (commandOptions.some(o => o.invalid)) {
|
|
171
|
-
if (!(command === null || command === void 0 ? void 0 : command.halt) || !(yield command.halt({ executeData, reason:
|
|
182
|
+
if (!(command === null || command === void 0 ? void 0 : command.halt) || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.invalid)) }))) {
|
|
172
183
|
message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
173
184
|
}
|
|
174
185
|
return;
|
|
175
186
|
}
|
|
176
187
|
if (commandOptions.some(o => o.missing)) {
|
|
177
|
-
if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
178
|
-
message.reply(this.getMessage('
|
|
188
|
+
if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(executeData.options.filter(o => o.missing)) }))) {
|
|
189
|
+
message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
179
190
|
}
|
|
180
191
|
return;
|
|
181
192
|
}
|
|
182
193
|
}
|
|
183
194
|
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
184
|
-
if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
195
|
+
if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
|
|
185
196
|
message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
186
197
|
}
|
|
187
198
|
return;
|
|
@@ -191,29 +202,30 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
191
202
|
command: command.name,
|
|
192
203
|
channel: message.channel,
|
|
193
204
|
guild: message.guild,
|
|
194
|
-
type:
|
|
205
|
+
type: builders_1.RecipleCommandBuilderType.MessageCommand
|
|
195
206
|
};
|
|
196
207
|
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
197
208
|
this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
198
209
|
}
|
|
199
210
|
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
200
|
-
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason:
|
|
211
|
+
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
|
|
201
212
|
yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
202
213
|
}
|
|
203
214
|
return;
|
|
204
215
|
}
|
|
205
216
|
try {
|
|
206
|
-
yield Promise.resolve(command.execute(executeData))
|
|
207
|
-
|
|
217
|
+
yield Promise.resolve(command.execute(executeData))
|
|
218
|
+
.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; }));
|
|
208
220
|
return executeData;
|
|
209
221
|
}
|
|
210
222
|
catch (err) {
|
|
211
|
-
if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
223
|
+
if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
|
|
212
224
|
this._commandExecuteError(err, executeData);
|
|
213
225
|
}
|
|
214
226
|
}
|
|
215
227
|
}
|
|
216
|
-
else if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
228
|
+
else if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
|
|
217
229
|
message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
218
230
|
}
|
|
219
231
|
});
|
|
@@ -224,9 +236,9 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
224
236
|
interactionCommandExecute(interaction) {
|
|
225
237
|
var _a, _b;
|
|
226
238
|
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
if (!interaction ||
|
|
239
|
+
if (!interaction || interaction.type !== discord_js_1.InteractionType.ApplicationCommand || !this.isReady())
|
|
228
240
|
return;
|
|
229
|
-
const command = this.findCommand(interaction.commandName,
|
|
241
|
+
const command = this.findCommand(interaction.commandName, builders_1.RecipleCommandBuilderType.InteractionCommand);
|
|
230
242
|
if (!command)
|
|
231
243
|
return;
|
|
232
244
|
const executeData = {
|
|
@@ -234,11 +246,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
234
246
|
builder: command,
|
|
235
247
|
client: this
|
|
236
248
|
};
|
|
237
|
-
if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions
|
|
238
|
-
if (!command || (0,
|
|
249
|
+
if ((0, permissions_1.userHasCommandPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.commands.interactionCommand.permissions, command)) {
|
|
250
|
+
if (!command || (0, permissions_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
239
251
|
return;
|
|
240
252
|
if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
241
|
-
if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
253
|
+
if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingBotPermissions }))) {
|
|
242
254
|
yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
243
255
|
}
|
|
244
256
|
return;
|
|
@@ -248,29 +260,30 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
248
260
|
command: command.name,
|
|
249
261
|
channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
|
|
250
262
|
guild: interaction.guild,
|
|
251
|
-
type:
|
|
263
|
+
type: builders_1.RecipleCommandBuilderType.InteractionCommand
|
|
252
264
|
};
|
|
253
265
|
if (this.config.commands.interactionCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
|
|
254
266
|
this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
255
267
|
}
|
|
256
268
|
else if (this.config.commands.interactionCommand.enableCooldown && command.cooldown) {
|
|
257
|
-
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason:
|
|
269
|
+
if (!command.halt || !(yield command.halt(Object.assign({ executeData, reason: commands_1.RecipleHaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
|
|
258
270
|
yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
259
271
|
}
|
|
260
272
|
return;
|
|
261
273
|
}
|
|
262
274
|
try {
|
|
263
|
-
yield Promise.resolve(command.execute(executeData))
|
|
264
|
-
|
|
275
|
+
yield Promise.resolve(command.execute(executeData))
|
|
276
|
+
.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; }));
|
|
265
278
|
return executeData;
|
|
266
279
|
}
|
|
267
280
|
catch (err) {
|
|
268
|
-
if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
281
|
+
if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.Error, error: err }))) {
|
|
269
282
|
this._commandExecuteError(err, executeData);
|
|
270
283
|
}
|
|
271
284
|
}
|
|
272
285
|
}
|
|
273
|
-
else if (!command.halt || !(yield command.halt({ executeData, reason:
|
|
286
|
+
else if (!command.halt || !(yield command.halt({ executeData, reason: commands_1.RecipleHaltedCommandReason.MissingMemberPermissions }))) {
|
|
274
287
|
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
275
288
|
}
|
|
276
289
|
});
|
|
@@ -285,11 +298,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
285
298
|
findCommand(command, type) {
|
|
286
299
|
var _a;
|
|
287
300
|
switch (type) {
|
|
288
|
-
case
|
|
289
|
-
return this.commands.
|
|
290
|
-
case
|
|
291
|
-
return (_a = this.commands.
|
|
292
|
-
? Object.values(this.commands.
|
|
301
|
+
case builders_1.RecipleCommandBuilderType.InteractionCommand:
|
|
302
|
+
return this.commands.interactionCommands[command];
|
|
303
|
+
case builders_1.RecipleCommandBuilderType.MessageCommand:
|
|
304
|
+
return (_a = this.commands.messageCommands[command.toLowerCase()]) !== null && _a !== void 0 ? _a : (this.config.commands.messageCommand.allowCommandAlias
|
|
305
|
+
? Object.values(this.commands.messageCommands).find(c => c.aliases.some(a => a == (command === null || command === void 0 ? void 0 : command.toLowerCase())))
|
|
293
306
|
: undefined);
|
|
294
307
|
default:
|
|
295
308
|
throw new TypeError('Unknown command type');
|
|
@@ -313,7 +326,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
313
326
|
_commandExecuteError(err, command) {
|
|
314
327
|
return __awaiter(this, void 0, void 0, function* () {
|
|
315
328
|
if (this.isClientLogsEnabled()) {
|
|
316
|
-
this.logger.error(`An error occured executing ${command.builder.builder ==
|
|
329
|
+
this.logger.error(`An error occured executing ${command.builder.builder == builders_1.RecipleCommandBuilderType.MessageCommand ? 'message' : 'interaction'} command "${command.builder.name}"`);
|
|
317
330
|
this.logger.error(err);
|
|
318
331
|
}
|
|
319
332
|
if (!err || !command)
|
|
@@ -5,14 +5,18 @@ export interface ConfigCommandPermissions {
|
|
|
5
5
|
}
|
|
6
6
|
export interface Config {
|
|
7
7
|
token: string;
|
|
8
|
-
prefix: string;
|
|
9
8
|
commands: {
|
|
10
9
|
messageCommand: {
|
|
11
10
|
enabled: boolean;
|
|
11
|
+
prefix?: string;
|
|
12
12
|
replyOnError: boolean;
|
|
13
13
|
allowCommandAlias: boolean;
|
|
14
14
|
enableCooldown: boolean;
|
|
15
15
|
commandArgumentSeparator: string;
|
|
16
|
+
permissions: {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
commands: ConfigCommandPermissions[];
|
|
19
|
+
};
|
|
16
20
|
};
|
|
17
21
|
interactionCommand: {
|
|
18
22
|
enabled: boolean;
|
|
@@ -20,17 +24,11 @@ export interface Config {
|
|
|
20
24
|
registerCommands: boolean;
|
|
21
25
|
enableCooldown: boolean;
|
|
22
26
|
setRequiredPermissions: boolean;
|
|
23
|
-
guilds
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
enabled: boolean;
|
|
29
|
-
commands: ConfigCommandPermissions[];
|
|
30
|
-
};
|
|
31
|
-
interactionCommands: {
|
|
32
|
-
enabled: boolean;
|
|
33
|
-
commands: ConfigCommandPermissions[];
|
|
27
|
+
guilds?: string[] | string;
|
|
28
|
+
permissions: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
commands: ConfigCommandPermissions[];
|
|
31
|
+
};
|
|
34
32
|
};
|
|
35
33
|
};
|
|
36
34
|
ignoredChannels: {
|
|
@@ -2,18 +2,19 @@ import { Awaitable, CommandInteraction, PermissionResolvable } from 'discord.js'
|
|
|
2
2
|
import { RecipleHaltedCommandData } from '../../types/commands';
|
|
3
3
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
|
4
4
|
import { RecipleClient } from '../RecipleClient';
|
|
5
|
+
import { RecipleCommandBuilderType } from '../../types/builders';
|
|
5
6
|
export interface RecipleInteractionCommandExecuteData {
|
|
6
7
|
interaction: CommandInteraction;
|
|
7
8
|
builder: InteractionCommandBuilder;
|
|
8
9
|
client: RecipleClient<true>;
|
|
9
10
|
}
|
|
10
11
|
export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
11
|
-
readonly builder =
|
|
12
|
+
readonly builder = RecipleCommandBuilderType.InteractionCommand;
|
|
12
13
|
cooldown: number;
|
|
13
14
|
requiredBotPermissions: PermissionResolvable[];
|
|
14
15
|
RequiredUserPermissions: PermissionResolvable[];
|
|
15
16
|
allowExecuteInDM: boolean;
|
|
16
|
-
halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean>;
|
|
17
|
+
halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean | void>;
|
|
17
18
|
execute: (executeData: RecipleInteractionCommandExecuteData) => Awaitable<void>;
|
|
18
19
|
/**
|
|
19
20
|
* Sets the execute cooldown for this command.
|
|
@@ -27,7 +28,7 @@ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
|
27
28
|
/**
|
|
28
29
|
* Function when the command is interupted before execution
|
|
29
30
|
*/
|
|
30
|
-
setHalt(halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean>): InteractionCommandBuilder;
|
|
31
|
+
setHalt(halt?: (haltData: RecipleHaltedCommandData<InteractionCommandBuilder>) => Awaitable<boolean | void>): InteractionCommandBuilder;
|
|
31
32
|
/**
|
|
32
33
|
* Function when the command is executed
|
|
33
34
|
*/
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InteractionCommandBuilder = void 0;
|
|
4
4
|
const builders_1 = require("@discordjs/builders");
|
|
5
|
+
const builders_2 = require("../../types/builders");
|
|
5
6
|
class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(...arguments);
|
|
8
|
-
this.builder =
|
|
9
|
+
this.builder = builders_2.RecipleCommandBuilderType.InteractionCommand;
|
|
9
10
|
this.cooldown = 0;
|
|
10
11
|
this.requiredBotPermissions = [];
|
|
11
12
|
this.RequiredUserPermissions = [];
|
|
@@ -4,6 +4,7 @@ import { Awaitable, Message, PermissionResolvable } from 'discord.js';
|
|
|
4
4
|
import { RecipleHaltedCommandData } from '../../types/commands';
|
|
5
5
|
import { Command as CommandMessage } from 'fallout-utility';
|
|
6
6
|
import { RecipleClient } from '../RecipleClient';
|
|
7
|
+
import { RecipleCommandBuilderType } from '../../types/builders';
|
|
7
8
|
export interface RecipleMessageCommandExecuteData {
|
|
8
9
|
message: Message;
|
|
9
10
|
options: MessageCommandOptionManager;
|
|
@@ -19,7 +20,7 @@ export interface MessageCommandValidatedOption {
|
|
|
19
20
|
missing: boolean;
|
|
20
21
|
}
|
|
21
22
|
export declare class MessageCommandBuilder {
|
|
22
|
-
readonly builder =
|
|
23
|
+
readonly builder = RecipleCommandBuilderType.MessageCommand;
|
|
23
24
|
name: string;
|
|
24
25
|
cooldown: number;
|
|
25
26
|
description: string;
|
|
@@ -30,7 +31,7 @@ export declare class MessageCommandBuilder {
|
|
|
30
31
|
RequiredUserPermissions: PermissionResolvable[];
|
|
31
32
|
allowExecuteInDM: boolean;
|
|
32
33
|
allowExecuteByBots: boolean;
|
|
33
|
-
halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean>;
|
|
34
|
+
halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>;
|
|
34
35
|
execute: (executeData: RecipleMessageCommandExecuteData) => void;
|
|
35
36
|
/**
|
|
36
37
|
* Sets the command name
|
|
@@ -68,7 +69,7 @@ export declare class MessageCommandBuilder {
|
|
|
68
69
|
/**
|
|
69
70
|
* Function when the command is interupted before execution
|
|
70
71
|
*/
|
|
71
|
-
setHalt(halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean>): MessageCommandBuilder;
|
|
72
|
+
setHalt(halt?: (haltData: RecipleHaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>): MessageCommandBuilder;
|
|
72
73
|
/**
|
|
73
74
|
* Function when the command is executed
|
|
74
75
|
*/
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageCommandBuilder = void 0;
|
|
4
4
|
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
5
|
+
const builders_1 = require("../../types/builders");
|
|
5
6
|
class MessageCommandBuilder {
|
|
6
7
|
constructor() {
|
|
7
|
-
this.builder =
|
|
8
|
+
this.builder = builders_1.RecipleCommandBuilderType.MessageCommand;
|
|
8
9
|
this.name = '';
|
|
9
10
|
this.cooldown = 0;
|
|
10
11
|
this.description = '';
|
package/bin/reciple/modules.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.loadModules = void 0;
|
|
16
|
+
const builders_1 = require("./types/builders");
|
|
16
17
|
const fs_1 = require("fs");
|
|
17
18
|
const version_1 = require("./version");
|
|
18
19
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
@@ -47,8 +48,9 @@ function loadModules(client, folder) {
|
|
|
47
48
|
throw new Error(script + ' onStart is not defined or returned false.');
|
|
48
49
|
if (module_.commands) {
|
|
49
50
|
for (const command of module_.commands) {
|
|
50
|
-
if (command.builder ===
|
|
51
|
+
if (command.builder === builders_1.RecipleCommandBuilderType.MessageCommand || command.builder === builders_1.RecipleCommandBuilderType.InteractionCommand) {
|
|
51
52
|
commands.push(command);
|
|
53
|
+
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -65,7 +67,7 @@ function loadModules(client, folder) {
|
|
|
65
67
|
client.logger.error(`A ${c.builder} command name is not defined in ${script}`);
|
|
66
68
|
return false;
|
|
67
69
|
}
|
|
68
|
-
if (c.builder ===
|
|
70
|
+
if (c.builder === builders_1.RecipleCommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
|
|
69
71
|
if (client.isClientLogsEnabled())
|
|
70
72
|
client.logger.error(`A ${c.builder} option name is not defined in ${script}`);
|
|
71
73
|
return false;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { Guild, PermissionResolvable,
|
|
1
|
+
import { Guild, PermissionResolvable, PermissionsBitField } from 'discord.js';
|
|
2
2
|
import { RecipleCommandBuilders } from './types/builders';
|
|
3
3
|
import { Config } from './classes/RecipleConfig';
|
|
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['commands']['messageCommand']['permissions'] | Config['commands']['interactionCommand']['permissions'], builder?: RecipleCommandBuilders): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if the bot has the required permissions in a guild
|
|
10
|
+
*/
|
|
8
11
|
export declare function botHasExecutePermissions(guild?: Guild, requiredPermissions?: PermissionResolvable[]): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the channel id is ignored in config file
|
|
14
|
+
*/
|
|
15
|
+
export declare function isIgnoredChannel(channelId: string, ignoredChannelsConfig?: Config["ignoredChannels"]): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
|
|
3
|
+
exports.isIgnoredChannel = exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Check if the user has permissions to execute the given command name
|
|
6
6
|
*/
|
|
@@ -14,10 +14,26 @@ function userHasCommandPermissions(commandName, memberPermissions, configConmman
|
|
|
14
14
|
return memberPermissions ? memberPermissions.has(command.permissions) : false;
|
|
15
15
|
}
|
|
16
16
|
exports.userHasCommandPermissions = userHasCommandPermissions;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the bot has the required permissions in a guild
|
|
19
|
+
*/
|
|
17
20
|
function botHasExecutePermissions(guild, requiredPermissions) {
|
|
18
21
|
var _a;
|
|
19
22
|
if (!(requiredPermissions === null || requiredPermissions === void 0 ? void 0 : requiredPermissions.length))
|
|
20
23
|
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;
|
|
24
|
+
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
25
|
}
|
|
23
26
|
exports.botHasExecutePermissions = botHasExecutePermissions;
|
|
27
|
+
/**
|
|
28
|
+
* Check if the channel id is ignored in config file
|
|
29
|
+
*/
|
|
30
|
+
function isIgnoredChannel(channelId, ignoredChannelsConfig) {
|
|
31
|
+
if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
|
|
32
|
+
return false;
|
|
33
|
+
if (ignoredChannelsConfig.channels.includes(channelId) && !ignoredChannelsConfig.convertToAllowList)
|
|
34
|
+
return true;
|
|
35
|
+
if (!ignoredChannelsConfig.channels.includes(channelId) && ignoredChannelsConfig.convertToAllowList)
|
|
36
|
+
return true;
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
exports.isIgnoredChannel = isIgnoredChannel;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare type InteractionBuilder = InteractionCommandBuilder | ContextMenuCommandBuilder | SlashCommandBuilder | SlashCommandSubcommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandGroupBuilder | SlashCommandSubcommandsOnlyBuilder;
|
|
2
|
+
import { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
|
3
|
+
import { RegisterInteractionCommandsOptions } from './types/paramOptions';
|
|
4
|
+
export declare type InteractionBuilder = ContextMenuCommandBuilder | InteractionCommandBuilder | SlashCommandBuilder;
|
|
6
5
|
/**
|
|
7
6
|
* Register interaction commands
|
|
8
7
|
*/
|
|
9
|
-
export declare function registerInteractionCommands(
|
|
8
|
+
export declare function registerInteractionCommands(options: RegisterInteractionCommandsOptions): Promise<void>;
|
|
@@ -10,33 +10,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.registerInteractionCommands = void 0;
|
|
13
|
+
const InteractionCommandBuilder_1 = require("./classes/builders/InteractionCommandBuilder");
|
|
13
14
|
/**
|
|
14
15
|
* Register interaction commands
|
|
15
16
|
*/
|
|
16
|
-
function registerInteractionCommands(
|
|
17
|
-
var _a, _b, _c;
|
|
17
|
+
function registerInteractionCommands(options) {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const client = options.client;
|
|
21
|
+
const guilds = typeof options.guilds == 'string' ? [options.guilds] : options.guilds;
|
|
22
|
+
const commands = (_b = Object.values((_a = options.commands) !== null && _a !== void 0 ? _a : client.commands.interactionCommands).map(cmd => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (typeof (cmd === null || cmd === void 0 ? void 0 : cmd.toJSON) == 'undefined')
|
|
25
|
+
return cmd;
|
|
26
|
+
cmd = cmd;
|
|
27
|
+
if (cmd instanceof InteractionCommandBuilder_1.InteractionCommandBuilder && client.config.commands.interactionCommand.setRequiredPermissions) {
|
|
28
|
+
const permissions = (_b = (client.config.commands.interactionCommand.permissions.enabled ?
|
|
29
|
+
(_a = client.config.commands.interactionCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _a === void 0 ? void 0 : _a.permissions :
|
|
30
|
+
undefined)) !== null && _b !== void 0 ? _b : cmd.requiredBotPermissions;
|
|
28
31
|
cmd.setRequiredMemberPermissions(permissions);
|
|
29
|
-
client.commands.
|
|
32
|
+
client.commands.interactionCommands[cmd.name] = cmd;
|
|
30
33
|
if (client.isClientLogsEnabled())
|
|
31
34
|
client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
32
35
|
return cmd.toJSON();
|
|
33
36
|
}
|
|
34
|
-
return
|
|
35
|
-
})) !== null &&
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
return cmd.toJSON();
|
|
38
|
+
})) !== null && _b !== void 0 ? _b : [];
|
|
39
|
+
if (!client.isReady())
|
|
40
|
+
throw new Error('Client is not ready');
|
|
38
41
|
if (!guilds || !(guilds === null || guilds === void 0 ? void 0 : guilds.length)) {
|
|
39
|
-
(
|
|
42
|
+
(_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands).then(() => {
|
|
40
43
|
if (client.isClientLogsEnabled())
|
|
41
44
|
client.logger.warn('No guilds were specified for interaction commands. Registered interaction commands globally.');
|
|
42
45
|
});
|
|
@@ -47,7 +50,7 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
47
50
|
for (const guild of guilds) {
|
|
48
51
|
if (!guild)
|
|
49
52
|
continue;
|
|
50
|
-
(
|
|
53
|
+
(_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.set(commands, guild).then(() => {
|
|
51
54
|
if (client.isClientLogsEnabled())
|
|
52
55
|
client.logger.warn(`Registered ${commands.length} interaction command(s) for ${guild}.`);
|
|
53
56
|
});
|
|
@@ -2,3 +2,7 @@ import { InteractionCommandBuilder, RecipleInteractionCommandExecuteData } from
|
|
|
2
2
|
import { MessageCommandBuilder, RecipleMessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
|
|
3
3
|
export declare type RecipleCommandBuilders = MessageCommandBuilder | InteractionCommandBuilder;
|
|
4
4
|
export declare type RecipleCommandBuildersExecuteData = RecipleInteractionCommandExecuteData | RecipleMessageCommandExecuteData;
|
|
5
|
+
export declare enum RecipleCommandBuilderType {
|
|
6
|
+
MessageCommand = 0,
|
|
7
|
+
InteractionCommand = 1
|
|
8
|
+
}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecipleCommandBuilderType = void 0;
|
|
4
|
+
var RecipleCommandBuilderType;
|
|
5
|
+
(function (RecipleCommandBuilderType) {
|
|
6
|
+
RecipleCommandBuilderType[RecipleCommandBuilderType["MessageCommand"] = 0] = "MessageCommand";
|
|
7
|
+
RecipleCommandBuilderType[RecipleCommandBuilderType["InteractionCommand"] = 1] = "InteractionCommand";
|
|
8
|
+
})(RecipleCommandBuilderType = exports.RecipleCommandBuilderType || (exports.RecipleCommandBuilderType = {}));
|
|
@@ -3,29 +3,36 @@ import { RecipleMessageCommandExecuteData } from '../classes/builders/MessageCom
|
|
|
3
3
|
import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
|
|
4
4
|
import { CooledDownUser } from '../classes/CommandCooldownManager';
|
|
5
5
|
import { RecipleCommandBuilders } from '../types/builders';
|
|
6
|
-
export declare type
|
|
7
|
-
export declare type RecipleHaltedCommandData<Builder extends RecipleCommandBuilders> = CommandErrorData<Builder> | CommandCooldownData<Builder> | CommandInvalidArguments<Builder> | CommandMissingArguments<Builder> | CommandMissingMemberPermissions<Builder> | CommandMissingBotPermissions<Builder>;
|
|
6
|
+
export declare type RecipleHaltedCommandData<Builder extends RecipleCommandBuilders> = CommandErrorData<Builder> | CommandCooldownData<Builder> | (Builder extends InteractionCommandBuilder ? never : CommandInvalidArguments<Builder> | CommandMissingArguments<Builder>) | CommandMissingMemberPermissions<Builder> | CommandMissingBotPermissions<Builder>;
|
|
8
7
|
export interface CommandHaltBaseData<Builder extends RecipleCommandBuilders> {
|
|
9
8
|
executeData: Builder extends InteractionCommandBuilder ? RecipleInteractionCommandExecuteData : RecipleMessageCommandExecuteData;
|
|
10
9
|
}
|
|
11
10
|
export interface CommandErrorData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
12
|
-
reason:
|
|
11
|
+
reason: RecipleHaltedCommandReason.Error;
|
|
13
12
|
error: any;
|
|
14
13
|
}
|
|
15
14
|
export interface CommandCooldownData<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder>, CooledDownUser {
|
|
16
|
-
reason:
|
|
15
|
+
reason: RecipleHaltedCommandReason.Cooldown;
|
|
17
16
|
}
|
|
18
17
|
export interface CommandInvalidArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
19
|
-
reason:
|
|
18
|
+
reason: RecipleHaltedCommandReason.InvalidArguments;
|
|
20
19
|
invalidArguments: MessageCommandOptionManager;
|
|
21
20
|
}
|
|
22
21
|
export interface CommandMissingArguments<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
23
|
-
reason:
|
|
22
|
+
reason: RecipleHaltedCommandReason.MissingArguments;
|
|
24
23
|
missingArguments: MessageCommandOptionManager;
|
|
25
24
|
}
|
|
26
25
|
export interface CommandMissingMemberPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
27
|
-
reason:
|
|
26
|
+
reason: RecipleHaltedCommandReason.MissingMemberPermissions;
|
|
28
27
|
}
|
|
29
28
|
export interface CommandMissingBotPermissions<Builder extends RecipleCommandBuilders> extends CommandHaltBaseData<Builder> {
|
|
30
|
-
reason:
|
|
29
|
+
reason: RecipleHaltedCommandReason.MissingBotPermissions;
|
|
30
|
+
}
|
|
31
|
+
export declare enum RecipleHaltedCommandReason {
|
|
32
|
+
Error = 0,
|
|
33
|
+
Cooldown = 1,
|
|
34
|
+
InvalidArguments = 2,
|
|
35
|
+
MissingArguments = 3,
|
|
36
|
+
MissingMemberPermissions = 4,
|
|
37
|
+
MissingBotPermissions = 5
|
|
31
38
|
}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecipleHaltedCommandReason = void 0;
|
|
4
|
+
var RecipleHaltedCommandReason;
|
|
5
|
+
(function (RecipleHaltedCommandReason) {
|
|
6
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["Error"] = 0] = "Error";
|
|
7
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["Cooldown"] = 1] = "Cooldown";
|
|
8
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["InvalidArguments"] = 2] = "InvalidArguments";
|
|
9
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["MissingArguments"] = 3] = "MissingArguments";
|
|
10
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["MissingMemberPermissions"] = 4] = "MissingMemberPermissions";
|
|
11
|
+
RecipleHaltedCommandReason[RecipleHaltedCommandReason["MissingBotPermissions"] = 5] = "MissingBotPermissions";
|
|
12
|
+
})(RecipleHaltedCommandReason = exports.RecipleHaltedCommandReason || (exports.RecipleHaltedCommandReason = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InteractionBuilder } from '../registerInteractionCommands';
|
|
2
|
+
import { RecipleModule, RecipleScript } from '../modules';
|
|
3
|
+
import { RecipleClient } from '../classes/RecipleClient';
|
|
4
|
+
import { ApplicationCommandData } from 'discord.js';
|
|
5
|
+
export interface AddModuleOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The Module script
|
|
8
|
+
*/
|
|
9
|
+
script: RecipleScript;
|
|
10
|
+
/**
|
|
11
|
+
* Register interaction commands if possible
|
|
12
|
+
*/
|
|
13
|
+
registerInteractionCommands?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Module optional info
|
|
16
|
+
*/
|
|
17
|
+
moduleInfo?: RecipleModule["info"];
|
|
18
|
+
}
|
|
19
|
+
export interface RegisterInteractionCommandsOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Bot client
|
|
22
|
+
*/
|
|
23
|
+
client: RecipleClient;
|
|
24
|
+
/**
|
|
25
|
+
* Commands to register
|
|
26
|
+
*/
|
|
27
|
+
commands: (ApplicationCommandData | InteractionBuilder)[];
|
|
28
|
+
/**
|
|
29
|
+
* Set guild to not register commands globally
|
|
30
|
+
*/
|
|
31
|
+
guilds?: string | string[];
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Handler for Discord.js",
|
|
5
5
|
"author": "FalloutStudios",
|
|
6
6
|
"homepage": "https://reciple.js.org",
|
|
7
|
+
"contributors": [
|
|
8
|
+
"GhexterCortes <cortesghexter@gmail.com>"
|
|
9
|
+
],
|
|
7
10
|
"bugs": {
|
|
8
11
|
"url": "https://github.com/FalloutStudios/reciple/issues"
|
|
9
12
|
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/FalloutStudios/reciple.git"
|
|
16
|
+
},
|
|
10
17
|
"license": "GPL-3.0",
|
|
11
18
|
"main": "bin/index.js",
|
|
12
19
|
"bin": {
|
|
@@ -36,7 +43,7 @@
|
|
|
36
43
|
},
|
|
37
44
|
"dependencies": {
|
|
38
45
|
"chalk": "4.1.2",
|
|
39
|
-
"commander": "^9.
|
|
46
|
+
"commander": "^9.4.0",
|
|
40
47
|
"dotenv": "^16.0.1",
|
|
41
48
|
"fallout-utility": "^1.4.2",
|
|
42
49
|
"semver": "^7.3.7",
|
|
@@ -44,12 +51,13 @@
|
|
|
44
51
|
"yaml": "^2.1.1"
|
|
45
52
|
},
|
|
46
53
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^18.0.
|
|
54
|
+
"@types/node": "^18.0.6",
|
|
48
55
|
"@types/semver": "^7.3.10",
|
|
49
|
-
"discord.js": "^
|
|
56
|
+
"discord.js": "^14.0.3",
|
|
50
57
|
"typescript": "^4.7.4"
|
|
51
58
|
},
|
|
52
59
|
"peerDependencies": {
|
|
53
|
-
"discord.js": "
|
|
54
|
-
}
|
|
60
|
+
"discord.js": "14.0.x"
|
|
61
|
+
},
|
|
62
|
+
"packageManager": "yarn@1.22.19"
|
|
55
63
|
}
|
package/resource/reciple.yml
CHANGED
|
@@ -2,52 +2,49 @@
|
|
|
2
2
|
# To use env variable as a token just do it like this env:TOKEN_ENV
|
|
3
3
|
token: TOKEN
|
|
4
4
|
|
|
5
|
-
# Message command prefix
|
|
6
|
-
prefix: '!'
|
|
7
|
-
|
|
8
5
|
|
|
9
6
|
# Commands options
|
|
10
7
|
commands:
|
|
11
8
|
messageCommand:
|
|
12
9
|
# enable message commands
|
|
13
10
|
enabled: true
|
|
11
|
+
# command prefix
|
|
12
|
+
prefix: '!'
|
|
14
13
|
# reply when an error occured
|
|
15
14
|
replyOnError: false
|
|
16
15
|
# Enable the use of command cooldowns
|
|
17
|
-
enableCooldown:
|
|
16
|
+
enableCooldown: true
|
|
18
17
|
# Allow executing commands via aliases
|
|
19
18
|
allowCommandAlias: true
|
|
20
19
|
# command argument separator
|
|
21
20
|
commandArgumentSeparator: ' '
|
|
21
|
+
# Overwrite command permissions
|
|
22
|
+
permissions:
|
|
23
|
+
# enable overwriten command permissions
|
|
24
|
+
enabled: false
|
|
25
|
+
commands:
|
|
26
|
+
- command: 'example-command'
|
|
27
|
+
permissions: ['Administrator']
|
|
22
28
|
interactionCommand:
|
|
23
29
|
# enable interaction commands
|
|
24
30
|
enabled: true
|
|
25
31
|
# reply when an error occured
|
|
26
32
|
replyOnError: false
|
|
27
33
|
# Enable the use of command cooldowns
|
|
28
|
-
enableCooldown:
|
|
34
|
+
enableCooldown: true
|
|
29
35
|
# register interaction commands on bot ready
|
|
30
36
|
registerCommands: true
|
|
31
37
|
# set required permissions for interaction commands
|
|
32
38
|
setRequiredPermissions: true
|
|
33
39
|
# register commands to specific guild(s) empty to make it global
|
|
34
40
|
guilds: []
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
commands:
|
|
43
|
-
- command: 'stop'
|
|
44
|
-
permissions: ['ADMINISTRATOR']
|
|
45
|
-
interactionCommands:
|
|
46
|
-
# enable command permissions
|
|
47
|
-
enabled: true
|
|
48
|
-
commands:
|
|
49
|
-
- command: 'stop'
|
|
50
|
-
permissions: ['ADMINISTRATOR']
|
|
41
|
+
# Overwrite command permissions
|
|
42
|
+
permissions:
|
|
43
|
+
# enable overwriten command permissions
|
|
44
|
+
enabled: false
|
|
45
|
+
commands:
|
|
46
|
+
- command: 'example-command'
|
|
47
|
+
permissions: ['Administrator']
|
|
51
48
|
|
|
52
49
|
|
|
53
50
|
# Ignored channel IDs
|
|
@@ -76,13 +73,14 @@ fileLogging:
|
|
|
76
73
|
# Client options
|
|
77
74
|
client:
|
|
78
75
|
intents:
|
|
79
|
-
- '
|
|
80
|
-
- '
|
|
81
|
-
- '
|
|
76
|
+
- 'Guilds'
|
|
77
|
+
- 'GuildMembers'
|
|
78
|
+
- 'GuildMessages'
|
|
79
|
+
- 'MessageContent'
|
|
82
80
|
|
|
83
81
|
# Bot replies
|
|
84
82
|
messages:
|
|
85
|
-
|
|
83
|
+
missingArguments: 'Not enough arguments.'
|
|
86
84
|
invalidArguments: 'Invalid argument(s) given.'
|
|
87
85
|
insufficientBotPerms:
|
|
88
86
|
content: 'Insufficient bot permissions.'
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isIgnoredChannel = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Check if the channel id is ignored in config file
|
|
6
|
-
*/
|
|
7
|
-
function isIgnoredChannel(channelId, ignoredChannelsConfig) {
|
|
8
|
-
if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
|
|
9
|
-
return false;
|
|
10
|
-
if (ignoredChannelsConfig.channels.includes(channelId) && !ignoredChannelsConfig.convertToAllowList)
|
|
11
|
-
return true;
|
|
12
|
-
if (!ignoredChannelsConfig.channels.includes(channelId) && ignoredChannelsConfig.convertToAllowList)
|
|
13
|
-
return true;
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
exports.isIgnoredChannel = isIgnoredChannel;
|