reciple 1.5.5 → 1.6.2
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/bin.js +2 -2
- package/bin/index.d.ts +1 -1
- package/bin/index.js +1 -1
- package/bin/reciple/classes/Config.d.ts +1 -0
- package/bin/reciple/classes/{Client.d.ts → RecipleClient.d.ts} +11 -10
- package/bin/reciple/classes/{Client.js → RecipleClient.js} +38 -20
- package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +12 -2
- package/bin/reciple/classes/builders/InteractionCommandBuilder.js +12 -0
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +35 -3
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +47 -6
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +12 -0
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +12 -0
- package/bin/reciple/classes/builders/MessageCommandOptions.d.ts +6 -0
- package/bin/reciple/modules.d.ts +3 -3
- package/bin/reciple/registerInteractionCommands.d.ts +1 -1
- package/package.json +9 -7
- package/resource/reciple.yml +2 -0
package/bin/bin.js
CHANGED
|
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
var _a, _b;
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
const Config_1 = require("./reciple/classes/Config");
|
|
15
|
-
const
|
|
15
|
+
const RecipleClient_1 = require("./reciple/classes/RecipleClient");
|
|
16
16
|
const fs_1 = require("fs");
|
|
17
17
|
const version_1 = require("./reciple/version");
|
|
18
18
|
const flags_1 = require("./reciple/flags");
|
|
@@ -29,7 +29,7 @@ if ((0, fs_1.readdirSync)('./').filter(f => !f.startsWith('.') && allowedFiles.i
|
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
31
|
const config = new Config_1.RecipleConfig((_b = flags_1.flags.config) !== null && _b !== void 0 ? _b : './reciple.yml').parseConfig().getConfig();
|
|
32
|
-
const client = new
|
|
32
|
+
const client = new RecipleClient_1.RecipleClient(Object.assign({ config: config }, config.client));
|
|
33
33
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
yield client.startModules();
|
|
35
35
|
client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
|
package/bin/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import discord from 'discord.js';
|
|
2
2
|
export declare const discordjs: typeof discord;
|
|
3
|
-
export * from './reciple/classes/
|
|
3
|
+
export * from './reciple/classes/RecipleClient';
|
|
4
4
|
export * from './reciple/classes/Config';
|
|
5
5
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
6
6
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
package/bin/index.js
CHANGED
|
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.discordjs = void 0;
|
|
21
21
|
const discord_js_1 = __importDefault(require("discord.js"));
|
|
22
22
|
exports.discordjs = discord_js_1.default;
|
|
23
|
-
__exportStar(require("./reciple/classes/
|
|
23
|
+
__exportStar(require("./reciple/classes/RecipleClient"), exports);
|
|
24
24
|
__exportStar(require("./reciple/classes/Config"), exports);
|
|
25
25
|
__exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
|
|
26
26
|
__exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
|
|
@@ -3,8 +3,8 @@ import { interactionCommandBuilders } from '../registerInteractionCommands';
|
|
|
3
3
|
import { MessageCommandBuilder, RecipleMessageCommandExecute } from './builders/MessageCommandBuilder';
|
|
4
4
|
import { Logger as ILogger } from 'fallout-utility';
|
|
5
5
|
import { Config } from './Config';
|
|
6
|
-
import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
|
|
7
|
-
import { recipleCommandBuilders, RecipleScript } from '../modules';
|
|
6
|
+
import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
|
|
7
|
+
import { recipleCommandBuilders, RecipleModule, RecipleScript } from '../modules';
|
|
8
8
|
export interface RecipleClientOptions extends ClientOptions {
|
|
9
9
|
config: Config;
|
|
10
10
|
}
|
|
@@ -20,7 +20,7 @@ export interface RecipleClientEvents extends ClientEvents {
|
|
|
20
20
|
recipleMessageCommandCreate: [command: RecipleMessageCommandExecute];
|
|
21
21
|
recipleInteractionCommandCreate: [command: RecipleInteractionCommandExecute];
|
|
22
22
|
}
|
|
23
|
-
export interface RecipleClient extends Client {
|
|
23
|
+
export interface RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
24
24
|
on<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
25
25
|
on<E extends string | symbol>(event: Exclude<E, keyof RecipleClientEvents>, listener: (...args: any) => Awaitable<void>): this;
|
|
26
26
|
once<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
@@ -31,22 +31,23 @@ export interface RecipleClient extends Client {
|
|
|
31
31
|
off<E extends string | symbol>(event: Exclude<E, keyof RecipleClientEvents>, listener: (...args: any) => Awaitable<void>): this;
|
|
32
32
|
removeAllListeners<E extends keyof RecipleClientEvents>(event?: E): this;
|
|
33
33
|
removeAllListeners(event?: string | symbol): this;
|
|
34
|
+
isReady(): this is RecipleClient<true>;
|
|
34
35
|
}
|
|
35
|
-
export declare class RecipleClient extends Client {
|
|
36
|
+
export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
36
37
|
config: Config;
|
|
37
38
|
commands: RecipleClientCommands;
|
|
38
39
|
otherApplicationCommandData: (interactionCommandBuilders | ApplicationCommandDataResolvable)[];
|
|
39
|
-
modules:
|
|
40
|
+
modules: RecipleModule[];
|
|
40
41
|
logger: ILogger;
|
|
41
42
|
version: string;
|
|
42
43
|
constructor(options: RecipleClientOptions);
|
|
43
|
-
startModules(): Promise<RecipleClient
|
|
44
|
-
loadModules(): Promise<RecipleClient
|
|
44
|
+
startModules(): Promise<RecipleClient<Ready>>;
|
|
45
|
+
loadModules(): Promise<RecipleClient<Ready>>;
|
|
45
46
|
addModule(script: RecipleScript, registerCommands?: boolean): Promise<void>;
|
|
46
|
-
addCommand(command: recipleCommandBuilders): RecipleClient
|
|
47
|
-
addCommandListeners(): RecipleClient
|
|
47
|
+
addCommand(command: recipleCommandBuilders): RecipleClient<Ready>;
|
|
48
|
+
addCommandListeners(): RecipleClient<Ready>;
|
|
48
49
|
messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecute>;
|
|
49
|
-
interactionCommandExecute(interaction: Interaction): Promise<void | RecipleInteractionCommandExecute>;
|
|
50
|
+
interactionCommandExecute(interaction: Interaction | CommandInteraction): Promise<void | RecipleInteractionCommandExecute>;
|
|
50
51
|
getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
|
|
51
52
|
private _commandExecuteError;
|
|
52
53
|
}
|
|
@@ -46,24 +46,32 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
46
46
|
const modules = yield (0, modules_1.loadModules)(this);
|
|
47
47
|
if (!modules)
|
|
48
48
|
throw new Error('Failed to load modules.');
|
|
49
|
-
this.modules = modules.modules
|
|
50
|
-
for (const command of modules.commands) {
|
|
51
|
-
if (!command.name)
|
|
52
|
-
continue;
|
|
53
|
-
this.addCommand(command);
|
|
54
|
-
}
|
|
55
|
-
this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
|
|
56
|
-
this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
|
|
49
|
+
this.modules = modules.modules;
|
|
57
50
|
return this;
|
|
58
51
|
});
|
|
59
52
|
}
|
|
60
53
|
loadModules() {
|
|
54
|
+
var _a, _b;
|
|
61
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
for (let m in this.modules) {
|
|
57
|
+
const module_ = this.modules[m];
|
|
58
|
+
if (typeof ((_a = module_.script) === null || _a === void 0 ? void 0 : _a.onLoad) === 'function') {
|
|
59
|
+
yield Promise.resolve(module_.script.onLoad(this)).catch(err => {
|
|
60
|
+
var _a;
|
|
61
|
+
this.logger.error(`Error loading ${(_a = module_.info.filename) !== null && _a !== void 0 ? _a : 'unknown module'}:`);
|
|
62
|
+
this.logger.error(err);
|
|
63
|
+
this.modules = this.modules.filter((r, i) => i.toString() !== m.toString());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (typeof ((_b = module_.script) === null || _b === void 0 ? void 0 : _b.commands) !== 'undefined') {
|
|
67
|
+
for (const command of module_.script.commands) {
|
|
68
|
+
this.addCommand(command);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
73
|
+
this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
|
|
74
|
+
this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
|
|
67
75
|
if (!this.config.commands.interactionCommand.registerCommands)
|
|
68
76
|
return this;
|
|
69
77
|
yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
|
|
@@ -73,7 +81,14 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
73
81
|
addModule(script, registerCommands = true) {
|
|
74
82
|
var _a;
|
|
75
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
this.modules.push(
|
|
84
|
+
this.modules.push({
|
|
85
|
+
script,
|
|
86
|
+
info: {
|
|
87
|
+
filename: undefined,
|
|
88
|
+
versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
|
|
89
|
+
path: undefined
|
|
90
|
+
}
|
|
91
|
+
});
|
|
77
92
|
if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
|
|
78
93
|
yield Promise.resolve(script.onLoad(this));
|
|
79
94
|
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
@@ -108,17 +123,19 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
108
123
|
return this;
|
|
109
124
|
}
|
|
110
125
|
messageCommandExecute(message, prefix) {
|
|
111
|
-
var _a;
|
|
126
|
+
var _a, _b;
|
|
112
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
if (!message.content)
|
|
128
|
+
if (!message.content || !this.isReady())
|
|
114
129
|
return;
|
|
115
130
|
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
116
|
-
if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command)
|
|
131
|
+
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
117
132
|
return;
|
|
118
|
-
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()]
|
|
133
|
+
const command = (_a = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()]) !== null && _a !== void 0 ? _a : (this.config.commands.messageCommand.allowCommandAlias
|
|
134
|
+
? Object.values(this.commands.MESSAGE_COMMANDS).find(c => c.aliases.some(a => { var _a; return a == ((_a = parseCommand.command) === null || _a === void 0 ? void 0 : _a.toLowerCase()); }))
|
|
135
|
+
: undefined);
|
|
119
136
|
if (!command)
|
|
120
137
|
return;
|
|
121
|
-
if ((0, hasPermissions_1.hasPermissions)(command.name, (
|
|
138
|
+
if ((0, hasPermissions_1.hasPermissions)(command.name, (_b = message.member) === null || _b === void 0 ? void 0 : _b.permissions, this.config.permissions.messageCommands, command)) {
|
|
122
139
|
if (!command.allowExecuteInDM && message.channel.type === 'DM'
|
|
123
140
|
|| !command.allowExecuteByBots
|
|
124
141
|
&& (message.author.bot || message.author.system)
|
|
@@ -154,12 +171,13 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
154
171
|
interactionCommandExecute(interaction) {
|
|
155
172
|
var _a;
|
|
156
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
if (!interaction || !interaction.isCommand())
|
|
174
|
+
if (!interaction || !interaction.isCommand() || !this.isReady())
|
|
158
175
|
return;
|
|
159
176
|
const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
|
|
160
177
|
if (!command)
|
|
161
178
|
return;
|
|
162
179
|
if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
|
|
180
|
+
// TODO: Deprecated allowEcuteInDM
|
|
163
181
|
if (!command.allowExecuteInDM && !interaction.inCachedGuild() || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
164
182
|
return;
|
|
165
183
|
if (!command)
|
|
@@ -192,12 +210,12 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
192
210
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
193
211
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
194
212
|
return;
|
|
195
|
-
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(
|
|
213
|
+
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(e => this.logger.debug(e));
|
|
196
214
|
}
|
|
197
215
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
198
216
|
if (!this.config.commands.interactionCommand.replyOnError)
|
|
199
217
|
return;
|
|
200
|
-
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(
|
|
218
|
+
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(e => this.logger.debug(e));
|
|
201
219
|
}
|
|
202
220
|
});
|
|
203
221
|
}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { CommandInteraction, PermissionFlags, PermissionString } from 'discord.js';
|
|
2
2
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
|
3
|
-
import { RecipleClient } from '../
|
|
3
|
+
import { RecipleClient } from '../RecipleClient';
|
|
4
4
|
export interface RecipleInteractionCommandExecute {
|
|
5
5
|
interaction: CommandInteraction;
|
|
6
6
|
command: InteractionCommandBuilder;
|
|
7
7
|
builder: InteractionCommandBuilder;
|
|
8
|
-
client: RecipleClient
|
|
8
|
+
client: RecipleClient<true>;
|
|
9
9
|
}
|
|
10
10
|
export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
11
11
|
readonly builder = "INTERACTION_COMMAND";
|
|
12
12
|
requiredPermissions: (PermissionFlags | PermissionString)[];
|
|
13
13
|
allowExecuteInDM: boolean;
|
|
14
14
|
execute: (options: RecipleInteractionCommandExecute) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Set required permissions before executing the command
|
|
17
|
+
*/
|
|
15
18
|
setRequiredPermissions(requiredPermissions: (keyof PermissionFlags)[]): InteractionCommandBuilder;
|
|
19
|
+
/**
|
|
20
|
+
* Set if command can be executed in dms
|
|
21
|
+
* @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
|
|
22
|
+
*/
|
|
16
23
|
setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
|
|
24
|
+
/**
|
|
25
|
+
* Function when the command is executed
|
|
26
|
+
*/
|
|
17
27
|
setExecute(execute: (options: RecipleInteractionCommandExecute) => void): InteractionCommandBuilder;
|
|
18
28
|
}
|
|
@@ -10,18 +10,30 @@ class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
|
|
|
10
10
|
this.allowExecuteInDM = true;
|
|
11
11
|
this.execute = () => { };
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Set required permissions before executing the command
|
|
15
|
+
*/
|
|
13
16
|
setRequiredPermissions(requiredPermissions) {
|
|
14
17
|
if (!requiredPermissions || !Array.isArray(requiredPermissions))
|
|
15
18
|
throw new Error('requiredPermissions must be an array.');
|
|
16
19
|
this.requiredPermissions = requiredPermissions;
|
|
17
20
|
return this;
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Set if command can be executed in dms
|
|
24
|
+
* @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
|
|
25
|
+
*/
|
|
19
26
|
setAllowExecuteInDM(allowExecuteInDM) {
|
|
27
|
+
// TODO: Deprecated this
|
|
20
28
|
if (typeof allowExecuteInDM !== 'boolean')
|
|
21
29
|
throw new Error('allowExecuteInDM must be a boolean.');
|
|
22
30
|
this.allowExecuteInDM = allowExecuteInDM;
|
|
31
|
+
process.emitWarning('InteractionCommandBuilder#setAllowExecuteInDM() method is deprecated in favor of setting SlashCommandBuilder#setDMPermission()', 'Deprecation Warning');
|
|
23
32
|
return this;
|
|
24
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Function when the command is executed
|
|
36
|
+
*/
|
|
25
37
|
setExecute(execute) {
|
|
26
38
|
if (!execute || typeof execute !== 'function')
|
|
27
39
|
throw new Error('execute must be a function.');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
2
2
|
import { Message, PermissionFlags, PermissionString } from 'discord.js';
|
|
3
3
|
import { Command } from 'fallout-utility';
|
|
4
|
-
import { RecipleClient } from '../
|
|
4
|
+
import { RecipleClient } from '../RecipleClient';
|
|
5
5
|
import { MessageCommandOptions } from './MessageCommandOptions';
|
|
6
6
|
export declare type CommandMessage = Command;
|
|
7
7
|
export interface RecipleMessageCommandExecute {
|
|
@@ -9,7 +9,7 @@ export interface RecipleMessageCommandExecute {
|
|
|
9
9
|
options: MessageCommandOptions;
|
|
10
10
|
command: CommandMessage;
|
|
11
11
|
builder: MessageCommandBuilder;
|
|
12
|
-
client: RecipleClient
|
|
12
|
+
client: RecipleClient<true>;
|
|
13
13
|
}
|
|
14
14
|
export interface MessageCommandValidatedOption {
|
|
15
15
|
name: string;
|
|
@@ -22,19 +22,51 @@ export declare class MessageCommandBuilder {
|
|
|
22
22
|
readonly builder = "MESSAGE_COMMAND";
|
|
23
23
|
name: string;
|
|
24
24
|
description: string;
|
|
25
|
+
aliases: string[];
|
|
25
26
|
options: MessageCommandOptionBuilder[];
|
|
26
27
|
validateOptions: boolean;
|
|
27
28
|
requiredPermissions: (PermissionFlags | PermissionString)[];
|
|
28
29
|
allowExecuteInDM: boolean;
|
|
29
30
|
allowExecuteByBots: boolean;
|
|
30
31
|
execute: (options: RecipleMessageCommandExecute) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the command name
|
|
34
|
+
*/
|
|
31
35
|
setName(name: string): MessageCommandBuilder;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the command description
|
|
38
|
+
*/
|
|
39
|
+
setDescription(description: string): MessageCommandBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* Add aliases to the command
|
|
42
|
+
*/
|
|
43
|
+
addAliases(...aliases: string[]): MessageCommandBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the default required permissions to execute this command
|
|
46
|
+
*/
|
|
32
47
|
setRequiredPermissions(permissions: (PermissionFlags | PermissionString)[]): MessageCommandBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Set if command can be executed in dms
|
|
50
|
+
*/
|
|
33
51
|
setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* Allow command to be executed by bots
|
|
54
|
+
*/
|
|
34
55
|
setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
|
|
35
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Function when the command is executed
|
|
58
|
+
*/
|
|
36
59
|
setExecute(execute: (options: RecipleMessageCommandExecute) => void): MessageCommandBuilder;
|
|
60
|
+
/**
|
|
61
|
+
* Add option to the command
|
|
62
|
+
*/
|
|
37
63
|
addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* Validate options before executing
|
|
66
|
+
*/
|
|
38
67
|
setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* validate given command options
|
|
70
|
+
*/
|
|
39
71
|
getCommandOptionValues(options: CommandMessage): MessageCommandValidatedOption[];
|
|
40
72
|
}
|
|
@@ -7,6 +7,7 @@ class MessageCommandBuilder {
|
|
|
7
7
|
this.builder = 'MESSAGE_COMMAND';
|
|
8
8
|
this.name = '';
|
|
9
9
|
this.description = '';
|
|
10
|
+
this.aliases = [];
|
|
10
11
|
this.options = [];
|
|
11
12
|
this.validateOptions = false;
|
|
12
13
|
this.requiredPermissions = [];
|
|
@@ -14,42 +15,76 @@ class MessageCommandBuilder {
|
|
|
14
15
|
this.allowExecuteByBots = false;
|
|
15
16
|
this.execute = () => { };
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets the command name
|
|
20
|
+
*/
|
|
17
21
|
setName(name) {
|
|
18
22
|
if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
19
23
|
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
|
|
20
24
|
this.name = name;
|
|
21
25
|
return this;
|
|
22
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets the command description
|
|
29
|
+
*/
|
|
30
|
+
setDescription(description) {
|
|
31
|
+
if (!description || typeof description !== 'string')
|
|
32
|
+
throw new TypeError('description must be a string.');
|
|
33
|
+
this.description = description;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Add aliases to the command
|
|
38
|
+
*/
|
|
39
|
+
addAliases(...aliases) {
|
|
40
|
+
if (!aliases.length)
|
|
41
|
+
throw new TypeError('Provide atleast one alias');
|
|
42
|
+
if (aliases.some(a => !a || typeof a !== 'string' || !a.match(/^[\w-]{1,32}$/)))
|
|
43
|
+
throw new TypeError('aliases must be strings and match the regex /^[\\w-]{1,32}$/');
|
|
44
|
+
if (this.name && aliases.some(a => a == this.name))
|
|
45
|
+
throw new TypeError('alias cannot have same name to its real command name');
|
|
46
|
+
this.aliases = [...new Set(aliases)];
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sets the default required permissions to execute this command
|
|
51
|
+
*/
|
|
23
52
|
setRequiredPermissions(permissions) {
|
|
24
53
|
if (!permissions || !Array.isArray(permissions))
|
|
25
54
|
throw new TypeError('permissions must be an array.');
|
|
26
55
|
this.requiredPermissions = permissions;
|
|
27
56
|
return this;
|
|
28
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Set if command can be executed in dms
|
|
60
|
+
*/
|
|
29
61
|
setAllowExecuteInDM(allowExecuteInDM) {
|
|
30
62
|
if (typeof allowExecuteInDM !== 'boolean')
|
|
31
63
|
throw new TypeError('allowExecuteInDM must be a boolean.');
|
|
32
64
|
this.allowExecuteInDM = allowExecuteInDM;
|
|
33
65
|
return this;
|
|
34
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Allow command to be executed by bots
|
|
69
|
+
*/
|
|
35
70
|
setAllowExecuteByBots(allowExecuteByBots) {
|
|
36
71
|
if (typeof allowExecuteByBots !== 'boolean')
|
|
37
72
|
throw new TypeError('allowExecuteByBots must be a boolean.');
|
|
38
73
|
this.allowExecuteByBots = allowExecuteByBots;
|
|
39
74
|
return this;
|
|
40
75
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.description = description;
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
76
|
+
/**
|
|
77
|
+
* Function when the command is executed
|
|
78
|
+
*/
|
|
47
79
|
setExecute(execute) {
|
|
48
80
|
if (!execute || typeof execute !== 'function')
|
|
49
81
|
throw new TypeError('execute must be a function.');
|
|
50
82
|
this.execute = execute;
|
|
51
83
|
return this;
|
|
52
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Add option to the command
|
|
87
|
+
*/
|
|
53
88
|
addOption(option) {
|
|
54
89
|
if (!option)
|
|
55
90
|
throw new TypeError('option must be a MessageOption.');
|
|
@@ -61,12 +96,18 @@ class MessageCommandBuilder {
|
|
|
61
96
|
this.options = [...this.options, option];
|
|
62
97
|
return this;
|
|
63
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Validate options before executing
|
|
101
|
+
*/
|
|
64
102
|
setValidateOptions(validateOptions) {
|
|
65
103
|
if (typeof validateOptions !== 'boolean')
|
|
66
104
|
throw new TypeError('validateOptions must be a boolean.');
|
|
67
105
|
this.validateOptions = validateOptions;
|
|
68
106
|
return this;
|
|
69
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* validate given command options
|
|
110
|
+
*/
|
|
70
111
|
getCommandOptionValues(options) {
|
|
71
112
|
const args = options.args || [];
|
|
72
113
|
const required = this.options.filter(o => o.required);
|
|
@@ -3,8 +3,20 @@ export declare class MessageCommandOptionBuilder {
|
|
|
3
3
|
description: string;
|
|
4
4
|
required: boolean;
|
|
5
5
|
validator: (value: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Set command option name
|
|
8
|
+
*/
|
|
6
9
|
setName(name: string): MessageCommandOptionBuilder;
|
|
10
|
+
/**
|
|
11
|
+
* Set command option description
|
|
12
|
+
*/
|
|
7
13
|
setDescription(description: string): MessageCommandOptionBuilder;
|
|
14
|
+
/**
|
|
15
|
+
* Set if this option is required
|
|
16
|
+
*/
|
|
8
17
|
setRequired(required: boolean): MessageCommandOptionBuilder;
|
|
18
|
+
/**
|
|
19
|
+
* Set your custom function to validate given value for this option
|
|
20
|
+
*/
|
|
9
21
|
setValidator(validator: (value: string) => boolean): MessageCommandOptionBuilder;
|
|
10
22
|
}
|
|
@@ -8,24 +8,36 @@ class MessageCommandOptionBuilder {
|
|
|
8
8
|
this.required = false;
|
|
9
9
|
this.validator = () => true;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Set command option name
|
|
13
|
+
*/
|
|
11
14
|
setName(name) {
|
|
12
15
|
if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
13
16
|
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/.');
|
|
14
17
|
this.name = name;
|
|
15
18
|
return this;
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Set command option description
|
|
22
|
+
*/
|
|
17
23
|
setDescription(description) {
|
|
18
24
|
if (!description || typeof description !== 'string')
|
|
19
25
|
throw new TypeError('description must be a string.');
|
|
20
26
|
this.description = description;
|
|
21
27
|
return this;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Set if this option is required
|
|
31
|
+
*/
|
|
23
32
|
setRequired(required) {
|
|
24
33
|
if (typeof required !== 'boolean')
|
|
25
34
|
throw new TypeError('required must be a boolean.');
|
|
26
35
|
this.required = required;
|
|
27
36
|
return this;
|
|
28
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Set your custom function to validate given value for this option
|
|
40
|
+
*/
|
|
29
41
|
setValidator(validator) {
|
|
30
42
|
if (!validator || typeof validator !== 'function')
|
|
31
43
|
throw new TypeError('validator must be a function.');
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { MessageCommandValidatedOption } from './MessageCommandBuilder';
|
|
2
2
|
export declare class MessageCommandOptions extends Array<MessageCommandValidatedOption> {
|
|
3
3
|
constructor(options: MessageCommandValidatedOption[]);
|
|
4
|
+
/**
|
|
5
|
+
* Get the option info
|
|
6
|
+
*/
|
|
4
7
|
get(name: string, requied: true): MessageCommandValidatedOption;
|
|
5
8
|
get(name: string, requied?: boolean): MessageCommandValidatedOption | null;
|
|
9
|
+
/**
|
|
10
|
+
* Get the option value
|
|
11
|
+
*/
|
|
6
12
|
getValue(name: string, requied: true): string;
|
|
7
13
|
getValue(name: string, requied?: boolean): string | null;
|
|
8
14
|
}
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InteractionCommandBuilder, RecipleInteractionCommandExecute } from './classes/builders/InteractionCommandBuilder';
|
|
2
2
|
import { MessageCommandBuilder, RecipleMessageCommandExecute } from './classes/builders/MessageCommandBuilder';
|
|
3
|
-
import { RecipleClient } from './classes/
|
|
3
|
+
import { RecipleClient } from './classes/RecipleClient';
|
|
4
4
|
export declare type recipleCommandBuilders = MessageCommandBuilder | InteractionCommandBuilder;
|
|
5
5
|
export declare type recipleCommandBuildersExecute = RecipleInteractionCommandExecute | RecipleMessageCommandExecute;
|
|
6
6
|
export declare type loadedModules = {
|
|
@@ -16,9 +16,9 @@ export declare class RecipleScript {
|
|
|
16
16
|
export interface RecipleModule {
|
|
17
17
|
script: RecipleScript;
|
|
18
18
|
info: {
|
|
19
|
-
filename
|
|
19
|
+
filename?: string;
|
|
20
20
|
versions: string[];
|
|
21
|
-
path
|
|
21
|
+
path?: string;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
export declare function loadModules(client: RecipleClient): Promise<loadedModules>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
|
|
2
2
|
import { ApplicationCommandDataResolvable } from 'discord.js';
|
|
3
|
-
import { RecipleClient } from './classes/
|
|
3
|
+
import { RecipleClient } from './classes/RecipleClient';
|
|
4
4
|
import { ContextMenuCommandBuilder, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder } from '@discordjs/builders';
|
|
5
5
|
export declare type interactionCommandBuilders = InteractionCommandBuilder | ContextMenuCommandBuilder | SlashCommandBuilder | SlashCommandSubcommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandGroupBuilder | SlashCommandSubcommandsOnlyBuilder;
|
|
6
6
|
export declare function registerInteractionCommands(client: RecipleClient, cmds?: (interactionCommandBuilders | ApplicationCommandDataResolvable)[], overwriteGuilds?: string | string[]): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "A Discord.js bot",
|
|
5
5
|
"author": "FalloutStudios",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"reciple": "bin/bin.js"
|
|
10
10
|
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16.9.0"
|
|
13
|
+
},
|
|
11
14
|
"files": [
|
|
12
15
|
"bin",
|
|
13
16
|
"resource",
|
|
@@ -16,12 +19,11 @@
|
|
|
16
19
|
"README.md"
|
|
17
20
|
],
|
|
18
21
|
"scripts": {
|
|
19
|
-
"clean": "
|
|
20
|
-
"
|
|
21
|
-
"build": "yarn
|
|
22
|
-
"
|
|
23
|
-
"test": "cd test && npx reciple"
|
|
24
|
-
"test:build": "yarn run build && yarn test:run"
|
|
22
|
+
"clean": "rm -rf bin",
|
|
23
|
+
"build": "yarn clean && npx tsc && npm un reciple -g && npm i ./ -g",
|
|
24
|
+
"build:publish": "yarn run build && yarn publish",
|
|
25
|
+
"test": "yarn run build && yarn test:start",
|
|
26
|
+
"test:start": "cd test && npx reciple"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"commander": "^9.3.0",
|
package/resource/reciple.yml
CHANGED