reciple 1.5.1 → 1.5.4
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/bin/index.d.ts +1 -0
- package/bin/index.js +1 -0
- package/bin/reciple/classes/Client.d.ts +3 -3
- package/bin/reciple/classes/Client.js +22 -17
- package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +1 -1
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +3 -2
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +1 -1
- package/bin/reciple/classes/builders/MessageCommandOptions.d.ts +6 -0
- package/bin/reciple/classes/builders/MessageCommandOptions.js +16 -0
- package/bin/reciple/modules.js +7 -7
- package/bin/reciple/registerInteractionCommands.js +1 -1
- package/package.json +1 -1
package/bin/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './reciple/classes/Config';
|
|
|
5
5
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
6
6
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
7
7
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
8
|
+
export * from './reciple/classes/builders/MessageCommandOptions';
|
|
8
9
|
export * from './reciple/hasPermissions';
|
|
9
10
|
export * from './reciple/flags';
|
|
10
11
|
export * from './reciple/isIgnoredChannel';
|
package/bin/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./reciple/classes/Config"), exports);
|
|
|
25
25
|
__exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
|
|
26
26
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
27
27
|
__exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
|
|
28
|
+
__exportStar(require("./reciple/classes/builders/MessageCommandOptions"), exports);
|
|
28
29
|
__exportStar(require("./reciple/hasPermissions"), exports);
|
|
29
30
|
__exportStar(require("./reciple/flags"), exports);
|
|
30
31
|
__exportStar(require("./reciple/isIgnoredChannel"), exports);
|
|
@@ -45,8 +45,8 @@ export declare class RecipleClient extends Client {
|
|
|
45
45
|
addModule(script: RecipleScript, registerCommands?: boolean): Promise<void>;
|
|
46
46
|
addCommand(command: recipleCommandBuilders): RecipleClient;
|
|
47
47
|
addCommandListeners(): RecipleClient;
|
|
48
|
-
messageCommandExecute(message: Message): Promise<void>;
|
|
49
|
-
interactionCommandExecute(interaction: Interaction): Promise<void>;
|
|
50
|
-
getMessage<T =
|
|
48
|
+
messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecute>;
|
|
49
|
+
interactionCommandExecute(interaction: Interaction): Promise<void | RecipleInteractionCommandExecute>;
|
|
50
|
+
getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
|
|
51
51
|
private _commandExecuteError;
|
|
52
52
|
}
|
|
@@ -24,6 +24,7 @@ const version_1 = require("../version");
|
|
|
24
24
|
const logger_1 = require("../logger");
|
|
25
25
|
const discord_js_1 = require("discord.js");
|
|
26
26
|
const modules_1 = require("../modules");
|
|
27
|
+
const MessageCommandOptions_1 = require("./builders/MessageCommandOptions");
|
|
27
28
|
class RecipleClient extends discord_js_1.Client {
|
|
28
29
|
constructor(options) {
|
|
29
30
|
super(options);
|
|
@@ -95,7 +96,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
95
96
|
this.commands.INTERACTION_COMMANDS[command.name] = command;
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
|
-
this.logger.error(`
|
|
99
|
+
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
99
100
|
}
|
|
100
101
|
return this;
|
|
101
102
|
}
|
|
@@ -106,12 +107,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
106
107
|
this.on('interactionCreate', (interaction) => { this.interactionCommandExecute(interaction); });
|
|
107
108
|
return this;
|
|
108
109
|
}
|
|
109
|
-
messageCommandExecute(message) {
|
|
110
|
+
messageCommandExecute(message, prefix) {
|
|
110
111
|
var _a;
|
|
111
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
if (!message.content
|
|
113
|
+
if (!message.content)
|
|
113
114
|
return;
|
|
114
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
115
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
115
116
|
if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
|
|
116
117
|
return;
|
|
117
118
|
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()];
|
|
@@ -124,33 +125,36 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
124
125
|
|| (0, isIgnoredChannel_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
|
|
125
126
|
return;
|
|
126
127
|
const commandOptions = command.getCommandOptionValues(parseCommand);
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
if (command.validateOptions) {
|
|
129
|
+
if (commandOptions.some(o => o.invalid)) {
|
|
130
|
+
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(err => this.logger.debug(err));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (commandOptions.some(o => o.missing)) {
|
|
134
|
+
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(err => this.logger.debug(err));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
134
137
|
}
|
|
135
138
|
const options = {
|
|
136
139
|
message: message,
|
|
137
|
-
options: commandOptions,
|
|
140
|
+
options: new MessageCommandOptions_1.MessageCommandOptions(commandOptions),
|
|
138
141
|
command: parseCommand,
|
|
139
142
|
builder: command,
|
|
140
143
|
client: this
|
|
141
144
|
};
|
|
142
145
|
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
143
146
|
this.emit('recipleMessageCommandCreate', options);
|
|
147
|
+
return options;
|
|
144
148
|
}
|
|
145
149
|
else {
|
|
146
|
-
yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(
|
|
150
|
+
yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(err => this.logger.debug(err));
|
|
147
151
|
}
|
|
148
152
|
});
|
|
149
153
|
}
|
|
150
154
|
interactionCommandExecute(interaction) {
|
|
151
155
|
var _a;
|
|
152
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
if (!interaction || !interaction.isCommand()
|
|
157
|
+
if (!interaction || !interaction.isCommand())
|
|
154
158
|
return;
|
|
155
159
|
const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
|
|
156
160
|
if (!command)
|
|
@@ -168,9 +172,10 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
168
172
|
};
|
|
169
173
|
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
170
174
|
this.emit('recipleInteractionCommandCreate', options);
|
|
175
|
+
return options;
|
|
171
176
|
}
|
|
172
177
|
else {
|
|
173
|
-
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(
|
|
178
|
+
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(err => this.logger.debug(err));
|
|
174
179
|
}
|
|
175
180
|
});
|
|
176
181
|
}
|
|
@@ -187,12 +192,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
187
192
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
188
193
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
189
194
|
return;
|
|
190
|
-
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(
|
|
195
|
+
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
|
|
191
196
|
}
|
|
192
197
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
193
198
|
if (!this.config.commands.interactionCommand.replyOnError)
|
|
194
199
|
return;
|
|
195
|
-
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(
|
|
200
|
+
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(err => this.logger.debug(err));
|
|
196
201
|
}
|
|
197
202
|
});
|
|
198
203
|
}
|
|
@@ -8,7 +8,7 @@ export interface RecipleInteractionCommandExecute {
|
|
|
8
8
|
client: RecipleClient;
|
|
9
9
|
}
|
|
10
10
|
export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
11
|
-
readonly builder
|
|
11
|
+
readonly builder = "INTERACTION_COMMAND";
|
|
12
12
|
requiredPermissions: (PermissionFlags | PermissionString)[];
|
|
13
13
|
allowExecuteInDM: boolean;
|
|
14
14
|
execute: (options: RecipleInteractionCommandExecute) => void;
|
|
@@ -2,10 +2,11 @@ import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
|
2
2
|
import { Message, PermissionFlags, PermissionString } from 'discord.js';
|
|
3
3
|
import { Command } from 'fallout-utility';
|
|
4
4
|
import { RecipleClient } from '../Client';
|
|
5
|
+
import { MessageCommandOptions } from './MessageCommandOptions';
|
|
5
6
|
export declare type CommandMessage = Command;
|
|
6
7
|
export interface RecipleMessageCommandExecute {
|
|
7
8
|
message: Message;
|
|
8
|
-
options:
|
|
9
|
+
options: MessageCommandOptions;
|
|
9
10
|
command: CommandMessage;
|
|
10
11
|
builder: MessageCommandBuilder;
|
|
11
12
|
client: RecipleClient;
|
|
@@ -18,7 +19,7 @@ export interface MessageCommandValidatedOption {
|
|
|
18
19
|
missing: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare class MessageCommandBuilder {
|
|
21
|
-
readonly builder
|
|
22
|
+
readonly builder = "MESSAGE_COMMAND";
|
|
22
23
|
name: string;
|
|
23
24
|
description: string;
|
|
24
25
|
options: MessageCommandOptionBuilder[];
|
|
@@ -72,7 +72,7 @@ class MessageCommandBuilder {
|
|
|
72
72
|
const required = this.options.filter(o => o.required);
|
|
73
73
|
const optional = this.options.filter(o => !o.required);
|
|
74
74
|
const allOptions = [...required, ...optional];
|
|
75
|
-
|
|
75
|
+
const result = [];
|
|
76
76
|
let i = 0;
|
|
77
77
|
for (const option of allOptions) {
|
|
78
78
|
const arg = args[i];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MessageCommandValidatedOption } from './MessageCommandBuilder';
|
|
2
|
+
export declare class MessageCommandOptions extends Array<MessageCommandValidatedOption> {
|
|
3
|
+
constructor(options: MessageCommandValidatedOption[]);
|
|
4
|
+
get(name: string, requied: true): MessageCommandValidatedOption;
|
|
5
|
+
get(name: string, requied?: boolean): MessageCommandValidatedOption | null;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageCommandOptions = void 0;
|
|
4
|
+
class MessageCommandOptions extends Array {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super();
|
|
7
|
+
this.push(...options);
|
|
8
|
+
}
|
|
9
|
+
get(name, required) {
|
|
10
|
+
const option = this.find(o => o.name == name);
|
|
11
|
+
if (!option && required || (option === null || option === void 0 ? void 0 : option.value) == undefined && required)
|
|
12
|
+
throw new TypeError(`Can't find option named ${name}`);
|
|
13
|
+
return option !== null && option !== void 0 ? option : null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.MessageCommandOptions = MessageCommandOptions;
|
package/bin/reciple/modules.js
CHANGED
|
@@ -18,7 +18,7 @@ const version_1 = require("./version");
|
|
|
18
18
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
function loadModules(client) {
|
|
21
|
-
var _a;
|
|
21
|
+
var _a, _b;
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
const response = { commands: [], modules: [] };
|
|
24
24
|
const modulesDir = client.config.modulesFolder || './modules';
|
|
@@ -30,17 +30,17 @@ function loadModules(client) {
|
|
|
30
30
|
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
31
31
|
});
|
|
32
32
|
for (const script of scripts) {
|
|
33
|
-
const modulePath = path_1.default.
|
|
33
|
+
const modulePath = path_1.default.join(process.cwd(), modulesDir, script);
|
|
34
34
|
const commands = [];
|
|
35
35
|
let module_;
|
|
36
36
|
try {
|
|
37
37
|
const reqMod = require(modulePath);
|
|
38
|
-
module_ =
|
|
38
|
+
module_ = typeof (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) != 'undefined' ? reqMod.default : reqMod;
|
|
39
39
|
if (!((_a = module_.versions) === null || _a === void 0 ? void 0 : _a.length))
|
|
40
40
|
throw new Error('Module does not have supported versions.');
|
|
41
41
|
const versions = typeof module_.versions === 'object' ? module_.versions : [module_.versions];
|
|
42
42
|
if (!versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
43
|
-
throw new Error('Module versions is not defined or unsupported.');
|
|
43
|
+
throw new Error((_b = 'Module versions is not defined or unsupported; supported versions: ' + module_.versions) !== null && _b !== void 0 ? _b : 'none' + '; current version: ' + version_1.version);
|
|
44
44
|
if (!(yield Promise.resolve(module_.onStart(client))))
|
|
45
45
|
throw new Error(script + ' onStart is not defined or returned false.');
|
|
46
46
|
if (module_.commands) {
|
|
@@ -55,13 +55,13 @@ function loadModules(client) {
|
|
|
55
55
|
logger.error(error);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
response.commands
|
|
58
|
+
response.commands.push(...commands.filter((c) => {
|
|
59
59
|
if (!c.name) {
|
|
60
|
-
logger.error(`A
|
|
60
|
+
logger.error(`A ${c.builder} command name is not defined in ${script}`);
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
if (c.builder === 'MESSAGE_COMMAND' && c.options.length && c.options.some(o => !o.name)) {
|
|
64
|
-
logger.error(`A
|
|
64
|
+
logger.error(`A ${c.builder} option name is not defined in ${script}`);
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
return true;
|
|
@@ -24,7 +24,7 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
24
24
|
undefined)) !== null && _d !== void 0 ? _d : cmd.requiredPermissions;
|
|
25
25
|
cmd.setRequiredPermissions(permissions);
|
|
26
26
|
client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
|
|
27
|
-
client.logger.debug(`Set required permissions for ${cmd.name}
|
|
27
|
+
client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
28
28
|
return cmd.toJSON();
|
|
29
29
|
}
|
|
30
30
|
return c.toJSON();
|