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
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageCommandOptionBuilder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Option builder for MessageCommandBuilder
|
|
6
|
-
*/
|
|
7
|
-
class MessageCommandOptionBuilder {
|
|
8
|
-
constructor(data) {
|
|
9
|
-
this.name = '';
|
|
10
|
-
this.description = '';
|
|
11
|
-
this.required = false;
|
|
12
|
-
this.validator = () => true;
|
|
13
|
-
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
14
|
-
this.setName(data.name);
|
|
15
|
-
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
16
|
-
this.setDescription(data.description);
|
|
17
|
-
if ((data === null || data === void 0 ? void 0 : data.required) !== undefined)
|
|
18
|
-
this.setRequired(data.required);
|
|
19
|
-
if ((data === null || data === void 0 ? void 0 : data.validator) !== undefined)
|
|
20
|
-
this.setValidator(data.validator);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Set command option name
|
|
24
|
-
* @param name Option name
|
|
25
|
-
*/
|
|
26
|
-
setName(name) {
|
|
27
|
-
if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
28
|
-
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/.');
|
|
29
|
-
this.name = name;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Set command option description
|
|
34
|
-
* @param description Option description
|
|
35
|
-
*/
|
|
36
|
-
setDescription(description) {
|
|
37
|
-
if (!description || typeof description !== 'string')
|
|
38
|
-
throw new TypeError('description must be a string.');
|
|
39
|
-
this.description = description;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Set if this option is required
|
|
44
|
-
* @param required `true` if this option is required
|
|
45
|
-
*/
|
|
46
|
-
setRequired(required) {
|
|
47
|
-
if (typeof required !== 'boolean')
|
|
48
|
-
throw new TypeError('required must be a boolean.');
|
|
49
|
-
this.required = required;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Set your custom function to validate given value for this option
|
|
54
|
-
* @param validator Custom function to validate value given for this option
|
|
55
|
-
*/
|
|
56
|
-
setValidator(validator) {
|
|
57
|
-
if (!validator || typeof validator !== 'function')
|
|
58
|
-
throw new TypeError('validator must be a function.');
|
|
59
|
-
this.validator = validator;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
toJSON() {
|
|
63
|
-
return {
|
|
64
|
-
name: this.name,
|
|
65
|
-
description: this.description,
|
|
66
|
-
required: this.required,
|
|
67
|
-
validator: this.validator,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getModules = void 0;
|
|
16
|
-
const builders_1 = require("./types/builders");
|
|
17
|
-
const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
|
|
18
|
-
const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
|
|
19
|
-
const discord_js_1 = require("discord.js");
|
|
20
|
-
const version_1 = require("./version");
|
|
21
|
-
const fs_1 = require("fs");
|
|
22
|
-
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
23
|
-
const flags_1 = require("./flags");
|
|
24
|
-
const path_1 = __importDefault(require("path"));
|
|
25
|
-
/**
|
|
26
|
-
* Load modules from folder
|
|
27
|
-
* @param client Reciple client
|
|
28
|
-
* @param folder Modules folder
|
|
29
|
-
*/
|
|
30
|
-
function getModules(client, folder) {
|
|
31
|
-
var _a;
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const response = { commands: [], modules: [] };
|
|
34
|
-
const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
|
|
35
|
-
if (!(0, fs_1.existsSync)(modulesDir))
|
|
36
|
-
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
37
|
-
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
38
|
-
const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
|
|
39
|
-
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
40
|
-
});
|
|
41
|
-
for (const script of scripts) {
|
|
42
|
-
const modulePath = path_1.default.join(modulesDir, script);
|
|
43
|
-
const commands = [];
|
|
44
|
-
let module_;
|
|
45
|
-
try {
|
|
46
|
-
const reqMod = require(modulePath);
|
|
47
|
-
module_ = (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) !== undefined ? reqMod.default : reqMod;
|
|
48
|
-
if (!(module_ === null || module_ === void 0 ? void 0 : module_.versions.length))
|
|
49
|
-
throw new Error(`${modulePath} does not have supported versions.`);
|
|
50
|
-
const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
|
|
51
|
-
if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
52
|
-
throw new Error((_a = `${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ')) !== null && _a !== void 0 ? _a : 'none');
|
|
53
|
-
if (!(yield Promise.resolve(module_.onStart(client)).catch(() => null)))
|
|
54
|
-
throw new Error(script + ' onStart returned false or undefined.');
|
|
55
|
-
if (module_.commands) {
|
|
56
|
-
for (const command of module_.commands) {
|
|
57
|
-
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
58
|
-
commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
59
|
-
}
|
|
60
|
-
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
61
|
-
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
if (client.isClientLogsEnabled()) {
|
|
68
|
-
client.logger.error(`Failed to load module ${script}`);
|
|
69
|
-
client.logger.error(error);
|
|
70
|
-
}
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
response.commands.push(...commands.filter((c) => {
|
|
74
|
-
if (!c.name) {
|
|
75
|
-
if (client.isClientLogsEnabled())
|
|
76
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
|
|
80
|
-
if (client.isClientLogsEnabled())
|
|
81
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
}));
|
|
86
|
-
response.modules.push({
|
|
87
|
-
script: module_,
|
|
88
|
-
info: {
|
|
89
|
-
filename: script,
|
|
90
|
-
versions: (0, discord_js_1.normalizeArray)([module_.versions]),
|
|
91
|
-
path: modulePath
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
if (client.isClientLogsEnabled())
|
|
95
|
-
client.logger.info(`Loaded module ${modulePath}`);
|
|
96
|
-
}
|
|
97
|
-
return response;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
exports.getModules = getModules;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Check if the user has permissions to execute the given command name
|
|
6
|
-
* @param options options
|
|
7
|
-
*/
|
|
8
|
-
function userHasCommandPermissions(options) {
|
|
9
|
-
var _a, _b, _c;
|
|
10
|
-
const command = (_c = (((_a = options.commandPermissions) === null || _a === void 0 ? void 0 : _a.enabled)
|
|
11
|
-
? (_b = options.commandPermissions) === null || _b === void 0 ? void 0 : _b.commands.find(c => c.command.toLowerCase() === options.builder.name.toLowerCase())
|
|
12
|
-
: null)) !== null && _c !== void 0 ? _c : { permissions: options.builder.requiredMemberPermissions };
|
|
13
|
-
if (!command.permissions.length)
|
|
14
|
-
return true;
|
|
15
|
-
return options.memberPermissions ? options.memberPermissions.has(command.permissions) : false;
|
|
16
|
-
}
|
|
17
|
-
exports.userHasCommandPermissions = userHasCommandPermissions;
|
|
18
|
-
/**
|
|
19
|
-
* Check if the bot has the required permissions in a guild
|
|
20
|
-
* @param guild Guild
|
|
21
|
-
* @param requiredPermissions Required guild bot permissions
|
|
22
|
-
*/
|
|
23
|
-
function botHasExecutePermissions(guild, requiredPermissions) {
|
|
24
|
-
if (!(requiredPermissions === null || requiredPermissions === void 0 ? void 0 : requiredPermissions.length))
|
|
25
|
-
return true;
|
|
26
|
-
return (guild === null || guild === void 0 ? void 0 : guild.members.me) ? guild.members.me.permissions.has(requiredPermissions) : false;
|
|
27
|
-
}
|
|
28
|
-
exports.botHasExecutePermissions = botHasExecutePermissions;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.registerApplicationCommands = void 0;
|
|
13
|
-
const discord_js_1 = require("discord.js");
|
|
14
|
-
const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
|
|
15
|
-
/**
|
|
16
|
-
* Register application commands
|
|
17
|
-
* @param options Register application commands options
|
|
18
|
-
*/
|
|
19
|
-
function registerApplicationCommands(options) {
|
|
20
|
-
var _a, _b, _c, _d;
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const client = options.client;
|
|
23
|
-
const guilds = (0, discord_js_1.normalizeArray)(options.guilds);
|
|
24
|
-
const commands = (_b = Object.values((_a = options.commands) !== null && _a !== void 0 ? _a : client.commands.slashCommands).map(cmd => {
|
|
25
|
-
var _a;
|
|
26
|
-
if (typeof (cmd === null || cmd === void 0 ? void 0 : cmd.toJSON) == 'undefined')
|
|
27
|
-
return cmd;
|
|
28
|
-
cmd = cmd;
|
|
29
|
-
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && client.config.commands.slashCommand.setRequiredPermissions) {
|
|
30
|
-
const permissions = client.config.commands.slashCommand.permissions.enabled
|
|
31
|
-
? (_a = client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _a === void 0 ? void 0 : _a.permissions
|
|
32
|
-
: undefined;
|
|
33
|
-
if (permissions) {
|
|
34
|
-
cmd.setRequiredMemberPermissions(...permissions);
|
|
35
|
-
if (client.isClientLogsEnabled())
|
|
36
|
-
client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
37
|
-
}
|
|
38
|
-
client.commands.slashCommands[cmd.name] = cmd;
|
|
39
|
-
}
|
|
40
|
-
return cmd.toJSON();
|
|
41
|
-
})) !== null && _b !== void 0 ? _b : [];
|
|
42
|
-
if (!client.isReady())
|
|
43
|
-
throw new Error('Client is not ready');
|
|
44
|
-
if (!guilds || !(guilds === null || guilds === void 0 ? void 0 : guilds.length)) {
|
|
45
|
-
(_c = client.application) === null || _c === void 0 ? void 0 : _c.commands.set(commands).then(() => {
|
|
46
|
-
if (client.isClientLogsEnabled())
|
|
47
|
-
client.logger.warn('No guilds were specified for application commands. Registered application commands globally.');
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
if (client.isClientLogsEnabled())
|
|
52
|
-
client.logger.warn(`Registering ${commands.length} application commands to ${guilds.length} guild(s).`);
|
|
53
|
-
for (const guild of guilds) {
|
|
54
|
-
if (!guild)
|
|
55
|
-
continue;
|
|
56
|
-
(_d = client.application) === null || _d === void 0 ? void 0 : _d.commands.set(commands, guild).then(() => {
|
|
57
|
-
if (client.isClientLogsEnabled())
|
|
58
|
-
client.logger.warn(`Registered ${commands.length} application command(s) for ${guild}.`);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
exports.registerApplicationCommands = registerApplicationCommands;
|
package/bin/mjs/bin.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { RecipleClient } from './reciple/classes/RecipleClient.js';
|
|
3
|
-
import { RecipleConfig } from './reciple/classes/RecipleConfig.js';
|
|
4
|
-
import { rawVersion } from './reciple/version.js';
|
|
5
|
-
import { existsSync, readdirSync } from 'fs';
|
|
6
|
-
import { cwd, flags } from './reciple/flags.js';
|
|
7
|
-
import { input } from 'fallout-utility';
|
|
8
|
-
import chalk from 'chalk';
|
|
9
|
-
import 'dotenv/config';
|
|
10
|
-
import { normalizeArray } from 'discord.js';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
13
|
-
const configPath = path.join(cwd, './reciple.yml');
|
|
14
|
-
if (readdirSync(cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !existsSync(flags.config ?? configPath)) {
|
|
15
|
-
const ask = (flags.yes ? 'y' : null) ?? input('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
|
|
16
|
-
if (ask.toString().toLowerCase() !== 'y')
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
let configParser;
|
|
20
|
-
try {
|
|
21
|
-
configParser = new RecipleConfig(flags.config ?? configPath).parseConfig();
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
console.error(`${chalk.bold.red('Config Error')}: ${chalk.white(err.message)}`);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
const config = configParser.getConfig();
|
|
28
|
-
const client = new RecipleClient({ config: config, ...config.client });
|
|
29
|
-
if (config.fileLogging.clientLogs)
|
|
30
|
-
client.logger.info('Starting Reciple client v' + rawVersion);
|
|
31
|
-
(async () => {
|
|
32
|
-
await client.startModules(normalizeArray(config.modulesFolder));
|
|
33
|
-
client.on('ready', async () => {
|
|
34
|
-
if (client.isClientLogsEnabled())
|
|
35
|
-
client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
|
|
36
|
-
client.on('cacheSweep', () => {
|
|
37
|
-
client.cooldowns.clean();
|
|
38
|
-
});
|
|
39
|
-
await client.loadModules();
|
|
40
|
-
client.addCommandListeners();
|
|
41
|
-
});
|
|
42
|
-
client.login(config.token).catch(err => {
|
|
43
|
-
if (client.isClientLogsEnabled())
|
|
44
|
-
client.logger.error(err);
|
|
45
|
-
});
|
|
46
|
-
})();
|
package/bin/mjs/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './reciple/classes/CommandCooldownManager.js';
|
|
2
|
-
export * from './reciple/classes/MessageCommandOptionManager.js';
|
|
3
|
-
export * from './reciple/classes/RecipleClient.js';
|
|
4
|
-
export * from './reciple/classes/RecipleConfig.js';
|
|
5
|
-
export * from './reciple/classes/builders/MessageCommandBuilder.js';
|
|
6
|
-
export * from './reciple/classes/builders/MessageCommandOptionBuilder.js';
|
|
7
|
-
export * from './reciple/classes/builders/SlashCommandBuilder.js';
|
|
8
|
-
export * from './reciple/types/builders.js';
|
|
9
|
-
export * from './reciple/types/commands.js';
|
|
10
|
-
export * from './reciple/types/paramOptions.js';
|
|
11
|
-
export * from './reciple/flags.js';
|
|
12
|
-
export * from './reciple/logger.js';
|
|
13
|
-
export * from './reciple/modules.js';
|
|
14
|
-
export * from './reciple/permissions.js';
|
|
15
|
-
export * from './reciple/registerApplicationCommands.js';
|
|
16
|
-
export * from './reciple/util.js';
|
|
17
|
-
export * from './reciple/version.js';
|
package/bin/mjs/package.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { normalizeArray } from 'discord.js';
|
|
2
|
-
/**
|
|
3
|
-
* Validated message options manager
|
|
4
|
-
*/
|
|
5
|
-
export class MessageCommandOptionManager extends Array {
|
|
6
|
-
constructor(...data) {
|
|
7
|
-
super(...normalizeArray(data));
|
|
8
|
-
}
|
|
9
|
-
get(name, required) {
|
|
10
|
-
const option = this.find(o => o.name == name);
|
|
11
|
-
if (!option?.value == undefined && required)
|
|
12
|
-
throw new TypeError(`Can't find option named ${name}`);
|
|
13
|
-
return option ?? null;
|
|
14
|
-
}
|
|
15
|
-
getValue(name, requied) {
|
|
16
|
-
const option = this.get(name, requied);
|
|
17
|
-
if (!option?.value && requied)
|
|
18
|
-
throw new TypeError(`Value of option named ${name} is undefined`);
|
|
19
|
-
return option?.value ?? null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { isSupportedVersion, version } from '../version.js';
|
|
3
|
-
import { input, replaceAll } from 'fallout-utility';
|
|
4
|
-
import { cwd, token as __token } from '../flags.js';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import yaml from 'yaml';
|
|
7
|
-
/**
|
|
8
|
-
* Create/parse reciple config
|
|
9
|
-
*/
|
|
10
|
-
export class RecipleConfig {
|
|
11
|
-
config = RecipleConfig.getDefaultConfig();
|
|
12
|
-
configPath = path.join(cwd, 'reciple.yml');
|
|
13
|
-
static defaultConfigPath = path.join(__dirname, '../../../resource/reciple.yml');
|
|
14
|
-
/**
|
|
15
|
-
* @param configPath Path to config
|
|
16
|
-
*/
|
|
17
|
-
constructor(configPath) {
|
|
18
|
-
if (!configPath)
|
|
19
|
-
throw new Error('Config path is not defined');
|
|
20
|
-
this.configPath = configPath;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parse the config file
|
|
24
|
-
*/
|
|
25
|
-
parseConfig() {
|
|
26
|
-
if (!existsSync(this.configPath)) {
|
|
27
|
-
const defaultConfigPath = RecipleConfig.defaultConfigPath;
|
|
28
|
-
if (!existsSync(defaultConfigPath))
|
|
29
|
-
throw new Error('Default Config file not found. Please reinstall Reciple.');
|
|
30
|
-
const defaultConfig = replaceAll(readFileSync(defaultConfigPath, 'utf-8'), 'VERSION', version);
|
|
31
|
-
writeFileSync(this.configPath, defaultConfig, 'utf-8');
|
|
32
|
-
if (!existsSync(this.configPath))
|
|
33
|
-
throw new Error('Failed to create config file.');
|
|
34
|
-
this.config = yaml.parse(defaultConfig);
|
|
35
|
-
if (this.config && this.config.token === 'TOKEN') {
|
|
36
|
-
this.config.token = this._askToken() || this.config.token;
|
|
37
|
-
writeFileSync(this.configPath, replaceAll(defaultConfig, ' TOKEN', ` ${this.config.token}`), 'utf-8');
|
|
38
|
-
}
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
if (!existsSync(this.configPath))
|
|
42
|
-
throw new Error('Failed to read config file.');
|
|
43
|
-
const config = readFileSync(this.configPath, 'utf-8');
|
|
44
|
-
this.config = yaml.parse(config);
|
|
45
|
-
if (!this._isSupportedConfig())
|
|
46
|
-
throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version);
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns the parsed config file
|
|
51
|
-
*/
|
|
52
|
-
getConfig() {
|
|
53
|
-
if (!this.config)
|
|
54
|
-
throw new Error('Config is not parsed.');
|
|
55
|
-
this.config.token = this.parseToken() || 'TOKEN';
|
|
56
|
-
return this.config;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Parse token from config
|
|
60
|
-
* @param askIfNull Ask for token if the token is null/undefined
|
|
61
|
-
*/
|
|
62
|
-
parseToken(askIfNull = true) {
|
|
63
|
-
let token = __token || this.config?.token || null;
|
|
64
|
-
if (!token)
|
|
65
|
-
return token || (askIfNull ? this._askToken() : null);
|
|
66
|
-
const envToken = token.toString().split(':');
|
|
67
|
-
if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
|
|
68
|
-
token = process.env[envToken[1]] || null;
|
|
69
|
-
}
|
|
70
|
-
return token || (askIfNull ? this._askToken() : null);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if the config version is supported
|
|
74
|
-
*/
|
|
75
|
-
_isSupportedConfig() {
|
|
76
|
-
return isSupportedVersion(this.config?.version || '0.0.0', version);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Ask for a token
|
|
80
|
-
*/
|
|
81
|
-
_askToken() {
|
|
82
|
-
return __token || input({ text: 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, sigint: true }) || null;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Get default config
|
|
86
|
-
*/
|
|
87
|
-
static getDefaultConfig() {
|
|
88
|
-
if (!existsSync(this.defaultConfigPath))
|
|
89
|
-
throw new Error("Default config file does not exists.");
|
|
90
|
-
return yaml.parse(readFileSync(this.defaultConfigPath, 'utf-8'));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { CommandBuilderType } from '../../types/builders.js';
|
|
2
|
-
import { isClass } from '../../util.js';
|
|
3
|
-
import { normalizeArray, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandBooleanOption, SlashCommandUserOption, SlashCommandChannelOption, SlashCommandRoleOption, SlashCommandAttachmentOption, SlashCommandMentionableOption, SlashCommandStringOption, SlashCommandIntegerOption, SlashCommandNumberOption, ApplicationCommandOptionType } from 'discord.js';
|
|
4
|
-
/**
|
|
5
|
-
* Reciple builder for slash command
|
|
6
|
-
*/
|
|
7
|
-
export class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
8
|
-
type = CommandBuilderType.SlashCommand;
|
|
9
|
-
cooldown = 0;
|
|
10
|
-
requiredBotPermissions = [];
|
|
11
|
-
requiredMemberPermissions = [];
|
|
12
|
-
halt;
|
|
13
|
-
execute = () => { };
|
|
14
|
-
constructor(data) {
|
|
15
|
-
super();
|
|
16
|
-
if (data?.name !== undefined)
|
|
17
|
-
this.setName(data.name);
|
|
18
|
-
if (data?.description !== undefined)
|
|
19
|
-
this.setDescription(data.description);
|
|
20
|
-
if (data?.cooldown !== undefined)
|
|
21
|
-
this.setCooldown(Number(data?.cooldown));
|
|
22
|
-
if (data?.requiredBotPermissions !== undefined)
|
|
23
|
-
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
24
|
-
if (data?.requiredMemberPermissions !== undefined)
|
|
25
|
-
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
26
|
-
if (data?.halt !== undefined)
|
|
27
|
-
this.setHalt(this.halt);
|
|
28
|
-
if (data?.execute !== undefined)
|
|
29
|
-
this.setExecute(data.execute);
|
|
30
|
-
if (data?.nameLocalizations !== undefined)
|
|
31
|
-
this.setNameLocalizations(data.nameLocalizations);
|
|
32
|
-
if (data?.descriptionLocalizations !== undefined)
|
|
33
|
-
this.setDescriptionLocalizations(data.descriptionLocalizations);
|
|
34
|
-
if (data?.defaultMemberPermissions !== undefined)
|
|
35
|
-
this.setDefaultMemberPermissions(data.defaultMemberPermissions);
|
|
36
|
-
if (data?.dmPermission)
|
|
37
|
-
this.setDMPermission(true);
|
|
38
|
-
if (data?.defaultPermission)
|
|
39
|
-
this.setDefaultPermission(true);
|
|
40
|
-
if (data?.options) {
|
|
41
|
-
for (const option of data.options) {
|
|
42
|
-
SlashCommandBuilder.addOption(this, isClass(option) ? option : SlashCommandBuilder.resolveOption(option));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
setCooldown(cooldown) {
|
|
47
|
-
this.cooldown = cooldown;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
setRequiredBotPermissions(...permissions) {
|
|
51
|
-
this.requiredBotPermissions = normalizeArray(permissions);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
setRequiredMemberPermissions(...permissions) {
|
|
55
|
-
this.requiredMemberPermissions = normalizeArray(permissions);
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
setHalt(halt) {
|
|
59
|
-
this.halt = halt ?? undefined;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
setExecute(execute) {
|
|
63
|
-
if (!execute || typeof execute !== 'function')
|
|
64
|
-
throw new Error('execute must be a function.');
|
|
65
|
-
this.execute = execute;
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Add option builder to command builder
|
|
70
|
-
*/
|
|
71
|
-
static addOption(builder, option) {
|
|
72
|
-
if (option instanceof SlashCommandAttachmentOption) {
|
|
73
|
-
builder.addAttachmentOption(option);
|
|
74
|
-
}
|
|
75
|
-
else if (option instanceof SlashCommandBooleanOption) {
|
|
76
|
-
builder.addBooleanOption(option);
|
|
77
|
-
}
|
|
78
|
-
else if (option instanceof SlashCommandChannelOption) {
|
|
79
|
-
builder.addChannelOption(option);
|
|
80
|
-
}
|
|
81
|
-
else if (option instanceof SlashCommandIntegerOption) {
|
|
82
|
-
builder.addIntegerOption(option);
|
|
83
|
-
}
|
|
84
|
-
else if (option instanceof SlashCommandMentionableOption) {
|
|
85
|
-
builder.addMentionableOption(option);
|
|
86
|
-
}
|
|
87
|
-
else if (option instanceof SlashCommandNumberOption) {
|
|
88
|
-
builder.addNumberOption(option);
|
|
89
|
-
}
|
|
90
|
-
else if (option instanceof SlashCommandRoleOption) {
|
|
91
|
-
builder.addRoleOption(option);
|
|
92
|
-
}
|
|
93
|
-
else if (option instanceof SlashCommandStringOption) {
|
|
94
|
-
builder.addStringOption(option);
|
|
95
|
-
}
|
|
96
|
-
else if (option instanceof SlashCommandUserOption) {
|
|
97
|
-
builder.addUserOption(option);
|
|
98
|
-
}
|
|
99
|
-
else if (builder instanceof SlashCommandBuilder) {
|
|
100
|
-
if (option instanceof SlashCommandSubcommandBuilder) {
|
|
101
|
-
builder.addSubcommand(option);
|
|
102
|
-
}
|
|
103
|
-
else if (option instanceof SlashCommandSubcommandGroupBuilder) {
|
|
104
|
-
builder.addSubcommandGroup(option);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return builder;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Resolve option data
|
|
111
|
-
*/
|
|
112
|
-
static resolveOption(option) {
|
|
113
|
-
let builder;
|
|
114
|
-
switch (option.type) {
|
|
115
|
-
case ApplicationCommandOptionType.Attachment:
|
|
116
|
-
builder = new SlashCommandAttachmentOption();
|
|
117
|
-
break;
|
|
118
|
-
case ApplicationCommandOptionType.Boolean:
|
|
119
|
-
builder = new SlashCommandBooleanOption();
|
|
120
|
-
break;
|
|
121
|
-
case ApplicationCommandOptionType.Channel:
|
|
122
|
-
builder = new SlashCommandChannelOption()
|
|
123
|
-
.addChannelTypes(...(option.channelTypes ?? []));
|
|
124
|
-
break;
|
|
125
|
-
case ApplicationCommandOptionType.Integer:
|
|
126
|
-
builder = new SlashCommandIntegerOption()
|
|
127
|
-
.addChoices(...(option.choices ?? []))
|
|
128
|
-
.setAutocomplete(!!option.autocomplete);
|
|
129
|
-
if (option.maxValue)
|
|
130
|
-
builder.setMaxValue(option.maxValue);
|
|
131
|
-
if (option.minValue)
|
|
132
|
-
builder.setMinValue(option.minValue);
|
|
133
|
-
break;
|
|
134
|
-
case ApplicationCommandOptionType.Mentionable:
|
|
135
|
-
builder = new SlashCommandMentionableOption();
|
|
136
|
-
break;
|
|
137
|
-
case ApplicationCommandOptionType.Number:
|
|
138
|
-
builder = new SlashCommandNumberOption()
|
|
139
|
-
.addChoices(...(option.choices ?? []))
|
|
140
|
-
.setAutocomplete(!!option.autocomplete);
|
|
141
|
-
if (option.maxValue)
|
|
142
|
-
builder.setMaxValue(option.maxValue);
|
|
143
|
-
if (option.minValue)
|
|
144
|
-
builder.setMinValue(option.minValue);
|
|
145
|
-
break;
|
|
146
|
-
case ApplicationCommandOptionType.Role:
|
|
147
|
-
builder = new SlashCommandRoleOption();
|
|
148
|
-
break;
|
|
149
|
-
case ApplicationCommandOptionType.String:
|
|
150
|
-
builder = new SlashCommandStringOption()
|
|
151
|
-
.addChoices(...(option.choices ?? []))
|
|
152
|
-
.setAutocomplete(!!option.autocomplete);
|
|
153
|
-
if (option.maxLength)
|
|
154
|
-
builder.setMaxLength(option.maxLength);
|
|
155
|
-
if (option.minLength)
|
|
156
|
-
builder.setMinLength(option.minLength);
|
|
157
|
-
break;
|
|
158
|
-
case ApplicationCommandOptionType.User:
|
|
159
|
-
builder = new SlashCommandUserOption();
|
|
160
|
-
break;
|
|
161
|
-
case ApplicationCommandOptionType.Subcommand:
|
|
162
|
-
builder = new SlashCommandSubcommandBuilder();
|
|
163
|
-
for (const optionData of option.options) {
|
|
164
|
-
this.addOption(builder, this.resolveOption(optionData));
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
case ApplicationCommandOptionType.SubcommandGroup:
|
|
168
|
-
builder = new SlashCommandSubcommandGroupBuilder();
|
|
169
|
-
for (const subCommandData of option.options) {
|
|
170
|
-
builder.addSubcommand(subCommandData instanceof SlashCommandSubcommandBuilder
|
|
171
|
-
? subCommandData
|
|
172
|
-
: this.resolveOption(subCommandData));
|
|
173
|
-
}
|
|
174
|
-
break;
|
|
175
|
-
default:
|
|
176
|
-
throw new TypeError("Unknown option data");
|
|
177
|
-
}
|
|
178
|
-
if (!(builder instanceof SlashCommandSubcommandBuilder) && !(builder instanceof SlashCommandSubcommandGroupBuilder)
|
|
179
|
-
&&
|
|
180
|
-
option.type !== ApplicationCommandOptionType.Subcommand && option.type !== ApplicationCommandOptionType.SubcommandGroup) {
|
|
181
|
-
builder.setRequired(option.required ?? false);
|
|
182
|
-
}
|
|
183
|
-
return builder
|
|
184
|
-
.setName(option.name)
|
|
185
|
-
.setDescription(option.description)
|
|
186
|
-
.setNameLocalizations(option.nameLocalizations ?? null)
|
|
187
|
-
.setDescriptionLocalizations(option.descriptionLocalizations ?? null);
|
|
188
|
-
}
|
|
189
|
-
static resolveSlashCommand(commandData) {
|
|
190
|
-
return this.isSlashCommandBuilder(commandData) ? commandData : new SlashCommandBuilder(commandData);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Is a slash command builder
|
|
194
|
-
*/
|
|
195
|
-
static isSlashCommandBuilder(builder) {
|
|
196
|
-
return builder instanceof SlashCommandBuilder;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Is a slash command execute data
|
|
200
|
-
*/
|
|
201
|
-
static isSlashCommandExecuteData(executeData) {
|
|
202
|
-
return executeData.builder !== undefined && this.isSlashCommandBuilder(executeData.builder);
|
|
203
|
-
}
|
|
204
|
-
}
|