reciple 1.5.3 → 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 +14 -11
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +2 -1
- 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/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);
|
|
@@ -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()];
|
|
@@ -126,33 +127,34 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
126
127
|
const commandOptions = command.getCommandOptionValues(parseCommand);
|
|
127
128
|
if (command.validateOptions) {
|
|
128
129
|
if (commandOptions.some(o => o.invalid)) {
|
|
129
|
-
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(
|
|
130
|
+
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(err => this.logger.debug(err));
|
|
130
131
|
return;
|
|
131
132
|
}
|
|
132
133
|
if (commandOptions.some(o => o.missing)) {
|
|
133
|
-
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(
|
|
134
|
+
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(err => this.logger.debug(err));
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
const options = {
|
|
138
139
|
message: message,
|
|
139
|
-
options: commandOptions,
|
|
140
|
+
options: new MessageCommandOptions_1.MessageCommandOptions(commandOptions),
|
|
140
141
|
command: parseCommand,
|
|
141
142
|
builder: command,
|
|
142
143
|
client: this
|
|
143
144
|
};
|
|
144
145
|
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
145
146
|
this.emit('recipleMessageCommandCreate', options);
|
|
147
|
+
return options;
|
|
146
148
|
}
|
|
147
149
|
else {
|
|
148
|
-
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));
|
|
149
151
|
}
|
|
150
152
|
});
|
|
151
153
|
}
|
|
152
154
|
interactionCommandExecute(interaction) {
|
|
153
155
|
var _a;
|
|
154
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
if (!interaction || !interaction.isCommand()
|
|
157
|
+
if (!interaction || !interaction.isCommand())
|
|
156
158
|
return;
|
|
157
159
|
const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
|
|
158
160
|
if (!command)
|
|
@@ -170,9 +172,10 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
170
172
|
};
|
|
171
173
|
yield Promise.resolve(command.execute(options)).catch(err => this._commandExecuteError(err, options));
|
|
172
174
|
this.emit('recipleInteractionCommandCreate', options);
|
|
175
|
+
return options;
|
|
173
176
|
}
|
|
174
177
|
else {
|
|
175
|
-
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));
|
|
176
179
|
}
|
|
177
180
|
});
|
|
178
181
|
}
|
|
@@ -189,12 +192,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
189
192
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
190
193
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
191
194
|
return;
|
|
192
|
-
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));
|
|
193
196
|
}
|
|
194
197
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
195
198
|
if (!this.config.commands.interactionCommand.replyOnError)
|
|
196
199
|
return;
|
|
197
|
-
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));
|
|
198
201
|
}
|
|
199
202
|
});
|
|
200
203
|
}
|
|
@@ -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;
|
|
@@ -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;
|