reciple 5.4.1 → 5.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bin.js +11 -22
- package/bin/reciple/classes/CommandCooldownManager.js +6 -7
- package/bin/reciple/classes/MessageCommandOptionManager.js +4 -5
- package/bin/reciple/classes/RecipleClient.d.ts +4 -4
- package/bin/reciple/classes/RecipleClient.js +225 -255
- package/bin/reciple/classes/RecipleConfig.js +6 -9
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +58 -68
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +8 -8
- package/bin/reciple/classes/builders/SlashCommandBuilder.js +29 -29
- package/bin/reciple/logger.js +1 -2
- package/bin/reciple/modules.js +85 -72
- package/bin/reciple/permissions.d.ts +6 -2
- package/bin/reciple/permissions.js +16 -10
- package/bin/reciple/registerApplicationCommands.js +36 -49
- package/bin/reciple/types/builders.d.ts +3 -5
- package/package.json +6 -5
|
@@ -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');
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
13
4
|
const builders_1 = require("../../types/builders");
|
|
@@ -18,42 +9,43 @@ const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
|
18
9
|
* Reciple builder for message command
|
|
19
10
|
*/
|
|
20
11
|
class MessageCommandBuilder {
|
|
12
|
+
type = builders_1.CommandBuilderType.MessageCommand;
|
|
13
|
+
name = '';
|
|
14
|
+
description = '';
|
|
15
|
+
cooldown = 0;
|
|
16
|
+
aliases = [];
|
|
17
|
+
validateOptions = false;
|
|
18
|
+
options = [];
|
|
19
|
+
requiredBotPermissions = [];
|
|
20
|
+
requiredMemberPermissions = [];
|
|
21
|
+
allowExecuteInDM = true;
|
|
22
|
+
allowExecuteByBots = false;
|
|
23
|
+
halt;
|
|
24
|
+
execute = () => { };
|
|
21
25
|
constructor(data) {
|
|
22
|
-
|
|
23
|
-
this.name = '';
|
|
24
|
-
this.description = '';
|
|
25
|
-
this.cooldown = 0;
|
|
26
|
-
this.aliases = [];
|
|
27
|
-
this.validateOptions = false;
|
|
28
|
-
this.options = [];
|
|
29
|
-
this.requiredBotPermissions = [];
|
|
30
|
-
this.requiredMemberPermissions = [];
|
|
31
|
-
this.allowExecuteInDM = true;
|
|
32
|
-
this.allowExecuteByBots = false;
|
|
33
|
-
this.execute = () => { };
|
|
34
|
-
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
26
|
+
if (data?.name !== undefined)
|
|
35
27
|
this.setName(data.name);
|
|
36
|
-
if (
|
|
28
|
+
if (data?.description !== undefined)
|
|
37
29
|
this.setDescription(data.description);
|
|
38
|
-
if (
|
|
39
|
-
this.setCooldown(Number(data
|
|
40
|
-
if (
|
|
30
|
+
if (data?.cooldown !== undefined)
|
|
31
|
+
this.setCooldown(Number(data?.cooldown));
|
|
32
|
+
if (data?.requiredBotPermissions !== undefined)
|
|
41
33
|
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
42
|
-
if (
|
|
34
|
+
if (data?.requiredMemberPermissions !== undefined)
|
|
43
35
|
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
44
|
-
if (
|
|
45
|
-
this.setHalt(
|
|
46
|
-
if (
|
|
36
|
+
if (data?.halt !== undefined)
|
|
37
|
+
this.setHalt(data.halt);
|
|
38
|
+
if (data?.execute !== undefined)
|
|
47
39
|
this.setExecute(data.execute);
|
|
48
|
-
if (
|
|
40
|
+
if (data?.aliases !== undefined)
|
|
49
41
|
this.addAliases(data.aliases);
|
|
50
|
-
if (data
|
|
42
|
+
if (data?.allowExecuteByBots !== undefined)
|
|
51
43
|
this.setAllowExecuteByBots(true);
|
|
52
|
-
if (data
|
|
44
|
+
if (data?.allowExecuteInDM !== undefined)
|
|
53
45
|
this.setAllowExecuteInDM(true);
|
|
54
|
-
if (data
|
|
46
|
+
if (data?.validateOptions !== undefined)
|
|
55
47
|
this.setValidateOptions(true);
|
|
56
|
-
if (
|
|
48
|
+
if (data?.options !== undefined)
|
|
57
49
|
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
|
|
58
50
|
}
|
|
59
51
|
/**
|
|
@@ -149,7 +141,7 @@ class MessageCommandBuilder {
|
|
|
149
141
|
return this;
|
|
150
142
|
}
|
|
151
143
|
setHalt(halt) {
|
|
152
|
-
this.halt = halt
|
|
144
|
+
this.halt = halt ?? undefined;
|
|
153
145
|
return this;
|
|
154
146
|
}
|
|
155
147
|
setExecute(execute) {
|
|
@@ -195,39 +187,37 @@ class MessageCommandBuilder {
|
|
|
195
187
|
}
|
|
196
188
|
}
|
|
197
189
|
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
198
|
-
function validateMessageCommandOptions(builder, options) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (arg == undefined && !option.required) {
|
|
221
|
-
result.push(value);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const validate = option.validator ? yield Promise.resolve(option.validator(arg)) : true;
|
|
225
|
-
if (!validate)
|
|
226
|
-
value.invalid = true;
|
|
190
|
+
async function validateMessageCommandOptions(builder, options) {
|
|
191
|
+
const args = options.args || [];
|
|
192
|
+
const required = builder.options.filter(o => o.required);
|
|
193
|
+
const optional = builder.options.filter(o => !o.required);
|
|
194
|
+
const allOptions = [...required, ...optional];
|
|
195
|
+
const result = [];
|
|
196
|
+
let i = 0;
|
|
197
|
+
for (const option of allOptions) {
|
|
198
|
+
const arg = args[i];
|
|
199
|
+
const value = {
|
|
200
|
+
name: option.name,
|
|
201
|
+
value: arg ?? undefined,
|
|
202
|
+
required: option.required,
|
|
203
|
+
invalid: false,
|
|
204
|
+
missing: false
|
|
205
|
+
};
|
|
206
|
+
if (arg == undefined && option.required) {
|
|
207
|
+
value.missing = true;
|
|
208
|
+
result.push(value);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (arg == undefined && !option.required) {
|
|
227
212
|
result.push(value);
|
|
228
|
-
|
|
213
|
+
continue;
|
|
229
214
|
}
|
|
230
|
-
|
|
231
|
-
|
|
215
|
+
const validate = option.validator ? await Promise.resolve(option.validator(arg)) : true;
|
|
216
|
+
if (!validate)
|
|
217
|
+
value.invalid = true;
|
|
218
|
+
result.push(value);
|
|
219
|
+
i++;
|
|
220
|
+
}
|
|
221
|
+
return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
|
|
232
222
|
}
|
|
233
223
|
exports.validateMessageCommandOptions = validateMessageCommandOptions;
|
|
@@ -5,18 +5,18 @@ exports.MessageCommandOptionBuilder = void 0;
|
|
|
5
5
|
* Option builder for MessageCommandBuilder
|
|
6
6
|
*/
|
|
7
7
|
class MessageCommandOptionBuilder {
|
|
8
|
+
name = '';
|
|
9
|
+
description = '';
|
|
10
|
+
required = false;
|
|
11
|
+
validator = () => true;
|
|
8
12
|
constructor(data) {
|
|
9
|
-
|
|
10
|
-
this.description = '';
|
|
11
|
-
this.required = false;
|
|
12
|
-
this.validator = () => true;
|
|
13
|
-
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
13
|
+
if (data?.name !== undefined)
|
|
14
14
|
this.setName(data.name);
|
|
15
|
-
if (
|
|
15
|
+
if (data?.description !== undefined)
|
|
16
16
|
this.setDescription(data.description);
|
|
17
|
-
if (
|
|
17
|
+
if (data?.required !== undefined)
|
|
18
18
|
this.setRequired(data.required);
|
|
19
|
-
if (
|
|
19
|
+
if (data?.validator !== undefined)
|
|
20
20
|
this.setValidator(data.validator);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -8,38 +8,39 @@ const discord_js_1 = require("discord.js");
|
|
|
8
8
|
* Reciple builder for slash command
|
|
9
9
|
*/
|
|
10
10
|
class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
11
|
+
type = builders_1.CommandBuilderType.SlashCommand;
|
|
12
|
+
cooldown = 0;
|
|
13
|
+
requiredBotPermissions = [];
|
|
14
|
+
requiredMemberPermissions = [];
|
|
15
|
+
halt;
|
|
16
|
+
execute = () => { };
|
|
11
17
|
constructor(data) {
|
|
12
18
|
super();
|
|
13
|
-
|
|
14
|
-
this.cooldown = 0;
|
|
15
|
-
this.requiredBotPermissions = [];
|
|
16
|
-
this.requiredMemberPermissions = [];
|
|
17
|
-
this.execute = () => { };
|
|
18
|
-
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
19
|
+
if (data?.name !== undefined)
|
|
19
20
|
this.setName(data.name);
|
|
20
|
-
if (
|
|
21
|
+
if (data?.description !== undefined)
|
|
21
22
|
this.setDescription(data.description);
|
|
22
|
-
if (
|
|
23
|
-
this.setCooldown(Number(data
|
|
24
|
-
if (
|
|
23
|
+
if (data?.cooldown !== undefined)
|
|
24
|
+
this.setCooldown(Number(data?.cooldown));
|
|
25
|
+
if (data?.requiredBotPermissions !== undefined)
|
|
25
26
|
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
26
|
-
if (
|
|
27
|
+
if (data?.requiredMemberPermissions !== undefined)
|
|
27
28
|
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
28
|
-
if (
|
|
29
|
-
this.setHalt(
|
|
30
|
-
if (
|
|
29
|
+
if (data?.halt !== undefined)
|
|
30
|
+
this.setHalt(data.halt);
|
|
31
|
+
if (data?.execute !== undefined)
|
|
31
32
|
this.setExecute(data.execute);
|
|
32
|
-
if (
|
|
33
|
+
if (data?.nameLocalizations !== undefined)
|
|
33
34
|
this.setNameLocalizations(data.nameLocalizations);
|
|
34
|
-
if (
|
|
35
|
+
if (data?.descriptionLocalizations !== undefined)
|
|
35
36
|
this.setDescriptionLocalizations(data.descriptionLocalizations);
|
|
36
|
-
if (
|
|
37
|
+
if (data?.defaultMemberPermissions !== undefined)
|
|
37
38
|
this.setDefaultMemberPermissions(data.defaultMemberPermissions);
|
|
38
|
-
if (data
|
|
39
|
+
if (data?.dmPermission !== undefined)
|
|
39
40
|
this.setDMPermission(true);
|
|
40
|
-
if (data
|
|
41
|
+
if (data?.defaultPermission !== undefined)
|
|
41
42
|
this.setDefaultPermission(true);
|
|
42
|
-
if (data
|
|
43
|
+
if (data?.options) {
|
|
43
44
|
for (const option of data.options) {
|
|
44
45
|
SlashCommandBuilder.addOption(this, (0, util_1.isClass)(option) ? option : SlashCommandBuilder.resolveOption(option));
|
|
45
46
|
}
|
|
@@ -58,7 +59,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
58
59
|
return this;
|
|
59
60
|
}
|
|
60
61
|
setHalt(halt) {
|
|
61
|
-
this.halt = halt
|
|
62
|
+
this.halt = halt ?? undefined;
|
|
62
63
|
return this;
|
|
63
64
|
}
|
|
64
65
|
setExecute(execute) {
|
|
@@ -112,7 +113,6 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
112
113
|
* Resolve option data
|
|
113
114
|
*/
|
|
114
115
|
static resolveOption(option) {
|
|
115
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
116
116
|
let builder;
|
|
117
117
|
switch (option.type) {
|
|
118
118
|
case discord_js_1.ApplicationCommandOptionType.Attachment:
|
|
@@ -123,11 +123,11 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
123
123
|
break;
|
|
124
124
|
case discord_js_1.ApplicationCommandOptionType.Channel:
|
|
125
125
|
builder = new discord_js_1.SlashCommandChannelOption()
|
|
126
|
-
.addChannelTypes(...(
|
|
126
|
+
.addChannelTypes(...(option.channelTypes ?? []));
|
|
127
127
|
break;
|
|
128
128
|
case discord_js_1.ApplicationCommandOptionType.Integer:
|
|
129
129
|
builder = new discord_js_1.SlashCommandIntegerOption()
|
|
130
|
-
.addChoices(...(
|
|
130
|
+
.addChoices(...(option.choices ?? []))
|
|
131
131
|
.setAutocomplete(!!option.autocomplete);
|
|
132
132
|
if (option.maxValue)
|
|
133
133
|
builder.setMaxValue(option.maxValue);
|
|
@@ -139,7 +139,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
139
139
|
break;
|
|
140
140
|
case discord_js_1.ApplicationCommandOptionType.Number:
|
|
141
141
|
builder = new discord_js_1.SlashCommandNumberOption()
|
|
142
|
-
.addChoices(...(
|
|
142
|
+
.addChoices(...(option.choices ?? []))
|
|
143
143
|
.setAutocomplete(!!option.autocomplete);
|
|
144
144
|
if (option.maxValue)
|
|
145
145
|
builder.setMaxValue(option.maxValue);
|
|
@@ -151,7 +151,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
151
151
|
break;
|
|
152
152
|
case discord_js_1.ApplicationCommandOptionType.String:
|
|
153
153
|
builder = new discord_js_1.SlashCommandStringOption()
|
|
154
|
-
.addChoices(...(
|
|
154
|
+
.addChoices(...(option.choices ?? []))
|
|
155
155
|
.setAutocomplete(!!option.autocomplete);
|
|
156
156
|
if (option.maxLength)
|
|
157
157
|
builder.setMaxLength(option.maxLength);
|
|
@@ -181,13 +181,13 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
181
181
|
if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
|
|
182
182
|
&&
|
|
183
183
|
option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
|
|
184
|
-
builder.setRequired(
|
|
184
|
+
builder.setRequired(option.required ?? false);
|
|
185
185
|
}
|
|
186
186
|
return builder
|
|
187
187
|
.setName(option.name)
|
|
188
188
|
.setDescription(option.description)
|
|
189
|
-
.setNameLocalizations(
|
|
190
|
-
.setDescriptionLocalizations(
|
|
189
|
+
.setNameLocalizations(option.nameLocalizations ?? null)
|
|
190
|
+
.setDescriptionLocalizations(option.descriptionLocalizations ?? null);
|
|
191
191
|
}
|
|
192
192
|
static resolveSlashCommand(commandData) {
|
|
193
193
|
return this.isSlashCommandBuilder(commandData) ? commandData : new SlashCommandBuilder(commandData);
|
package/bin/reciple/logger.js
CHANGED
|
@@ -14,10 +14,9 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
14
14
|
* @param colorizeMessage add logger colours to messages
|
|
15
15
|
*/
|
|
16
16
|
function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
|
|
17
|
-
var _a;
|
|
18
17
|
return new fallout_utility_1.Logger({
|
|
19
18
|
stringifyJSON: stringifyJSON,
|
|
20
|
-
enableDebugMode:
|
|
19
|
+
enableDebugMode: flags_1.flags.debugmode ?? debugmode,
|
|
21
20
|
loggerName: 'Main',
|
|
22
21
|
prefixes: {
|
|
23
22
|
[fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, { hour12: false })}][${(name ? name + "/" : '') + "INFO"}]`,
|
package/bin/reciple/modules.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
10
24
|
};
|
|
11
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -27,74 +41,73 @@ const path_1 = __importDefault(require("path"));
|
|
|
27
41
|
* @param client Reciple client
|
|
28
42
|
* @param folder Modules folder
|
|
29
43
|
*/
|
|
30
|
-
function getModules(client, folder) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
44
|
+
async function getModules(client, folder) {
|
|
45
|
+
const response = { commands: [], modules: [] };
|
|
46
|
+
const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
|
|
47
|
+
if (!(0, fs_1.existsSync)(modulesDir))
|
|
48
|
+
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
49
|
+
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
50
|
+
const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
|
|
51
|
+
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
52
|
+
});
|
|
53
|
+
for (const script of scripts) {
|
|
54
|
+
const modulePath = path_1.default.join(modulesDir, script);
|
|
55
|
+
const commands = [];
|
|
56
|
+
let module_;
|
|
57
|
+
try {
|
|
58
|
+
const reqMod = await Promise.resolve().then(() => __importStar(require(modulePath)));
|
|
59
|
+
module_ = reqMod?.default !== undefined ? reqMod.default : reqMod;
|
|
60
|
+
if (typeof module_ !== 'object')
|
|
61
|
+
throw new Error(`Module ${modulePath} is not an object`);
|
|
62
|
+
if (!client.config.disableVersionCheck && !module_?.versions.length)
|
|
63
|
+
throw new Error(`${modulePath} does not have supported versions.`);
|
|
64
|
+
const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
|
|
65
|
+
if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
66
|
+
throw new Error(`${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ') ?? 'none');
|
|
67
|
+
if (!await Promise.resolve(module_.onStart(client)).catch(() => false))
|
|
68
|
+
throw new Error(script + ' onStart returned false or undefined.');
|
|
69
|
+
if (module_.commands) {
|
|
70
|
+
for (const command of module_.commands) {
|
|
71
|
+
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
72
|
+
commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
73
|
+
}
|
|
74
|
+
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
75
|
+
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
63
76
|
}
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
continue;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (client.isClientLogsEnabled()) {
|
|
82
|
+
client.logger.error(`Failed to load module ${script}`);
|
|
83
|
+
client.logger.error(error);
|
|
72
84
|
}
|
|
73
|
-
|
|
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}`);
|
|
85
|
+
continue;
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
response.commands.push(...commands.filter((c) => {
|
|
88
|
+
if (!c.name) {
|
|
89
|
+
if (client.isClientLogsEnabled())
|
|
90
|
+
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
|
|
94
|
+
if (client.isClientLogsEnabled())
|
|
95
|
+
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}));
|
|
100
|
+
response.modules.push({
|
|
101
|
+
script: module_,
|
|
102
|
+
info: {
|
|
103
|
+
filename: script,
|
|
104
|
+
versions: (0, discord_js_1.normalizeArray)([module_.versions]),
|
|
105
|
+
path: modulePath
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (client.isClientLogsEnabled())
|
|
109
|
+
client.logger.info(`Loaded module ${modulePath}`);
|
|
110
|
+
}
|
|
111
|
+
return response;
|
|
99
112
|
}
|
|
100
113
|
exports.getModules = getModules;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserHasCommandPermissionsOptions } from './types/paramOptions';
|
|
2
|
-
import { Guild, PermissionResolvable } from 'discord.js';
|
|
2
|
+
import { Guild, GuildTextBasedChannel, PermissionResolvable } from 'discord.js';
|
|
3
3
|
/**
|
|
4
4
|
* Check if the user has permissions to execute the given command name
|
|
5
5
|
* @param options options
|
|
@@ -7,7 +7,11 @@ import { Guild, PermissionResolvable } from 'discord.js';
|
|
|
7
7
|
export declare function userHasCommandPermissions(options: UserHasCommandPermissionsOptions): boolean;
|
|
8
8
|
/**
|
|
9
9
|
* Check if the bot has the required permissions in a guild
|
|
10
|
-
* @param guild
|
|
10
|
+
* @param guild Check if the bot has the required permissions in a guild
|
|
11
11
|
* @param requiredPermissions Required guild bot permissions
|
|
12
12
|
*/
|
|
13
13
|
export declare function botHasExecutePermissions(guild?: Guild, requiredPermissions?: PermissionResolvable[]): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* @param channel Check if the bot has the required permissions in a channel
|
|
16
|
+
*/
|
|
17
|
+
export declare function botHasExecutePermissions(channel?: GuildTextBasedChannel, requiredPermissions?: PermissionResolvable[]): boolean;
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
4
5
|
/**
|
|
5
6
|
* Check if the user has permissions to execute the given command name
|
|
6
7
|
* @param options options
|
|
7
8
|
*/
|
|
8
9
|
function userHasCommandPermissions(options) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const command = (options.commandPermissions?.enabled
|
|
11
|
+
? options.commandPermissions?.commands.find(c => c.command.toLowerCase() === options.builder.name.toLowerCase())
|
|
12
|
+
: null)
|
|
13
|
+
?? { permissions: options.builder.requiredMemberPermissions };
|
|
13
14
|
if (!command.permissions.length)
|
|
14
15
|
return true;
|
|
15
16
|
return options.memberPermissions ? options.memberPermissions.has(command.permissions) : false;
|
|
16
17
|
}
|
|
17
18
|
exports.userHasCommandPermissions = userHasCommandPermissions;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param guild Guild
|
|
21
|
-
* @param requiredPermissions Required guild bot permissions
|
|
20
|
+
* @param guildOrChannel Check permission in a guild or channel
|
|
22
21
|
*/
|
|
23
|
-
function botHasExecutePermissions(
|
|
24
|
-
if (!
|
|
22
|
+
function botHasExecutePermissions(guildOrChannel, requiredPermissions) {
|
|
23
|
+
if (!requiredPermissions?.length)
|
|
25
24
|
return true;
|
|
26
|
-
|
|
25
|
+
let permissions = null;
|
|
26
|
+
if (guildOrChannel instanceof discord_js_1.Guild) {
|
|
27
|
+
permissions = guildOrChannel.members.me?.permissions ?? null;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
permissions = guildOrChannel?.permissionsFor(guildOrChannel.client.user.id) ?? null;
|
|
31
|
+
}
|
|
32
|
+
return permissions ? permissions.has(requiredPermissions) : false;
|
|
27
33
|
}
|
|
28
34
|
exports.botHasExecutePermissions = botHasExecutePermissions;
|