reciple 5.4.1 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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: ' + (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || 'No version specified.') + ', Reciple version: ' + version_1.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
- var _a;
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
- var _a;
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
- this.type = builders_1.CommandBuilderType.MessageCommand;
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 ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
28
+ if (data?.description !== undefined)
37
29
  this.setDescription(data.description);
38
- if ((data === null || data === void 0 ? void 0 : data.cooldown) !== undefined)
39
- this.setCooldown(Number(data === null || data === void 0 ? void 0 : data.cooldown));
40
- if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
30
+ if (data?.cooldown !== undefined)
31
+ this.setCooldown(Number(data?.cooldown));
32
+ if (data?.requiredBotPermissions !== undefined)
41
33
  this.setRequiredBotPermissions(data.requiredBotPermissions);
42
- if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
34
+ if (data?.requiredMemberPermissions !== undefined)
43
35
  this.setRequiredMemberPermissions(data.requiredMemberPermissions);
44
- if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
45
- this.setHalt(this.halt);
46
- if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
36
+ if (data?.halt !== undefined)
37
+ this.setHalt(data.halt);
38
+ if (data?.execute !== undefined)
47
39
  this.setExecute(data.execute);
48
- if ((data === null || data === void 0 ? void 0 : data.aliases) !== undefined)
40
+ if (data?.aliases !== undefined)
49
41
  this.addAliases(data.aliases);
50
- if (data === null || data === void 0 ? void 0 : data.allowExecuteByBots)
42
+ if (data?.allowExecuteByBots !== undefined)
51
43
  this.setAllowExecuteByBots(true);
52
- if (data === null || data === void 0 ? void 0 : data.allowExecuteInDM)
44
+ if (data?.allowExecuteInDM !== undefined)
53
45
  this.setAllowExecuteInDM(true);
54
- if (data === null || data === void 0 ? void 0 : data.validateOptions)
46
+ if (data?.validateOptions !== undefined)
55
47
  this.setValidateOptions(true);
