reciple 1.6.0 → 1.7.0
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 +3 -1
- package/bin/bin.js +6 -3
- package/bin/index.d.ts +1 -1
- package/bin/index.js +1 -1
- package/bin/reciple/classes/RecipleClient.d.ts +37 -4
- package/bin/reciple/classes/RecipleClient.js +89 -38
- package/bin/reciple/classes/{Config.d.ts → RecipleConfig.d.ts} +22 -0
- package/bin/reciple/classes/{Config.js → RecipleConfig.js} +25 -1
- package/bin/reciple/classes/builders/InteractionCommandBuilder.d.ts +4 -3
- package/bin/reciple/classes/builders/InteractionCommandBuilder.js +4 -8
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +34 -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/flags.d.ts +7 -1
- package/bin/reciple/flags.js +6 -0
- package/bin/reciple/hasPermissions.d.ts +4 -1
- package/bin/reciple/hasPermissions.js +3 -0
- package/bin/reciple/isIgnoredChannel.d.ts +4 -1
- package/bin/reciple/isIgnoredChannel.js +3 -0
- package/bin/reciple/logger.d.ts +4 -1
- package/bin/reciple/logger.js +24 -4
- package/bin/reciple/modules.d.ts +4 -1
- package/bin/reciple/modules.js +15 -8
- package/bin/reciple/registerInteractionCommands.d.ts +3 -0
- package/bin/reciple/registerInteractionCommands.js +13 -6
- package/bin/reciple/version.d.ts +12 -0
- package/bin/reciple/version.js +12 -0
- package/package.json +13 -5
- package/resource/reciple.yml +4 -0
package/README.md
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
<a href="https://www.codefactor.io/repository/github/falloutstudios/reciple/overview/main"><img src="https://www.codefactor.io/repository/github/falloutstudios/reciple/badge/main" alt="CodeFactor"></a>
|
|
7
7
|
</h1>
|
|
8
8
|
|
|
9
|
-
A simple
|
|
9
|
+
A simple Dicord.js command handler that just works.
|
|
10
10
|
|
|
11
|
+
# Join Discord
|
|
12
|
+
[](https://discord.gg/2CattJYNpw)
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
13
15
|
To install the bot, run the following command:
|
package/bin/bin.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
};
|
|
12
12
|
var _a, _b;
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
const
|
|
14
|
+
const RecipleConfig_1 = require("./reciple/classes/RecipleConfig");
|
|
15
15
|
const RecipleClient_1 = require("./reciple/classes/RecipleClient");
|
|
16
16
|
const fs_1 = require("fs");
|
|
17
17
|
const version_1 = require("./reciple/version");
|
|
@@ -28,13 +28,16 @@ if ((0, fs_1.readdirSync)('./').filter(f => !f.startsWith('.') && allowedFiles.i
|
|
|
28
28
|
if (ask.toString().toLowerCase() !== 'y')
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
|
-
const config = new
|
|
31
|
+
const config = new RecipleConfig_1.RecipleConfig((_b = flags_1.flags.config) !== null && _b !== void 0 ? _b : './reciple.yml').parseConfig().getConfig();
|
|
32
32
|
const client = new RecipleClient_1.RecipleClient(Object.assign({ config: config }, config.client));
|
|
33
|
+
if (config.fileLogging.clientLogs)
|
|
34
|
+
client.logger.info('Reciple Client v' + version_1.version + ' is starting...');
|
|
33
35
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
36
|
yield client.startModules();
|
|
35
37
|
client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
38
|
var _c;
|
|
37
|
-
|
|
39
|
+
if (client.isClientLogsEnabled())
|
|
40
|
+
client.logger.warn(`Logged in as ${((_c = client.user) === null || _c === void 0 ? void 0 : _c.tag) || 'Unknown'}!`);
|
|
38
41
|
yield client.loadModules();
|
|
39
42
|
client.addCommandListeners();
|
|
40
43
|
}));
|
package/bin/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import discord from 'discord.js';
|
|
2
2
|
export declare const discordjs: typeof discord;
|
|
3
3
|
export * from './reciple/classes/RecipleClient';
|
|
4
|
-
export * from './reciple/classes/
|
|
4
|
+
export * from './reciple/classes/RecipleConfig';
|
|
5
5
|
export * from './reciple/classes/builders/InteractionCommandBuilder';
|
|
6
6
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
7
7
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
package/bin/index.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.discordjs = void 0;
|
|
|
21
21
|
const discord_js_1 = __importDefault(require("discord.js"));
|
|
22
22
|
exports.discordjs = discord_js_1.default;
|
|
23
23
|
__exportStar(require("./reciple/classes/RecipleClient"), exports);
|
|
24
|
-
__exportStar(require("./reciple/classes/
|
|
24
|
+
__exportStar(require("./reciple/classes/RecipleConfig"), 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);
|
|
@@ -2,11 +2,11 @@ import { InteractionCommandBuilder, RecipleInteractionCommandExecute } from './b
|
|
|
2
2
|
import { interactionCommandBuilders } from '../registerInteractionCommands';
|
|
3
3
|
import { MessageCommandBuilder, RecipleMessageCommandExecute } from './builders/MessageCommandBuilder';
|
|
4
4
|
import { Logger as ILogger } from 'fallout-utility';
|
|
5
|
-
import { Config } from './
|
|
5
|
+
import { Config } from './RecipleConfig';
|
|
6
6
|
import { ApplicationCommandDataResolvable, Awaitable, Client, ClientEvents, ClientOptions, CommandInteraction, Interaction, Message } from 'discord.js';
|
|
7
7
|
import { recipleCommandBuilders, RecipleModule, RecipleScript } from '../modules';
|
|
8
8
|
export interface RecipleClientOptions extends ClientOptions {
|
|
9
|
-
config
|
|
9
|
+
config?: Config;
|
|
10
10
|
}
|
|
11
11
|
export interface RecipleClientCommands {
|
|
12
12
|
MESSAGE_COMMANDS: {
|
|
@@ -19,6 +19,7 @@ export interface RecipleClientCommands {
|
|
|
19
19
|
export interface RecipleClientEvents extends ClientEvents {
|
|
20
20
|
recipleMessageCommandCreate: [command: RecipleMessageCommandExecute];
|
|
21
21
|
recipleInteractionCommandCreate: [command: RecipleInteractionCommandExecute];
|
|
22
|
+
recipleReplyError: [error: any];
|
|
22
23
|
}
|
|
23
24
|
export interface RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
24
25
|
on<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
@@ -41,13 +42,45 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
41
42
|
logger: ILogger;
|
|
42
43
|
version: string;
|
|
43
44
|
constructor(options: RecipleClientOptions);
|
|
44
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Load modules
|
|
47
|
+
*/
|
|
48
|
+
startModules(folder?: string): Promise<RecipleClient<Ready>>;
|
|
49
|
+
/**
|
|
50
|
+
* Execute `onLoad()` from client modules and register interaction commands if enabled
|
|
51
|
+
*/
|
|
45
52
|
loadModules(): Promise<RecipleClient<Ready>>;
|
|
46
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Add module
|
|
55
|
+
*/
|
|
56
|
+
addModule(script: RecipleScript, registerCommands?: boolean, info?: RecipleModule['info']): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Add interaction or message command to client
|
|
59
|
+
*/
|
|
47
60
|
addCommand(command: recipleCommandBuilders): RecipleClient<Ready>;
|
|
61
|
+
/**
|
|
62
|
+
* Listed to command executions
|
|
63
|
+
*/
|
|
48
64
|
addCommandListeners(): RecipleClient<Ready>;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a Message command
|
|
67
|
+
*/
|
|
49
68
|
messageCommandExecute(message: Message, prefix?: string): Promise<void | RecipleMessageCommandExecute>;
|
|
69
|
+
/**
|
|
70
|
+
* Execute an Interaction command
|
|
71
|
+
*/
|
|
50
72
|
interactionCommandExecute(interaction: Interaction | CommandInteraction): Promise<void | RecipleInteractionCommandExecute>;
|
|
73
|
+
/**
|
|
74
|
+
* Get a message from config
|
|
75
|
+
*/
|
|
51
76
|
getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
|
|
77
|
+
/**
|
|
78
|
+
* Returns true if client logs is enabled
|
|
79
|
+
*/
|
|
80
|
+
isClientLogsEnabled(): boolean;
|
|
81
|
+
private replpyError;
|
|
82
|
+
/**
|
|
83
|
+
* Error message when a command fails to execute
|
|
84
|
+
*/
|
|
52
85
|
private _commandExecuteError;
|
|
53
86
|
}
|
|
@@ -22,66 +22,89 @@ const isIgnoredChannel_1 = require("../isIgnoredChannel");
|
|
|
22
22
|
const hasPermissions_1 = require("../hasPermissions");
|
|
23
23
|
const version_1 = require("../version");
|
|
24
24
|
const logger_1 = require("../logger");
|
|
25
|
+
const RecipleConfig_1 = require("./RecipleConfig");
|
|
25
26
|
const discord_js_1 = require("discord.js");
|
|
26
27
|
const modules_1 = require("../modules");
|
|
27
28
|
const MessageCommandOptions_1 = require("./builders/MessageCommandOptions");
|
|
28
29
|
class RecipleClient extends discord_js_1.Client {
|
|
29
30
|
constructor(options) {
|
|
31
|
+
var _a, _b, _c;
|
|
30
32
|
super(options);
|
|
33
|
+
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
31
34
|
this.commands = { MESSAGE_COMMANDS: {}, INTERACTION_COMMANDS: {} };
|
|
32
35
|
this.otherApplicationCommandData = [];
|
|
33
36
|
this.modules = [];
|
|
34
37
|
this.version = version_1.version;
|
|
35
|
-
this.logger = (0, logger_1.logger)(!!options.config.fileLogging.stringifyLoggedJSON, !!options.config.fileLogging.debugmode);
|
|
38
|
+
this.logger = (0, logger_1.logger)(!!((_a = options.config) === null || _a === void 0 ? void 0 : _a.fileLogging.stringifyLoggedJSON), !!((_b = options.config) === null || _b === void 0 ? void 0 : _b.fileLogging.debugmode));
|
|
36
39
|
if (!options.config)
|
|
37
40
|
throw new Error('Config is not defined.');
|
|
38
|
-
this.config = options.config;
|
|
41
|
+
this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
|
|
39
42
|
if (this.config.fileLogging.enabled)
|
|
40
43
|
this.logger.logFile(this.config.fileLogging.logFilePath, false);
|
|
41
|
-
this.logger.info('Reciple Client v' + version_1.version + ' is starting...');
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Load modules
|
|
47
|
+
*/
|
|
48
|
+
startModules(folder) {
|
|
44
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
this.
|
|
46
|
-
|
|
50
|
+
if (this.isClientLogsEnabled())
|
|
51
|
+
this.logger.info(`Loading Modules from ${folder !== null && folder !== void 0 ? folder : this.config.modulesFolder}`);
|
|
52
|
+
const modules = yield (0, modules_1.loadModules)(this, folder);
|
|
47
53
|
if (!modules)
|
|
48
54
|
throw new Error('Failed to load modules.');
|
|
49
55
|
this.modules = modules.modules;
|
|
50
56
|
return this;
|
|
51
57
|
});
|
|
52
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Execute `onLoad()` from client modules and register interaction commands if enabled
|
|
61
|
+
*/
|
|
53
62
|
loadModules() {
|
|
63
|
+
var _a, _b;
|
|
54
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
for (
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
for (let m in this.modules) {
|
|
66
|
+
const module_ = this.modules[m];
|
|
67
|
+
if (typeof ((_a = module_.script) === null || _a === void 0 ? void 0 : _a.onLoad) === 'function') {
|
|
68
|
+
yield Promise.resolve(module_.script.onLoad(this)).catch(err => {
|
|
69
|
+
var _a;
|
|
70
|
+
if (this.isClientLogsEnabled()) {
|
|
71
|
+
this.logger.error(`Error loading ${(_a = module_.info.filename) !== null && _a !== void 0 ? _a : 'unknown module'}:`);
|
|
72
|
+
this.logger.error(err);
|
|
73
|
+
}
|
|
74
|
+
this.modules = this.modules.filter((r, i) => i.toString() !== m.toString());
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (typeof ((_b = module_.script) === null || _b === void 0 ? void 0 : _b.commands) !== 'undefined') {
|
|
78
|
+
for (const command of module_.script.commands) {
|
|
79
|
+
this.addCommand(command);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
58
82
|
}
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
this.
|
|
83
|
+
if (this.isClientLogsEnabled()) {
|
|
84
|
+
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
85
|
+
this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
|
|
86
|
+
this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
|
|
62
87
|
}
|
|
63
|
-
this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
|
|
64
|
-
this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
|
|
65
88
|
if (!this.config.commands.interactionCommand.registerCommands)
|
|
66
89
|
return this;
|
|
67
90
|
yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
|
|
68
91
|
return this;
|
|
69
92
|
});
|
|
70
93
|
}
|
|
71
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Add module
|
|
96
|
+
*/
|
|
97
|
+
addModule(script, registerCommands = true, info) {
|
|
72
98
|
var _a;
|
|
73
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
100
|
this.modules.push({
|
|
75
101
|
script,
|
|
76
|
-
info: {
|
|
77
|
-
filename: undefined,
|
|
78
|
-
versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
|
|
79
|
-
path: undefined
|
|
80
|
-
}
|
|
102
|
+
info: Object.assign({ filename: undefined, versions: typeof script.versions == 'string' ? [script.versions] : script.versions, path: undefined }, info)
|
|
81
103
|
});
|
|
82
104
|
if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
|
|
83
105
|
yield Promise.resolve(script.onLoad(this));
|
|
84
|
-
this.
|
|
106
|
+
if (this.isClientLogsEnabled())
|
|
107
|
+
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
85
108
|
for (const command of (_a = script.commands) !== null && _a !== void 0 ? _a : []) {
|
|
86
109
|
if (!command.name)
|
|
87
110
|
continue;
|
|
@@ -92,6 +115,9 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
92
115
|
yield (0, registerInteractionCommands_1.registerInteractionCommands)(this, [...Object.values(this.commands.INTERACTION_COMMANDS), ...this.otherApplicationCommandData]);
|
|
93
116
|
});
|
|
94
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Add interaction or message command to client
|
|
120
|
+
*/
|
|
95
121
|
addCommand(command) {
|
|
96
122
|
var _a;
|
|
97
123
|
if (command.builder === 'MESSAGE_COMMAND') {
|
|
@@ -100,11 +126,14 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
100
126
|
else if (command.builder === 'INTERACTION_COMMAND') {
|
|
101
127
|
this.commands.INTERACTION_COMMANDS[command.name] = command;
|
|
102
128
|
}
|
|
103
|
-
else {
|
|
129
|
+
else if (this.isClientLogsEnabled()) {
|
|
104
130
|
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
105
131
|
}
|
|
106
132
|
return this;
|
|
107
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Listed to command executions
|
|
136
|
+
*/
|
|
108
137
|
addCommandListeners() {
|
|
109
138
|
if (this.config.commands.messageCommand.enabled)
|
|
110
139
|
this.on('messageCreate', (message) => { this.messageCommandExecute(message); });
|
|
@@ -112,18 +141,23 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
112
141
|
this.on('interactionCreate', (interaction) => { this.interactionCommandExecute(interaction); });
|
|
113
142
|
return this;
|
|
114
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Execute a Message command
|
|
146
|
+
*/
|
|
115
147
|
messageCommandExecute(message, prefix) {
|
|
116
|
-
var _a;
|
|
148
|
+
var _a, _b;
|
|
117
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
150
|
if (!message.content || !this.isReady())
|
|
119
151
|
return;
|
|
120
152
|
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
121
|
-
if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command)
|
|
153
|
+
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
122
154
|
return;
|
|
123
|
-
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()]
|
|
155
|
+
const command = (_a = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()]) !== null && _a !== void 0 ? _a : (this.config.commands.messageCommand.allowCommandAlias
|
|
156
|
+
? 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()); }))
|
|
157
|
+
: undefined);
|
|
124
158
|
if (!command)
|
|
125
159
|
return;
|
|
126
|
-
if ((0, hasPermissions_1.hasPermissions)(command.name, (
|
|
160
|
+
if ((0, hasPermissions_1.hasPermissions)(command.name, (_b = message.member) === null || _b === void 0 ? void 0 : _b.permissions, this.config.permissions.messageCommands, command)) {
|
|
127
161
|
if (!command.allowExecuteInDM && message.channel.type === 'DM'
|
|
128
162
|
|| !command.allowExecuteByBots
|
|
129
163
|
&& (message.author.bot || message.author.system)
|
|
@@ -132,11 +166,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
132
166
|
const commandOptions = command.getCommandOptionValues(parseCommand);
|
|
133
167
|
if (command.validateOptions) {
|
|
134
168
|
if (commandOptions.some(o => o.invalid)) {
|
|
135
|
-
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(
|
|
169
|
+
yield message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this.replpyError(er));
|
|
136
170
|
return;
|
|
137
171
|
}
|
|
138
172
|
if (commandOptions.some(o => o.missing)) {
|
|
139
|
-
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(
|
|
173
|
+
yield message.reply(this.getMessage('notEnoughArguments', 'Not enough arguments.')).catch(er => this.replpyError(er));
|
|
140
174
|
return;
|
|
141
175
|
}
|
|
142
176
|
}
|
|
@@ -152,10 +186,13 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
152
186
|
return options;
|
|
153
187
|
}
|
|
154
188
|
else {
|
|
155
|
-
yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(
|
|
189
|
+
yield message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this.replpyError(er));
|
|
156
190
|
}
|
|
157
191
|
});
|
|
158
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Execute an Interaction command
|
|
195
|
+
*/
|
|
159
196
|
interactionCommandExecute(interaction) {
|
|
160
197
|
var _a;
|
|
161
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -165,10 +202,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
165
202
|
if (!command)
|
|
166
203
|
return;
|
|
167
204
|
if ((0, hasPermissions_1.hasPermissions)(command.name, (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined, this.config.permissions.interactionCommands, command)) {
|
|
168
|
-
|
|
169
|
-
if (!command.allowExecuteInDM && !interaction.inCachedGuild() || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
170
|
-
return;
|
|
171
|
-
if (!command)
|
|
205
|
+
if (!command || (0, isIgnoredChannel_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
|
|
172
206
|
return;
|
|
173
207
|
const options = {
|
|
174
208
|
interaction: interaction,
|
|
@@ -181,29 +215,46 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
181
215
|
return options;
|
|
182
216
|
}
|
|
183
217
|
else {
|
|
184
|
-
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(
|
|
218
|
+
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this.replpyError(er));
|
|
185
219
|
}
|
|
186
220
|
});
|
|
187
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Get a message from config
|
|
224
|
+
*/
|
|
188
225
|
getMessage(messageKey, defaultMessage) {
|
|
189
226
|
var _a, _b;
|
|
190
227
|
return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
|
|
191
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Returns true if client logs is enabled
|
|
231
|
+
*/
|
|
232
|
+
isClientLogsEnabled() {
|
|
233
|
+
return !!this.config.fileLogging.clientLogs;
|
|
234
|
+
}
|
|
235
|
+
replpyError(error) {
|
|
236
|
+
this.emit('recipleReplyError', error);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Error message when a command fails to execute
|
|
240
|
+
*/
|
|
192
241
|
_commandExecuteError(err, command) {
|
|
193
242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
this.
|
|
195
|
-
|
|
243
|
+
if (this.isClientLogsEnabled()) {
|
|
244
|
+
this.logger.error(`An error occured executing ${command.builder.builder == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
|
|
245
|
+
this.logger.error(err);
|
|
246
|
+
}
|
|
196
247
|
if (!err || !command)
|
|
197
248
|
return;
|
|
198
249
|
if (command === null || command === void 0 ? void 0 : command.message) {
|
|
199
250
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
200
251
|
return;
|
|
201
|
-
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(
|
|
252
|
+
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this.replpyError(er));
|
|
202
253
|
}
|
|
203
254
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
204
255
|
if (!this.config.commands.interactionCommand.replyOnError)
|
|
205
256
|
return;
|
|
206
|
-
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(
|
|
257
|
+
yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(er => this.replpyError(er));
|
|
207
258
|
}
|
|
208
259
|
});
|
|
209
260
|
}
|
|
@@ -10,6 +10,7 @@ export interface Config {
|
|
|
10
10
|
messageCommand: {
|
|
11
11
|
enabled: boolean;
|
|
12
12
|
replyOnError: boolean;
|
|
13
|
+
allowCommandAlias: boolean;
|
|
13
14
|
commandArgumentSeparator: string;
|
|
14
15
|
};
|
|
15
16
|
interactionCommand: {
|
|
@@ -38,6 +39,7 @@ export interface Config {
|
|
|
38
39
|
fileLogging: {
|
|
39
40
|
enabled: boolean;
|
|
40
41
|
debugmode: boolean;
|
|
42
|
+
clientLogs: boolean;
|
|
41
43
|
stringifyLoggedJSON: boolean;
|
|
42
44
|
logFilePath: string;
|
|
43
45
|
};
|
|
@@ -52,10 +54,30 @@ export interface Config {
|
|
|
52
54
|
export declare class RecipleConfig {
|
|
53
55
|
config?: Config;
|
|
54
56
|
configPath: string;
|
|
57
|
+
static defaultConfigPath: string;
|
|
55
58
|
constructor(configPath: string);
|
|
59
|
+
/**
|
|
60
|
+
* Parse the config file
|
|
61
|
+
*/
|
|
56
62
|
parseConfig(): RecipleConfig;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the parsed config file
|
|
65
|
+
*/
|
|
57
66
|
getConfig(): Config;
|
|
67
|
+
/**
|
|
68
|
+
* Parse token from config
|
|
69
|
+
*/
|
|
58
70
|
parseToken(askIfNull?: boolean): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Check if the config version is supported
|
|
73
|
+
*/
|
|
59
74
|
private isSupportedConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Ask for a token
|
|
77
|
+
*/
|
|
60
78
|
private askToken;
|
|
79
|
+
/**
|
|
80
|
+
* Get default config
|
|
81
|
+
*/
|
|
82
|
+
static getDefaultConfig(): Config;
|
|
61
83
|
}
|
|
@@ -17,10 +17,13 @@ class RecipleConfig {
|
|
|
17
17
|
throw new Error('Config path is not defined');
|
|
18
18
|
this.configPath = configPath;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse the config file
|
|
22
|
+
*/
|
|
20
23
|
parseConfig() {
|
|
21
24
|
var _a;
|
|
22
25
|
if (!(0, fs_1.existsSync)(this.configPath)) {
|
|
23
|
-
const defaultConfigPath =
|
|
26
|
+
const defaultConfigPath = RecipleConfig.defaultConfigPath;
|
|
24
27
|
if (!(0, fs_1.existsSync)(defaultConfigPath))
|
|
25
28
|
throw new Error('Default Config file not found. Please reinstall Reciple.');
|
|
26
29
|
const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
|
|
@@ -42,12 +45,18 @@ class RecipleConfig {
|
|
|
42
45
|
throw new Error('Unsupported config version. Your config version: ' + (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || 'No version specified.') + ', Reciple version: ' + version_1.version);
|
|
43
46
|
return this;
|
|
44
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the parsed config file
|
|
50
|
+
*/
|
|
45
51
|
getConfig() {
|
|
46
52
|
if (!this.config)
|
|
47
53
|
throw new Error('Config is not parsed.');
|
|
48
54
|
this.config.token = this.parseToken() || 'TOKEN';
|
|
49
55
|
return this.config;
|
|
50
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse token from config
|
|
59
|
+
*/
|
|
51
60
|
parseToken(askIfNull = true) {
|
|
52
61
|
var _a, _b;
|
|
53
62
|
let token = flags_1.token || null;
|
|
@@ -64,12 +73,27 @@ class RecipleConfig {
|
|
|
64
73
|
}
|
|
65
74
|
return token || (askIfNull ? this.askToken() : null);
|
|
66
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if the config version is supported
|
|
78
|
+
*/
|
|
67
79
|
isSupportedConfig() {
|
|
68
80
|
var _a;
|
|
69
81
|
return (0, version_1.isSupportedVersion)(((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || '0.0.0', version_1.version);
|
|
70
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Ask for a token
|
|
85
|
+
*/
|
|
71
86
|
askToken() {
|
|
72
87
|
return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
|
|
73
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Get default config
|
|
91
|
+
*/
|
|
92
|
+
static getDefaultConfig() {
|
|
93
|
+
if (!(0, fs_1.existsSync)(this.defaultConfigPath))
|
|
94
|
+
throw new Error("Default config file does not exists.");
|
|
95
|
+
return yaml_1.default.parse((0, fs_1.readFileSync)(this.defaultConfigPath, 'utf-8'));
|
|
96
|
+
}
|
|
74
97
|
}
|
|
75
98
|
exports.RecipleConfig = RecipleConfig;
|
|
99
|
+
RecipleConfig.defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
|
|
@@ -12,11 +12,12 @@ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
|
|
|
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;
|
|
16
19
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
|
|
20
|
+
* Function when the command is executed
|
|
19
21
|
*/
|
|
20
|
-
setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
|
|
21
22
|
setExecute(execute: (options: RecipleInteractionCommandExecute) => void): InteractionCommandBuilder;
|
|
22
23
|
}
|
|
@@ -10,6 +10,9 @@ 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.');
|
|
@@ -17,15 +20,8 @@ class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
|
|
|
17
20
|
return this;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @deprecated use `InteractionCommandBuilder.setDMPermission()` instead
|
|
23
|
+
* Function when the command is executed
|
|
22
24
|
*/
|
|
23
|
-
setAllowExecuteInDM(allowExecuteInDM) {
|
|
24
|
-
if (typeof allowExecuteInDM !== 'boolean')
|
|
25
|
-
throw new Error('allowExecuteInDM must be a boolean.');
|
|
26
|
-
this.allowExecuteInDM = allowExecuteInDM;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
25
|
setExecute(execute) {
|
|
30
26
|
if (!execute || typeof execute !== 'function')
|
|
31
27
|
throw new Error('execute must be a function.');
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
2
2
|
import { Message, PermissionFlags, PermissionString } from 'discord.js';
|
|
3
|
-
import { Command } from 'fallout-utility';
|
|
3
|
+
import { Command as CommandMessage } from 'fallout-utility';
|
|
4
4
|
import { RecipleClient } from '../RecipleClient';
|
|
5
5
|
import { MessageCommandOptions } from './MessageCommandOptions';
|
|
6
|
-
export declare type CommandMessage = Command;
|
|
7
6
|
export interface RecipleMessageCommandExecute {
|
|
8
7
|
message: Message;
|
|
9
8
|
options: MessageCommandOptions;
|
|
@@ -22,19 +21,51 @@ export declare class MessageCommandBuilder {
|
|
|
22
21
|
readonly builder = "MESSAGE_COMMAND";
|
|
23
22
|
name: string;
|
|
24
23
|
description: string;
|
|
24
|
+
aliases: string[];
|
|
25
25
|
options: MessageCommandOptionBuilder[];
|
|
26
26
|
validateOptions: boolean;
|
|
27
27
|
requiredPermissions: (PermissionFlags | PermissionString)[];
|
|
28
28
|
allowExecuteInDM: boolean;
|
|
29
29
|
allowExecuteByBots: boolean;
|
|
30
30
|
execute: (options: RecipleMessageCommandExecute) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the command name
|
|
33
|
+
*/
|
|
31
34
|
setName(name: string): MessageCommandBuilder;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the command description
|
|
37
|
+
*/
|
|
38
|
+
setDescription(description: string): MessageCommandBuilder;
|
|
39
|
+
/**
|
|
40
|
+
* Add aliases to the command
|
|
41
|
+
*/
|
|
42
|
+
addAliases(...aliases: string[]): MessageCommandBuilder;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the default required permissions to execute this command
|
|
45
|
+
*/
|
|
32
46
|
setRequiredPermissions(permissions: (PermissionFlags | PermissionString)[]): MessageCommandBuilder;
|
|
47
|
+
/**
|
|
48
|
+
* Set if command can be executed in dms
|
|
49
|
+
*/
|
|
33
50
|
setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
|
|
51
|
+
/**
|
|
52
|
+
* Allow command to be executed by bots
|
|
53
|
+
*/
|
|
34
54
|
setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
|
|
35
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Function when the command is executed
|
|
57
|
+
*/
|
|
36
58
|
setExecute(execute: (options: RecipleMessageCommandExecute) => void): MessageCommandBuilder;
|
|
59
|
+
/**
|
|
60
|
+
* Add option to the command
|
|
61
|
+
*/
|
|
37
62
|
addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
|
|
63
|
+
/**
|
|
64
|
+
* Validate options before executing
|
|
65
|
+
*/
|
|
38
66
|
setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
|
|
67
|
+
/**
|
|
68
|
+
* validate given command options
|
|
69
|
+
*/
|
|
39
70
|
getCommandOptionValues(options: CommandMessage): MessageCommandValidatedOption[];
|
|
40
71
|
}
|
|
@@ -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/flags.d.ts
CHANGED
package/bin/reciple/flags.js
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.token = exports.flags = void 0;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
+
/**
|
|
6
|
+
* Used flags
|
|
7
|
+
*/
|
|
5
8
|
exports.flags = commander_1.program
|
|
6
9
|
.option('-t, --token <token>', 'Replace used bot token')
|
|
7
10
|
.option('-c, --config <config>', 'Change path to config file')
|
|
8
11
|
.option('-D, --debugmode', 'Enabled debug mode')
|
|
9
12
|
.option('-v, --version', 'Display version')
|
|
10
13
|
.parse().opts();
|
|
14
|
+
/**
|
|
15
|
+
* Temporary token flag
|
|
16
|
+
*/
|
|
11
17
|
exports.token = exports.flags.token;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Permissions } from 'discord.js';
|
|
2
2
|
import { recipleCommandBuilders } from './modules';
|
|
3
|
-
import { Config } from './classes/
|
|
3
|
+
import { Config } from './classes/RecipleConfig';
|
|
4
|
+
/**
|
|
5
|
+
* Check if the user has permissions to execute the given command name
|
|
6
|
+
*/
|
|
4
7
|
export declare function hasPermissions(commandName: string, memberPermissions?: Permissions, configConmmandPermissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands'], builder?: recipleCommandBuilders): boolean;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasPermissions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if the user has permissions to execute the given command name
|
|
6
|
+
*/
|
|
4
7
|
function hasPermissions(commandName, memberPermissions, configConmmandPermissions, builder) {
|
|
5
8
|
var _a, _b;
|
|
6
9
|
if (!(configConmmandPermissions === null || configConmmandPermissions === void 0 ? void 0 : configConmmandPermissions.enabled))
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { Config } from './classes/
|
|
1
|
+
import { Config } from './classes/RecipleConfig';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the channel id is ignored in config file
|
|
4
|
+
*/
|
|
2
5
|
export declare function isIgnoredChannel(channelId: string, ignoredChannelsConfig?: Config["ignoredChannels"]): boolean;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isIgnoredChannel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if the channel id is ignored in config file
|
|
6
|
+
*/
|
|
4
7
|
function isIgnoredChannel(channelId, ignoredChannelsConfig) {
|
|
5
8
|
if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
|
|
6
9
|
return false;
|
package/bin/reciple/logger.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Logger } from 'fallout-utility';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Create new logger
|
|
4
|
+
*/
|
|
5
|
+
export declare function logger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
|
package/bin/reciple/logger.js
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.logger = void 0;
|
|
4
7
|
const fallout_utility_1 = require("fallout-utility");
|
|
5
8
|
const flags_1 = require("./flags");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
/**
|
|
11
|
+
* Create new logger
|
|
12
|
+
*/
|
|
13
|
+
function logger(stringifyJSON, debugmode = false, colorizeMessage = true) {
|
|
14
|
+
var _a;
|
|
15
|
+
return new fallout_utility_1.Logger({
|
|
9
16
|
stringifyJSON: stringifyJSON,
|
|
10
|
-
|
|
17
|
+
enableDebugMode: (_a = flags_1.flags.debugmode) !== null && _a !== void 0 ? _a : debugmode,
|
|
18
|
+
loggerName: 'Main',
|
|
19
|
+
prefixes: {
|
|
20
|
+
[fallout_utility_1.LogLevels.INFO]: (name) => `[${chalk_1.default.bold("INFO" + (name ? chalk_1.default.dim(" - ") + name : ''))}]`,
|
|
21
|
+
[fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.bold.yellow("WARN" + (name ? chalk_1.default.dim(" - ") + name : ''))}]`,
|
|
22
|
+
[fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.bold.red("ERROR" + (name ? chalk_1.default.dim(" - ") + name : ''))}]`,
|
|
23
|
+
[fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.bold.blue("DEBUG" + (name ? chalk_1.default.dim(" - ") + name : ''))}]`
|
|
24
|
+
},
|
|
25
|
+
colorMessages: {
|
|
26
|
+
[fallout_utility_1.LogLevels.INFO]: (message) => message,
|
|
27
|
+
[fallout_utility_1.LogLevels.WARN]: (message) => !colorizeMessage ? message : chalk_1.default.yellow(message),
|
|
28
|
+
[fallout_utility_1.LogLevels.ERROR]: (message) => !colorizeMessage ? message : chalk_1.default.red(message),
|
|
29
|
+
[fallout_utility_1.LogLevels.DEBUG]: (message) => !colorizeMessage ? message : chalk_1.default.blue(message)
|
|
30
|
+
}
|
|
11
31
|
});
|
|
12
32
|
}
|
|
13
33
|
exports.logger = logger;
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -21,4 +21,7 @@ export interface RecipleModule {
|
|
|
21
21
|
path?: string;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Load modules from folder
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadModules(client: RecipleClient, folder?: string): Promise<loadedModules>;
|
package/bin/reciple/modules.js
CHANGED
|
@@ -17,12 +17,14 @@ const fs_1 = require("fs");
|
|
|
17
17
|
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
|
+
/**
|
|
21
|
+
* Load modules from folder
|
|
22
|
+
*/
|
|
23
|
+
function loadModules(client, folder) {
|
|
21
24
|
var _a, _b;
|
|
22
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
26
|
const response = { commands: [], modules: [] };
|
|
24
|
-
const modulesDir = client.config.modulesFolder || './modules';
|
|
25
|
-
const logger = client.logger;
|
|
27
|
+
const modulesDir = client.config.modulesFolder || folder || './modules';
|
|
26
28
|
if (!(0, fs_1.existsSync)(modulesDir))
|
|
27
29
|
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
28
30
|
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
@@ -51,17 +53,21 @@ function loadModules(client) {
|
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
catch (error) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (client.isClientLogsEnabled()) {
|
|
57
|
+
client.logger.error(`Failed to load module ${script}`);
|
|
58
|
+
client.logger.error(error);
|
|
59
|
+
}
|
|
56
60
|
continue;
|
|
57
61
|
}
|
|
58
62
|
response.commands.push(...commands.filter((c) => {
|
|
59
63
|
if (!c.name) {
|
|
60
|
-
|
|
64
|
+
if (client.isClientLogsEnabled())
|
|
65
|
+
client.logger.error(`A ${c.builder} command name is not defined in ${script}`);
|
|
61
66
|
return false;
|
|
62
67
|
}
|
|
63
68
|
if (c.builder === 'MESSAGE_COMMAND' && c.options.length && c.options.some(o => !o.name)) {
|
|
64
|
-
|
|
69
|
+
if (client.isClientLogsEnabled())
|
|
70
|
+
client.logger.error(`A ${c.builder} option name is not defined in ${script}`);
|
|
65
71
|
return false;
|
|
66
72
|
}
|
|
67
73
|
return true;
|
|
@@ -74,7 +80,8 @@ function loadModules(client) {
|
|
|
74
80
|
path: modulePath
|
|
75
81
|
}
|
|
76
82
|
});
|
|
77
|
-
|
|
83
|
+
if (client.isClientLogsEnabled())
|
|
84
|
+
client.logger.info(`Loaded module ${script}`);
|
|
78
85
|
}
|
|
79
86
|
return response;
|
|
80
87
|
});
|
|
@@ -3,4 +3,7 @@ import { ApplicationCommandDataResolvable } from 'discord.js';
|
|
|
3
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
|
+
/**
|
|
7
|
+
* Register interaction commands
|
|
8
|
+
*/
|
|
6
9
|
export declare function registerInteractionCommands(client: RecipleClient, cmds?: (interactionCommandBuilders | ApplicationCommandDataResolvable)[], overwriteGuilds?: string | string[]): Promise<void>;
|
|
@@ -10,6 +10,9 @@ 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
|
+
/**
|
|
14
|
+
* Register interaction commands
|
|
15
|
+
*/
|
|
13
16
|
function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
14
17
|
var _a, _b, _c;
|
|
15
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -24,7 +27,8 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
24
27
|
undefined)) !== null && _d !== void 0 ? _d : cmd.requiredPermissions;
|
|
25
28
|
cmd.setRequiredPermissions(permissions);
|
|
26
29
|
client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
|
|
27
|
-
client.
|
|
30
|
+
if (client.isClientLogsEnabled())
|
|
31
|
+
client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
28
32
|
return cmd.toJSON();
|
|
29
33
|
}
|
|
30
34
|
return c.toJSON();
|
|
@@ -33,17 +37,20 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
33
37
|
const guilds = typeof configGuilds === 'object' ? configGuilds : [configGuilds];
|
|
34
38
|
if (!guilds || !(guilds === null || guilds === void 0 ? void 0 : guilds.length)) {
|
|
35
39
|
(_b = client.application) === null || _b === void 0 ? void 0 : _b.commands.set(commands).then(() => {
|
|
36
|
-
client.
|
|
37
|
-
|
|
40
|
+
if (client.isClientLogsEnabled())
|
|
41
|
+
client.logger.warn('No guilds were specified for interaction commands. Registered interaction commands globally.');
|
|
42
|
+
});
|
|
38
43
|
}
|
|
39
44
|
else {
|
|
40
|
-
client.
|
|
45
|
+
if (client.isClientLogsEnabled())
|
|
46
|
+
client.logger.warn(`Registering ${commands.length} interaction commands to ${guilds.length} guild(s).`);
|
|
41
47
|
for (const guild of guilds) {
|
|
42
48
|
if (!guild)
|
|
43
49
|
continue;
|
|
44
50
|
(_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands, guild).then(() => {
|
|
45
|
-
client.
|
|
46
|
-
|
|
51
|
+
if (client.isClientLogsEnabled())
|
|
52
|
+
client.logger.warn(`Registered ${commands.length} interaction command(s) for ${guild}.`);
|
|
53
|
+
});
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
});
|
package/bin/reciple/version.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current reciple version
|
|
3
|
+
*/
|
|
1
4
|
export declare const version: string;
|
|
5
|
+
/**
|
|
6
|
+
* Check if the version is valid
|
|
7
|
+
*/
|
|
2
8
|
export declare function isValidVersion(ver: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Parse the version string
|
|
11
|
+
*/
|
|
3
12
|
export declare function parseVersion(ver: string): {
|
|
4
13
|
major: number;
|
|
5
14
|
minor: number;
|
|
6
15
|
patch: number;
|
|
7
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if the given version is supported by the given version range
|
|
19
|
+
*/
|
|
8
20
|
export declare function isSupportedVersion(versionRange: string, supportedVersion?: string): boolean;
|
package/bin/reciple/version.js
CHANGED
|
@@ -5,11 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isSupportedVersion = exports.parseVersion = exports.isValidVersion = exports.version = void 0;
|
|
7
7
|
const semver_1 = __importDefault(require("semver"));
|
|
8
|
+
/**
|
|
9
|
+
* Current reciple version
|
|
10
|
+
*/
|
|
8
11
|
exports.version = require('../../package.json').version;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the version is valid
|
|
14
|
+
*/
|
|
9
15
|
function isValidVersion(ver) {
|
|
10
16
|
return semver_1.default.valid(semver_1.default.coerce(ver)) !== null;
|
|
11
17
|
}
|
|
12
18
|
exports.isValidVersion = isValidVersion;
|
|
19
|
+
/**
|
|
20
|
+
* Parse the version string
|
|
21
|
+
*/
|
|
13
22
|
function parseVersion(ver) {
|
|
14
23
|
var _a, _b;
|
|
15
24
|
if (!isValidVersion(ver))
|
|
@@ -18,6 +27,9 @@ function parseVersion(ver) {
|
|
|
18
27
|
return { major: parseInt(major), minor: parseInt(minor), patch: parseInt(patch) };
|
|
19
28
|
}
|
|
20
29
|
exports.parseVersion = parseVersion;
|
|
30
|
+
/**
|
|
31
|
+
* Check if the given version is supported by the given version range
|
|
32
|
+
*/
|
|
21
33
|
function isSupportedVersion(versionRange, supportedVersion) {
|
|
22
34
|
supportedVersion = supportedVersion || exports.version;
|
|
23
35
|
if (!isValidVersion(versionRange))
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A Discord.js bot",
|
|
5
5
|
"author": "FalloutStudios",
|
|
6
|
+
"homepage": "https://falloutstudios.github.io/Reciple",
|
|
6
7
|
"license": "GPL-3.0",
|
|
7
8
|
"main": "bin/index.js",
|
|
8
9
|
"bin": {
|
|
@@ -22,14 +23,17 @@
|
|
|
22
23
|
"clean": "rm -rf bin",
|
|
23
24
|
"build": "yarn clean && npx tsc && npm un reciple -g && npm i ./ -g",
|
|
24
25
|
"build:publish": "yarn run build && yarn publish",
|
|
25
|
-
"test": "yarn run build && yarn test:
|
|
26
|
-
"test:start": "cd test && npx reciple"
|
|
26
|
+
"test": "yarn run build && yarn test:start",
|
|
27
|
+
"test:start": "cd test && npx reciple",
|
|
28
|
+
"postpublish": "yarn build:docs && yarn update:docs",
|
|
29
|
+
"build:docs": "cd docs && yarn build",
|
|
30
|
+
"update:docs": "cd docs && yarn update"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
33
|
+
"chalk": "4.1.2",
|
|
29
34
|
"commander": "^9.3.0",
|
|
30
|
-
"discord.js": "^13.8.1",
|
|
31
35
|
"dotenv": "^16.0.1",
|
|
32
|
-
"fallout-utility": "^1.
|
|
36
|
+
"fallout-utility": "^1.4.2",
|
|
33
37
|
"semver": "^7.3.7",
|
|
34
38
|
"wildcard-match": "^5.1.2",
|
|
35
39
|
"yaml": "^2.1.1"
|
|
@@ -37,6 +41,10 @@
|
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/node": "^18.0.0",
|
|
39
43
|
"@types/semver": "^7.3.10",
|
|
44
|
+
"discord.js": "^13.8.1",
|
|
40
45
|
"typescript": "^4.7.4"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"discord.js": "13.8.x"
|
|
41
49
|
}
|
|
42
50
|
}
|
package/resource/reciple.yml
CHANGED
|
@@ -13,6 +13,8 @@ commands:
|
|
|
13
13
|
enabled: true
|
|
14
14
|
# reply when an error occured
|
|
15
15
|
replyOnError: false
|
|
16
|
+
# Allow executing commands via aliases
|
|
17
|
+
allowCommandAlias: false
|
|
16
18
|
# command argument separator
|
|
17
19
|
commandArgumentSeparator: ' '
|
|
18
20
|
interactionCommand:
|
|
@@ -60,6 +62,8 @@ fileLogging:
|
|
|
60
62
|
enabled: true
|
|
61
63
|
# enable debug mode
|
|
62
64
|
debugmode: false
|
|
65
|
+
# enable if reciple will use the logger
|
|
66
|
+
clientLogs: true
|
|
63
67
|
# stringify logged JSONs
|
|
64
68
|
stringifyLoggedJSON: false
|
|
65
69
|
# log file path
|