reciple 5.4.1-pre.5 → 5.4.3
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/{types/bin.d.ts → bin.d.ts} +0 -0
- package/bin/{cjs/bin.js → bin.js} +11 -22
- package/bin/{types/index.d.ts → index.d.ts} +0 -0
- package/bin/{cjs/index.js → index.js} +0 -0
- package/bin/{types/reciple → reciple}/classes/CommandCooldownManager.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/CommandCooldownManager.js +12 -8
- package/bin/{types/reciple → reciple}/classes/MessageCommandOptionManager.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/MessageCommandOptionManager.js +4 -5
- package/bin/{types/reciple → reciple}/classes/RecipleClient.d.ts +4 -4
- package/bin/{mjs/reciple → reciple}/classes/RecipleClient.js +68 -61
- package/bin/{types/reciple → reciple}/classes/RecipleConfig.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/RecipleConfig.js +6 -9
- package/bin/{types/reciple → reciple}/classes/builders/MessageCommandBuilder.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/builders/MessageCommandBuilder.js +22 -17
- package/bin/{types/reciple → reciple}/classes/builders/MessageCommandOptionBuilder.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/builders/MessageCommandOptionBuilder.js +5 -1
- package/bin/{types/reciple → reciple}/classes/builders/SlashCommandBuilder.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/builders/SlashCommandBuilder.js +29 -29
- package/bin/{types/reciple → reciple}/flags.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/flags.js +0 -0
- package/bin/{types/reciple → reciple}/logger.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/logger.js +1 -2
- package/bin/{types/reciple → reciple}/modules.d.ts +0 -0
- package/bin/reciple/modules.js +113 -0
- package/bin/{types/reciple → reciple}/permissions.d.ts +6 -2
- package/bin/reciple/permissions.js +34 -0
- package/bin/{types/reciple → reciple}/registerApplicationCommands.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/registerApplicationCommands.js +9 -5
- package/bin/{types/reciple → reciple}/types/builders.d.ts +1 -1
- package/bin/{cjs/reciple → reciple}/types/builders.js +0 -0
- package/bin/{types/reciple → reciple}/types/commands.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/types/commands.js +0 -0
- package/bin/{types/reciple → reciple}/types/paramOptions.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/types/paramOptions.js +0 -0
- package/bin/{types/reciple → reciple}/util.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/util.js +0 -0
- package/bin/{types/reciple → reciple}/version.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/version.js +0 -0
- package/package.json +10 -14
- package/bin/cjs/package.json +0 -3
- package/bin/cjs/reciple/classes/CommandCooldownManager.js +0 -92
- package/bin/cjs/reciple/classes/RecipleClient.js +0 -400
- package/bin/cjs/reciple/classes/builders/MessageCommandBuilder.js +0 -233
- package/bin/cjs/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -71
- package/bin/cjs/reciple/modules.js +0 -100
- package/bin/cjs/reciple/permissions.js +0 -28
- package/bin/cjs/reciple/registerApplicationCommands.js +0 -64
- package/bin/mjs/bin.js +0 -46
- package/bin/mjs/index.js +0 -17
- package/bin/mjs/package.json +0 -3
- package/bin/mjs/reciple/classes/MessageCommandOptionManager.js +0 -21
- package/bin/mjs/reciple/classes/RecipleConfig.js +0 -92
- package/bin/mjs/reciple/classes/builders/SlashCommandBuilder.js +0 -204
- package/bin/mjs/reciple/flags.js +0 -28
- package/bin/mjs/reciple/logger.js +0 -28
- package/bin/mjs/reciple/modules.js +0 -81
- package/bin/mjs/reciple/permissions.js +0 -23
- package/bin/mjs/reciple/types/builders.js +0 -8
- package/bin/mjs/reciple/types/commands.js +0 -12
- package/bin/mjs/reciple/types/paramOptions.js +0 -1
- package/bin/mjs/reciple/util.js +0 -7
- package/bin/mjs/reciple/version.js +0 -38
|
File without changes
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
5
|
};
|
|
15
|
-
var _a, _b, _c, _d;
|
|
16
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
7
|
const RecipleClient_1 = require("./reciple/classes/RecipleClient");
|
|
18
8
|
const RecipleConfig_1 = require("./reciple/classes/RecipleConfig");
|
|
@@ -26,37 +16,36 @@ const discord_js_1 = require("discord.js");
|
|
|
26
16
|
const path_1 = __importDefault(require("path"));
|
|
27
17
|
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
28
18
|
const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
|
|
29
|
-
if ((0, fs_1.readdirSync)(flags_1.cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)(
|
|
30
|
-
const ask = (
|
|
19
|
+
if ((0, fs_1.readdirSync)(flags_1.cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)(flags_1.flags.config ?? configPath)) {
|
|
20
|
+
const ask = (flags_1.flags.yes ? 'y' : null) ?? (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
|
|
31
21
|
if (ask.toString().toLowerCase() !== 'y')
|
|
32
22
|
process.exit(0);
|
|
33
23
|
}
|
|
34
24
|
let configParser;
|
|
35
25
|
try {
|
|
36
|
-
configParser = new RecipleConfig_1.RecipleConfig(
|
|
26
|
+
configParser = new RecipleConfig_1.RecipleConfig(flags_1.flags.config ?? configPath).parseConfig();
|
|
37
27
|
}
|
|
38
28
|
catch (err) {
|
|
39
29
|
console.error(`${chalk_1.default.bold.red('Config Error')}: ${chalk_1.default.white(err.message)}`);
|
|
40
30
|
process.exit(1);
|
|
41
31
|
}
|
|
42
32
|
const config = configParser.getConfig();
|
|
43
|
-
const client = new RecipleClient_1.RecipleClient(
|
|
33
|
+
const client = new RecipleClient_1.RecipleClient({ config: config, ...config.client });
|
|
44
34
|
if (config.fileLogging.clientLogs)
|
|
45
35
|
client.logger.info('Starting Reciple client v' + version_1.rawVersion);
|
|
46
|
-
(() =>
|
|
47
|
-
|
|
48
|
-
client.on('ready', () =>
|
|
49
|
-
var _e;
|
|
36
|
+
(async () => {
|
|
37
|
+
await client.startModules((0, discord_js_1.normalizeArray)(config.modulesFolder));
|
|
38
|
+
client.on('ready', async () => {
|
|
50
39
|
if (client.isClientLogsEnabled())
|
|
51
|
-
client.logger.warn(`Logged in as ${
|
|
40
|
+
client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
|
|
52
41
|
client.on('cacheSweep', () => {
|
|
53
42
|
client.cooldowns.clean();
|
|
54
43
|
});
|
|
55
|
-
|
|
44
|
+
await client.loadModules();
|
|
56
45
|
client.addCommandListeners();
|
|
57
|
-
})
|
|
46
|
+
});
|
|
58
47
|
client.login(config.token).catch(err => {
|
|
59
48
|
if (client.isClientLogsEnabled())
|
|
60
49
|
client.logger.error(err);
|
|
61
50
|
});
|
|
62
|
-
})
|
|
51
|
+
})();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandCooldownManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
2
5
|
/**
|
|
3
6
|
* cooled-down users manager
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class CommandCooldownManager extends Array {
|
|
6
9
|
constructor(...data) {
|
|
7
|
-
super(...normalizeArray(data));
|
|
10
|
+
super(...(0, discord_js_1.normalizeArray)(data));
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* Alias for `CommandCooldownManager#push()`
|
|
@@ -72,16 +75,17 @@ export class CommandCooldownManager extends Array {
|
|
|
72
75
|
* @param data Cooled-down user data
|
|
73
76
|
*/
|
|
74
77
|
static checkOptions(options, data) {
|
|
75
|
-
if (options?.user && options.user.id !== data.user.id)
|
|
78
|
+
if (options?.user !== undefined && options.user.id !== data.user.id)
|
|
76
79
|
return false;
|
|
77
|
-
if (options?.guild && options.guild
|
|
80
|
+
if (options?.guild !== undefined && options.guild?.id !== data.guild?.id)
|
|
78
81
|
return false;
|
|
79
|
-
if (options?.channel && options.channel.id !== data.channel?.id)
|
|
82
|
+
if (options?.channel !== undefined && options.channel.id !== data.channel?.id)
|
|
80
83
|
return false;
|
|
81
|
-
if (options?.command && options.command !== data.command)
|
|
84
|
+
if (options?.command !== undefined && options.command !== data.command)
|
|
82
85
|
return false;
|
|
83
|
-
if (options?.type && options.type !== data.type)
|
|
86
|
+
if (options?.type !== undefined && options.type !== data.type)
|
|
84
87
|
return false;
|
|
85
88
|
return true;
|
|
86
89
|
}
|
|
87
90
|
}
|
|
91
|
+
exports.CommandCooldownManager = CommandCooldownManager;
|
|
File without changes
|
|
@@ -11,16 +11,15 @@ class MessageCommandOptionManager extends Array {
|
|
|
11
11
|
}
|
|
12
12
|
get(name, required) {
|
|
13
13
|
const option = this.find(o => o.name == name);
|
|
14
|
-
if (!
|
|
14
|
+
if (!option?.value == undefined && required)
|
|
15
15
|
throw new TypeError(`Can't find option named ${name}`);
|
|
16
|
-
return option
|
|
16
|
+
return option ?? null;
|
|
17
17
|
}
|
|
18
18
|
getValue(name, requied) {
|
|
19
|
-
var _a;
|
|
20
19
|
const option = this.get(name, requied);
|
|
21
|
-
if (!
|
|
20
|
+
if (!option?.value && requied)
|
|
22
21
|
throw new TypeError(`Value of option named ${name} is undefined`);
|
|
23
|
-
return
|
|
22
|
+
return option?.value ?? null;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
exports.MessageCommandOptionManager = MessageCommandOptionManager;
|
|
@@ -39,13 +39,13 @@ export interface RecipleClientEvents extends ClientEvents {
|
|
|
39
39
|
*/
|
|
40
40
|
export interface RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
41
41
|
on<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
42
|
-
on<E extends string | symbol>(event:
|
|
42
|
+
on<E extends string | symbol>(event: E, listener: (...args: any) => Awaitable<void>): this;
|
|
43
43
|
once<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
44
|
-
once<E extends keyof string | symbol>(event:
|
|
44
|
+
once<E extends keyof string | symbol>(event: E, listener: (...args: any) => Awaitable<void>): this;
|
|
45
45
|
emit<E extends keyof RecipleClientEvents>(event: E, ...args: RecipleClientEvents[E]): boolean;
|
|
46
|
-
emit<E extends string | symbol>(event:
|
|
46
|
+
emit<E extends string | symbol>(event: E, ...args: any): boolean;
|
|
47
47
|
off<E extends keyof RecipleClientEvents>(event: E, listener: (...args: RecipleClientEvents[E]) => Awaitable<void>): this;
|
|
48
|
-
off<E extends string | symbol>(event:
|
|
48
|
+
off<E extends string | symbol>(event: E, listener: (...args: any) => Awaitable<void>): this;
|
|
49
49
|
removeAllListeners<E extends keyof RecipleClientEvents>(event?: E): this;
|
|
50
50
|
removeAllListeners(event?: string | symbol): this;
|
|
51
51
|
isReady(): this is RecipleClient<true>;
|
|
@@ -1,49 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RecipleClient = void 0;
|
|
7
|
+
const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
|
|
8
|
+
const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
|
|
9
|
+
const builders_1 = require("../types/builders");
|
|
10
|
+
const registerApplicationCommands_1 = require("../registerApplicationCommands");
|
|
11
|
+
const commands_1 = require("../types/commands");
|
|
12
|
+
const permissions_1 = require("../permissions");
|
|
13
|
+
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
14
|
+
const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
|
|
15
|
+
const fallout_utility_1 = require("fallout-utility");
|
|
16
|
+
const RecipleConfig_1 = require("./RecipleConfig");
|
|
17
|
+
const modules_1 = require("../modules");
|
|
18
|
+
const logger_1 = require("../logger");
|
|
19
|
+
const version_1 = require("../version");
|
|
20
|
+
const flags_1 = require("../flags");
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const discord_js_1 = require("discord.js");
|
|
23
|
+
class RecipleClient extends discord_js_1.Client {
|
|
24
|
+
config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
19
25
|
commands = { slashCommands: {}, messageCommands: {} };
|
|
20
26
|
additionalApplicationCommands = [];
|
|
21
|
-
cooldowns = new CommandCooldownManager();
|
|
27
|
+
cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
22
28
|
modules = [];
|
|
23
29
|
logger;
|
|
24
|
-
version = version;
|
|
30
|
+
version = version_1.version;
|
|
25
31
|
/**
|
|
26
32
|
* @param options Client options
|
|
27
33
|
*/
|
|
28
34
|
constructor(options) {
|
|
29
35
|
super(options);
|
|
30
|
-
this.logger = createLogger(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
|
|
36
|
+
this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
|
|
31
37
|
if (!options.config)
|
|
32
38
|
throw new Error('Config is not defined.');
|
|
33
39
|
this.config = { ...this.config, ...(options.config ?? {}) };
|
|
34
40
|
if (this.config.fileLogging.enabled)
|
|
35
|
-
this.logger.logFile(
|
|
41
|
+
this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
|
|
36
42
|
}
|
|
37
43
|
/**
|
|
38
44
|
* Load modules from modules folder
|
|
39
45
|
* @param folders List of folders that contains the modules you want to load
|
|
40
46
|
*/
|
|
41
47
|
async startModules(...folders) {
|
|
42
|
-
folders = normalizeArray(folders).map(f =>
|
|
48
|
+
folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
|
|
43
49
|
for (const folder of folders) {
|
|
44
50
|
if (this.isClientLogsEnabled())
|
|
45
51
|
this.logger.info(`Loading Modules from ${folder}`);
|
|
46
|
-
const modules = await getModules(this, folder).catch(() => null);
|
|
52
|
+
const modules = await (0, modules_1.getModules)(this, folder).catch(() => null);
|
|
47
53
|
if (!modules) {
|
|
48
54
|
if (this.isClientLogsEnabled())
|
|
49
55
|
this.logger.error(`Failed to load modules from ${folder}`);
|
|
@@ -80,7 +86,7 @@ export class RecipleClient extends Client {
|
|
|
80
86
|
this.logger.info(`${Object.keys(this.commands.slashCommands).length} slash commands loaded.`);
|
|
81
87
|
}
|
|
82
88
|
if (this.config.commands.slashCommand.registerCommands) {
|
|
83
|
-
await registerApplicationCommands({
|
|
89
|
+
await (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
84
90
|
client: this,
|
|
85
91
|
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
86
92
|
guilds: this.config.commands.slashCommand.guilds
|
|
@@ -115,7 +121,7 @@ export class RecipleClient extends Client {
|
|
|
115
121
|
this.addCommand(command);
|
|
116
122
|
}
|
|
117
123
|
if (registerCommands)
|
|
118
|
-
await registerApplicationCommands({
|
|
124
|
+
await (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
119
125
|
client: this,
|
|
120
126
|
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
121
127
|
guilds: this.config.commands.slashCommand.guilds
|
|
@@ -126,11 +132,11 @@ export class RecipleClient extends Client {
|
|
|
126
132
|
* @param command Slash/Message command builder
|
|
127
133
|
*/
|
|
128
134
|
addCommand(command) {
|
|
129
|
-
if (command.type === CommandBuilderType.SlashCommand) {
|
|
130
|
-
this.commands.slashCommands[command.name] = SlashCommandBuilder.resolveSlashCommand(command);
|
|
135
|
+
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
136
|
+
this.commands.slashCommands[command.name] = SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command);
|
|
131
137
|
}
|
|
132
|
-
else if (command.type === CommandBuilderType.MessageCommand) {
|
|
133
|
-
this.commands.messageCommands[command.name] = MessageCommandBuilder.resolveMessageCommand(command);
|
|
138
|
+
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
139
|
+
this.commands.messageCommands[command.name] = MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
|
|
134
140
|
}
|
|
135
141
|
else if (this.isClientLogsEnabled()) {
|
|
136
142
|
this.logger.error(`Unknow command "${typeof command ?? 'unknown'}".`);
|
|
@@ -154,7 +160,7 @@ export class RecipleClient extends Client {
|
|
|
154
160
|
async slashCommandExecute(interaction) {
|
|
155
161
|
if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
|
|
156
162
|
return;
|
|
157
|
-
const command = this.findCommand(interaction.commandName, CommandBuilderType.SlashCommand);
|
|
163
|
+
const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
|
|
158
164
|
if (!command)
|
|
159
165
|
return;
|
|
160
166
|
const executeData = {
|
|
@@ -162,15 +168,15 @@ export class RecipleClient extends Client {
|
|
|
162
168
|
builder: command,
|
|
163
169
|
client: this
|
|
164
170
|
};
|
|
165
|
-
if (userHasCommandPermissions({
|
|
171
|
+
if ((0, permissions_1.userHasCommandPermissions)({
|
|
166
172
|
builder: command,
|
|
167
173
|
memberPermissions: interaction.memberPermissions ?? undefined,
|
|
168
174
|
commandPermissions: this.config.commands.slashCommand.permissions
|
|
169
175
|
})) {
|
|
170
176
|
if (!command)
|
|
171
177
|
return;
|
|
172
|
-
if (interaction.
|
|
173
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.MissingBotPermissions })) {
|
|
178
|
+
if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
|
|
179
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
|
|
174
180
|
await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
175
181
|
}
|
|
176
182
|
return;
|
|
@@ -180,20 +186,20 @@ export class RecipleClient extends Client {
|
|
|
180
186
|
command: command.name,
|
|
181
187
|
channel: interaction.channel ?? undefined,
|
|
182
188
|
guild: interaction.guild,
|
|
183
|
-
type: CommandBuilderType.SlashCommand
|
|
189
|
+
type: builders_1.CommandBuilderType.SlashCommand
|
|
184
190
|
};
|
|
185
191
|
if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
186
192
|
this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
|
|
187
193
|
}
|
|
188
194
|
else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
|
|
189
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
|
|
195
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
|
|
190
196
|
await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
191
197
|
}
|
|
192
198
|
return;
|
|
193
199
|
}
|
|
194
200
|
return this._executeCommand(command, executeData);
|
|
195
201
|
}
|
|
196
|
-
else if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.MissingMemberPermissions })) {
|
|
202
|
+
else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
|
|
197
203
|
await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
198
204
|
}
|
|
199
205
|
}
|
|
@@ -205,13 +211,13 @@ export class RecipleClient extends Client {
|
|
|
205
211
|
async messageCommandExecute(message, prefix) {
|
|
206
212
|
if (!message.content || !this.isReady())
|
|
207
213
|
return;
|
|
208
|
-
const parseCommand = getCommand(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
214
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
209
215
|
if (!parseCommand || !parseCommand?.command)
|
|
210
216
|
return;
|
|
211
|
-
const command = this.findCommand(parseCommand.command, CommandBuilderType.MessageCommand);
|
|
217
|
+
const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
|
|
212
218
|
if (!command)
|
|
213
219
|
return;
|
|
214
|
-
const commandOptions = await validateMessageCommandOptions(command, parseCommand);
|
|
220
|
+
const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
|
|
215
221
|
const executeData = {
|
|
216
222
|
message: message,
|
|
217
223
|
options: commandOptions,
|
|
@@ -219,29 +225,29 @@ export class RecipleClient extends Client {
|
|
|
219
225
|
builder: command,
|
|
220
226
|
client: this
|
|
221
227
|
};
|
|
222
|
-
if (userHasCommandPermissions({
|
|
228
|
+
if ((0, permissions_1.userHasCommandPermissions)({
|
|
223
229
|
builder: command,
|
|
224
230
|
memberPermissions: message.member?.permissions,
|
|
225
231
|
commandPermissions: this.config.commands.messageCommand.permissions
|
|
226
232
|
})) {
|
|
227
|
-
if (!command.allowExecuteInDM && message.channel.type === ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
233
|
+
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
228
234
|
return;
|
|
229
235
|
if (command.validateOptions) {
|
|
230
236
|
if (commandOptions.some(o => o.invalid)) {
|
|
231
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) })) {
|
|
237
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) })) {
|
|
232
238
|
message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
233
239
|
}
|
|
234
240
|
return;
|
|
235
241
|
}
|
|
236
242
|
if (commandOptions.some(o => o.missing)) {
|
|
237
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) })) {
|
|
243
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) })) {
|
|
238
244
|
message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
239
245
|
}
|
|
240
246
|
return;
|
|
241
247
|
}
|
|
242
248
|
}
|
|
243
|
-
if (message.
|
|
244
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.MissingBotPermissions })) {
|
|
249
|
+
if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
|
|
250
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
|
|
245
251
|
message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
246
252
|
}
|
|
247
253
|
return;
|
|
@@ -251,20 +257,20 @@ export class RecipleClient extends Client {
|
|
|
251
257
|
command: command.name,
|
|
252
258
|
channel: message.channel,
|
|
253
259
|
guild: message.guild,
|
|
254
|
-
type: CommandBuilderType.MessageCommand
|
|
260
|
+
type: builders_1.CommandBuilderType.MessageCommand
|
|
255
261
|
};
|
|
256
262
|
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
257
263
|
this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
|
|
258
264
|
}
|
|
259
265
|
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
260
|
-
if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
|
|
266
|
+
if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
|
|
261
267
|
await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
262
268
|
}
|
|
263
269
|
return;
|
|
264
270
|
}
|
|
265
271
|
return this._executeCommand(command, executeData);
|
|
266
272
|
}
|
|
267
|
-
else if (!await this._haltCommand(command, { executeData, reason: CommandHaltReason.MissingMemberPermissions })) {
|
|
273
|
+
else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
|
|
268
274
|
message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
269
275
|
}
|
|
270
276
|
}
|
|
@@ -278,9 +284,9 @@ export class RecipleClient extends Client {
|
|
|
278
284
|
}
|
|
279
285
|
findCommand(command, type) {
|
|
280
286
|
switch (type) {
|
|
281
|
-
case CommandBuilderType.SlashCommand:
|
|
287
|
+
case builders_1.CommandBuilderType.SlashCommand:
|
|
282
288
|
return this.commands.slashCommands[command];
|
|
283
|
-
case CommandBuilderType.MessageCommand:
|
|
289
|
+
case builders_1.CommandBuilderType.MessageCommand:
|
|
284
290
|
return this.commands.messageCommands[command.toLowerCase()]
|
|
285
291
|
?? (this.config.commands.messageCommand.allowCommandAlias
|
|
286
292
|
? Object.values(this.commands.messageCommands).find(c => c.aliases.some(a => a == command?.toLowerCase()))
|
|
@@ -305,10 +311,10 @@ export class RecipleClient extends Client {
|
|
|
305
311
|
async _haltCommand(command, haltData) {
|
|
306
312
|
try {
|
|
307
313
|
const haltResolved = (command.halt
|
|
308
|
-
? await (command.type == CommandBuilderType.SlashCommand
|
|
309
|
-
?
|
|
310
|
-
:
|
|
311
|
-
: false)
|
|
314
|
+
? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand
|
|
315
|
+
? command.halt(haltData)
|
|
316
|
+
: command.halt(haltData)).catch(err => { console.log(err); })
|
|
317
|
+
: false) || false;
|
|
312
318
|
this.emit('recipleCommandHalt', haltData);
|
|
313
319
|
return haltResolved;
|
|
314
320
|
}
|
|
@@ -322,17 +328,17 @@ export class RecipleClient extends Client {
|
|
|
322
328
|
}
|
|
323
329
|
async _executeCommand(command, executeData) {
|
|
324
330
|
try {
|
|
325
|
-
await Promise.resolve(command.type === CommandBuilderType.SlashCommand
|
|
331
|
+
await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
|
|
326
332
|
? command.execute(executeData)
|
|
327
333
|
: command.execute(executeData))
|
|
328
334
|
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
329
|
-
.catch(async (err) => await this._haltCommand(command, { executeData: executeData, reason: CommandHaltReason.Error, error: err })
|
|
335
|
+
.catch(async (err) => !await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err })
|
|
330
336
|
? this._commandExecuteError(err, executeData)
|
|
331
337
|
: void 0);
|
|
332
338
|
return executeData;
|
|
333
339
|
}
|
|
334
340
|
catch (err) {
|
|
335
|
-
if (!await this._haltCommand(command, { executeData: executeData, reason: CommandHaltReason.Error, error: err })) {
|
|
341
|
+
if (!await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err })) {
|
|
336
342
|
this._commandExecuteError(err, executeData);
|
|
337
343
|
}
|
|
338
344
|
}
|
|
@@ -344,20 +350,21 @@ export class RecipleClient extends Client {
|
|
|
344
350
|
*/
|
|
345
351
|
async _commandExecuteError(err, command) {
|
|
346
352
|
if (this.isClientLogsEnabled()) {
|
|
347
|
-
this.logger.error(`An error occured executing ${command.builder.type == CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
|
|
353
|
+
this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
|
|
348
354
|
this.logger.error(err);
|
|
349
355
|
}
|
|
350
356
|
if (!err || !command)
|
|
351
357
|
return;
|
|
352
|
-
if (SlashCommandBuilder.isSlashCommandExecuteData(command)) {
|
|
358
|
+
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
|
|
353
359
|
if (!this.config.commands.slashCommand.replyOnError)
|
|
354
360
|
return;
|
|
355
361
|
await command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
356
362
|
}
|
|
357
|
-
else if (MessageCommandBuilder.isMessageCommandExecuteData(command)) {
|
|
363
|
+
else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
|
|
358
364
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
359
365
|
return;
|
|
360
366
|
await command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
361
367
|
}
|
|
362
368
|
}
|
|
363
369
|
}
|
|
370
|
+
exports.RecipleClient = RecipleClient;
|
|
File without changes
|
|
@@ -14,12 +14,13 @@ const yaml_1 = __importDefault(require("yaml"));
|
|
|
14
14
|
* Create/parse reciple config
|
|
15
15
|
*/
|
|
16
16
|
class RecipleConfig {
|
|
17
|
+
config = RecipleConfig.getDefaultConfig();
|
|
18
|
+
configPath = path_1.default.join(flags_1.cwd, 'reciple.yml');
|
|
19
|
+
static defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
|
|
17
20
|
/**
|
|
18
21
|
* @param configPath Path to config
|
|
19
22
|
*/
|
|
20
23
|
constructor(configPath) {
|
|
21
|
-
this.config = RecipleConfig.getDefaultConfig();
|
|
22
|
-
this.configPath = path_1.default.join(flags_1.cwd, 'reciple.yml');
|
|
23
24
|
if (!configPath)
|
|
24
25
|
throw new Error('Config path is not defined');
|
|
25
26
|
this.configPath = configPath;
|
|
@@ -28,7 +29,6 @@ class RecipleConfig {
|
|
|
28
29
|
* Parse the config file
|
|
29
30
|
*/
|
|
30
31
|
parseConfig() {
|
|
31
|
-
var _a;
|
|
32
32
|
if (!(0, fs_1.existsSync)(this.configPath)) {
|
|
33
33
|
const defaultConfigPath = RecipleConfig.defaultConfigPath;
|
|
34
34
|
if (!(0, fs_1.existsSync)(defaultConfigPath))
|
|
@@ -49,7 +49,7 @@ class RecipleConfig {
|
|
|
49
49
|
const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
|
|
50
50
|
this.config = yaml_1.default.parse(config);
|
|
51
51
|
if (!this._isSupportedConfig())
|
|
52
|
-
throw new Error('Unsupported config version. Your config version: ' + (
|
|
52
|
+
throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version_1.version);
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -66,8 +66,7 @@ class RecipleConfig {
|
|
|
66
66
|
* @param askIfNull Ask for token if the token is null/undefined
|
|
67
67
|
*/
|
|
68
68
|
parseToken(askIfNull = true) {
|
|
69
|
-
|
|
70
|
-
let token = flags_1.token || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || null;
|
|
69
|
+
let token = flags_1.token || this.config?.token || null;
|
|
71
70
|
if (!token)
|
|
72
71
|
return token || (askIfNull ? this._askToken() : null);
|
|
73
72
|
const envToken = token.toString().split(':');
|
|
@@ -80,8 +79,7 @@ class RecipleConfig {
|
|
|
80
79
|
* Check if the config version is supported
|
|
81
80
|
*/
|
|
82
81
|
_isSupportedConfig() {
|
|
83
|
-
|
|
84
|
-
return (0, version_1.isSupportedVersion)(((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || '0.0.0', version_1.version);
|
|
82
|
+
return (0, version_1.isSupportedVersion)(this.config?.version || '0.0.0', version_1.version);
|
|
85
83
|
}
|
|
86
84
|
/**
|
|
87
85
|
* Ask for a token
|
|
@@ -99,4 +97,3 @@ class RecipleConfig {
|
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
exports.RecipleConfig = RecipleConfig;
|
|
102
|
-
RecipleConfig.defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
|
|
File without changes
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
4
|
+
const builders_1 = require("../../types/builders");
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
|
|
7
|
+
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
5
8
|
/**
|
|
6
9
|
* Reciple builder for message command
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
type = CommandBuilderType.MessageCommand;
|
|
11
|
+
class MessageCommandBuilder {
|
|
12
|
+
type = builders_1.CommandBuilderType.MessageCommand;
|
|
10
13
|
name = '';
|
|
11
14
|
description = '';
|
|
12
15
|
cooldown = 0;
|
|
@@ -31,19 +34,19 @@ export class MessageCommandBuilder {
|
|
|
31
34
|
if (data?.requiredMemberPermissions !== undefined)
|
|
32
35
|
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
33
36
|
if (data?.halt !== undefined)
|
|
34
|
-
this.setHalt(
|
|
37
|
+
this.setHalt(data.halt);
|
|
35
38
|
if (data?.execute !== undefined)
|
|
36
39
|
this.setExecute(data.execute);
|
|
37
40
|
if (data?.aliases !== undefined)
|
|
38
41
|
this.addAliases(data.aliases);
|
|
39
|
-
if (data?.allowExecuteByBots)
|
|
42
|
+
if (data?.allowExecuteByBots !== undefined)
|
|
40
43
|
this.setAllowExecuteByBots(true);
|
|
41
|
-
if (data?.allowExecuteInDM)
|
|
44
|
+
if (data?.allowExecuteInDM !== undefined)
|
|
42
45
|
this.setAllowExecuteInDM(true);
|
|
43
|
-
if (data?.validateOptions)
|
|
46
|
+
if (data?.validateOptions !== undefined)
|
|
44
47
|
this.setValidateOptions(true);
|
|
45
48
|
if (data?.options !== undefined)
|
|
46
|
-
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder(o));
|
|
49
|
+
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
52
|
* Sets the command name
|
|
@@ -70,7 +73,7 @@ export class MessageCommandBuilder {
|
|
|
70
73
|
* @param aliases Command aliases
|
|
71
74
|
*/
|
|
72
75
|
addAliases(...aliases) {
|
|
73
|
-
aliases = normalizeArray(aliases);
|
|
76
|
+
aliases = (0, discord_js_1.normalizeArray)(aliases);
|
|
74
77
|
if (!aliases.length)
|
|
75
78
|
throw new TypeError('Provide atleast one alias');
|
|
76
79
|
if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
|
|
@@ -107,7 +110,7 @@ export class MessageCommandBuilder {
|
|
|
107
110
|
addOption(option) {
|
|
108
111
|
if (!option)
|
|
109
112
|
throw new TypeError('option must be a MessageOption.');
|
|
110
|
-
option = typeof option === 'function' ? option(new MessageCommandOptionBuilder()) : option;
|
|
113
|
+
option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
|
|
111
114
|
if (this.options.find(o => o.name === option.name))
|
|
112
115
|
throw new TypeError('option with name "' + option.name + '" already exists.');
|
|
113
116
|
if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
|
|
@@ -130,11 +133,11 @@ export class MessageCommandBuilder {
|
|
|
130
133
|
return this;
|
|
131
134
|
}
|
|
132
135
|
setRequiredBotPermissions(...permissions) {
|
|
133
|
-
this.requiredBotPermissions = normalizeArray(permissions);
|
|
136
|
+
this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
134
137
|
return this;
|
|
135
138
|
}
|
|
136
139
|
setRequiredMemberPermissions(...permissions) {
|
|
137
|
-
this.requiredMemberPermissions = normalizeArray(permissions);
|
|
140
|
+
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
138
141
|
return this;
|
|
139
142
|
}
|
|
140
143
|
setHalt(halt) {
|
|
@@ -183,7 +186,8 @@ export class MessageCommandBuilder {
|
|
|
183
186
|
return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
|
-
|
|
189
|
+
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
190
|
+
async function validateMessageCommandOptions(builder, options) {
|
|
187
191
|
const args = options.args || [];
|
|
188
192
|
const required = builder.options.filter(o => o.required);
|
|
189
193
|
const optional = builder.options.filter(o => !o.required);
|
|
@@ -214,5 +218,6 @@ export async function validateMessageCommandOptions(builder, options) {
|
|
|
214
218
|
result.push(value);
|
|
215
219
|
i++;
|
|
216
220
|
}
|
|
217
|
-
return new MessageCommandOptionManager(...result);
|
|
221
|
+
return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
|
|
218
222
|
}
|
|
223
|
+
exports.validateMessageCommandOptions = validateMessageCommandOptions;
|