56
- if ((data === null || data === void 0 ? void 0 : data.options) !== undefined)
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 !== null && halt !== void 0 ? halt : undefined;
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
- return __awaiter(this, void 0, void 0, function* () {
200
- const args = options.args || [];
201
- const required = builder.options.filter(o => o.required);
202
- const optional = builder.options.filter(o => !o.required);
203
- const allOptions = [...required, ...optional];
204
- const result = [];
205
- let i = 0;
206
- for (const option of allOptions) {
207
- const arg = args[i];
208
- const value = {
209
- name: option.name,
210
- value: arg !== null && arg !== void 0 ? arg : undefined,
211
- required: option.required,
212
- invalid: false,
213
- missing: false
214
- };
215
- if (arg == undefined && option.required) {
216
- value.missing = true;
217
- result.push(value);
218
- continue;
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
- i++;
213
+ continue;
229
214
  }
230
- return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
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
- 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)
13
+ if (data?.name !== undefined)
14
14
  this.setName(data.name);
15
- if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
15
+ if (data?.description !== undefined)
16
16
  this.setDescription(data.description);
17
- if ((data === null || data === void 0 ? void 0 : data.required) !== undefined)
17
+ if (data?.required !== undefined)
18
18
  this.setRequired(data.required);
19
- if ((data === null || data === void 0 ? void 0 : data.validator) !== undefined)
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
- this.type = builders_1.CommandBuilderType.SlashCommand;
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 ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
21
+ if (data?.description !== undefined)
21
22
  this.setDescription(data.description);
22
- if ((data === null || data === void 0 ? void 0 : data.cooldown) !== undefined)
23
- this.setCooldown(Number(data === null || data === void 0 ? void 0 : data.cooldown));
24
- if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
23
+ if (data?.cooldown !== undefined)
24
+ this.setCooldown(Number(data?.cooldown));
25
+ if (data?.requiredBotPermissions !== undefined)
25
26
  this.setRequiredBotPermissions(data.requiredBotPermissions);
26
- if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
27
+ if (data?.requiredMemberPermissions !== undefined)
27
28
  this.setRequiredMemberPermissions(data.requiredMemberPermissions);
28
- if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
29
- this.setHalt(this.halt);
30
- if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
29
+ if (data?.halt !== undefined)
30
+ this.setHalt(data.halt);
31
+ if (data?.execute !== undefined)
31
32
  this.setExecute(data.execute);
32
- if ((data === null || data === void 0 ? void 0 : data.nameLocalizations) !== undefined)
33
+ if (data?.nameLocalizations !== undefined)
33
34
  this.setNameLocalizations(data.nameLocalizations);
34
- if ((data === null || data === void 0 ? void 0 : data.descriptionLocalizations) !== undefined)
35
+ if (data?.descriptionLocalizations !== undefined)
35
36
  this.setDescriptionLocalizations(data.descriptionLocalizations);
36
- if ((data === null || data === void 0 ? void 0 : data.defaultMemberPermissions) !== undefined)
37
+ if (data?.defaultMemberPermissions !== undefined)
37
38
  this.setDefaultMemberPermissions(data.defaultMemberPermissions);
38
- if (data === null || data === void 0 ? void 0 : data.dmPermission)
39
+ if (data?.dmPermission !== undefined)
39
40
  this.setDMPermission(true);
40
- if (data === null || data === void 0 ? void 0 : data.defaultPermission)
41
+ if (data?.defaultPermission !== undefined)
41
42
  this.setDefaultPermission(true);
42
- if (data === null || data === void 0 ? void 0 : data.options) {
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 !== null && halt !== void 0 ? halt : undefined;
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(...((_a = option.channelTypes) !== null && _a !== void 0 ? _a : []));
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(...((_b = option.choices) !== null && _b !== void 0 ? _b : []))
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(...((_c = option.choices) !== null && _c !== void 0 ? _c : []))
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(...((_d = option.choices) !== null && _d !== void 0 ? _d : []))
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((_e = option.required) !== null && _e !== void 0 ? _e : false);
184
+ builder.setRequired(option.required ?? false);
185
185
  }
186
186
  return builder
187
187
  .setName(option.name)
188
188
  .setDescription(option.description)
189
- .setNameLocalizations((_f = option.nameLocalizations) !== null && _f !== void 0 ? _f : null)
190
- .setDescriptionLocalizations((_g = option.descriptionLocalizations) !== null && _g !== void 0 ? _g : null);
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);
@@ -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: (_a = flags_1.flags.debugmode) !== null && _a !== void 0 ? _a : debugmode,
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"}]`,
@@ -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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -27,74 +18,73 @@ const path_1 = __importDefault(require("path"));
27
18
  * @param client Reciple client
28
19
  * @param folder Modules folder
29
20
  */
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
- }
21
+ async function getModules(client, folder) {
22
+ const response = { commands: [], modules: [] };
23
+ const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
24
+ if (!(0, fs_1.existsSync)(modulesDir))
25
+ (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
26
+ const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
27
+ const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
28
+ return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
29
+ });
30
+ for (const script of scripts) {
31
+ const modulePath = path_1.default.join(modulesDir, script);
32
+ const commands = [];
33
+ let module_;
34
+ try {
35
+ const reqMod = require(modulePath);
36
+ module_ = reqMod?.default !== undefined ? reqMod.default : reqMod;
37
+ if (typeof module_ !== 'object')
38
+ throw new Error(`Module ${modulePath} is not an object`);
39
+ if (!client.config.disableVersionCheck && !module_?.versions.length)
40
+ throw new Error(`${modulePath} does not have supported versions.`);
41
+ const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
42
+ if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
43
+ throw new Error(`${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ') ?? 'none');
44
+ if (!await Promise.resolve(module_.onStart(client)).catch(() => false))
45
+ throw new Error(script + ' onStart returned false or undefined.');
46
+ if (module_.commands) {
47
+ for (const command of module_.commands) {
48
+ if (command.type === builders_1.CommandBuilderType.MessageCommand) {
49
+ commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
50
+ }
51
+ else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
52
+ commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
63
53
  }
64
54
  }
65
55
  }
66
- catch (error) {
67
- if (client.isClientLogsEnabled()) {
68
- client.logger.error(`Failed to load module ${script}`);
69
- client.logger.error(error);
70
- }
71
- continue;
56
+ }
57
+ catch (error) {
58
+ if (client.isClientLogsEnabled()) {
59
+ client.logger.error(`Failed to load module ${script}`);
60
+ client.logger.error(error);
72
61
  }
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}`);
62
+ continue;
96
63
  }
97
- return response;
98
- });
64
+ response.commands.push(...commands.filter((c) => {
65
+ if (!c.name) {
66
+ if (client.isClientLogsEnabled())
67
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
68
+ return false;
69
+ }
70
+ if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
71
+ if (client.isClientLogsEnabled())
72
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
73
+ return false;
74
+ }
75
+ return true;
76
+ }));
77
+ response.modules.push({
78
+ script: module_,
79
+ info: {
80
+ filename: script,
81
+ versions: (0, discord_js_1.normalizeArray)([module_.versions]),
82
+ path: modulePath
83
+ }
84
+ });
85
+ if (client.isClientLogsEnabled())
86
+ client.logger.info(`Loaded module ${modulePath}`);
87
+ }
88
+ return response;
99
89
  }
100
90
  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 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
- 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 };
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
- * Check if the bot has the required permissions in a guild
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(guild, requiredPermissions) {
24
- if (!(requiredPermissions === null || requiredPermissions === void 0 ? void 0 : requiredPermissions.length))
22
+ function botHasExecutePermissions(guildOrChannel, requiredPermissions) {
23
+ if (!requiredPermissions?.length)
25
24
  return true;
26
- return (guild === null || guild === void 0 ? void 0 : guild.members.me) ? guild.members.me.permissions.has(requiredPermissions) : false;
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;