2020-04-08 18:08:46 +02:00
|
|
|
const Component = require('./Component.js');
|
2020-07-26 22:10:55 +02:00
|
|
|
const { stripIndents } = require('common-tags');
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
class Command extends Component {
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
constructor(manager, opts = {}) {
|
2020-04-08 18:08:46 +02:00
|
|
|
if(!opts) return null;
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
super(manager, {
|
2020-04-08 18:08:46 +02:00
|
|
|
id: opts.name,
|
|
|
|
type: 'command',
|
|
|
|
disabled: opts.disabled || false,
|
|
|
|
guarded: opts.guarded || false
|
|
|
|
});
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
this.manager = manager;
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
this.name = opts.name;
|
|
|
|
this.module = opts.module;
|
|
|
|
this.aliases = opts.aliases || [];
|
|
|
|
|
2020-05-08 08:50:54 +02:00
|
|
|
this.description = `C_${opts.name.toUpperCase()}_DESCRIPTION`;
|
2020-05-07 01:26:16 +02:00
|
|
|
this.usage = opts.usage || '';
|
|
|
|
this.examples = opts.examples || [];
|
2020-07-04 12:23:10 +02:00
|
|
|
this.rawExamples = Boolean(opts.rawExamples);
|
2020-04-08 18:08:46 +02:00
|
|
|
|
2020-07-23 22:40:20 +02:00
|
|
|
this.tags = opts.tags || [];
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
this.restricted = Boolean(opts.restricted);
|
2020-05-07 01:26:16 +02:00
|
|
|
this.showUsage = Boolean(opts.showUsage);
|
2020-04-08 18:08:46 +02:00
|
|
|
this.guildOnly = Boolean(opts.guildOnly);
|
2020-05-07 01:26:16 +02:00
|
|
|
|
2020-05-25 13:13:34 +02:00
|
|
|
this.archivable = opts.archivable === undefined ? true : Boolean(opts.archivable);
|
2020-04-09 23:08:28 +02:00
|
|
|
this.arguments = opts.arguments || [];
|
2020-06-02 12:09:28 +02:00
|
|
|
this.keepQuotes = Boolean(opts.keepQuotes);
|
2020-05-17 15:07:39 +02:00
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
this.clientPermissions = opts.clientPermissions || [];
|
|
|
|
this.memberPermissions = opts.memberPermissions || [];
|
2021-05-03 16:55:46 +02:00
|
|
|
this.permissionRequired = opts.permissionRequired || opts.memberPermissions?.length > 0;
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
this.throttling = opts.throttling || {
|
|
|
|
usages: 5,
|
|
|
|
duration: 10
|
|
|
|
};
|
|
|
|
|
|
|
|
this._throttles = new Map();
|
2020-08-14 21:46:08 +02:00
|
|
|
this._invokes = {
|
|
|
|
success: 0,
|
|
|
|
fail: 0
|
|
|
|
};
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-28 22:40:15 +02:00
|
|
|
execute() {
|
|
|
|
throw new Error(`${this.resolveable} is missing an execute function.`);
|
|
|
|
}
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
get moduleResolveable() {
|
|
|
|
return `${this.module.id}:${this.id}`;
|
|
|
|
}
|
2020-04-08 16:27:34 +02:00
|
|
|
|
2020-07-26 22:10:55 +02:00
|
|
|
usageEmbed(message, verbose = false) {
|
|
|
|
|
|
|
|
const { guild } = message;
|
2021-05-03 16:55:46 +02:00
|
|
|
const type = guild._settings.permissionType;
|
2020-07-26 22:10:55 +02:00
|
|
|
const prefix = guild?.prefix || this.client.prefix;
|
|
|
|
const fields = [];
|
|
|
|
|
|
|
|
if (this.examples.length) {
|
|
|
|
fields.push({
|
2020-08-16 09:27:49 +02:00
|
|
|
name: `》 ${message.format('GENERAL_EXAMPLES')}`,
|
2020-07-26 22:10:55 +02:00
|
|
|
value: this.examples.map((e) => this.rawExamples ? `\`${prefix}${e}\`` : `\`${prefix}${this.name} ${e}\``).join('\n')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.aliases.length && verbose) {
|
|
|
|
fields.push({
|
2020-08-16 09:27:49 +02:00
|
|
|
name: `》 ${message.format('GENERAL_ALIASES')}`,
|
2020-07-26 22:10:55 +02:00
|
|
|
value: this.aliases.join(', ')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.arguments.length && verbose) {
|
|
|
|
fields.push({
|
2020-08-16 09:27:49 +02:00
|
|
|
name: `》 ${message.format('GENERAL_ARGUMENTS')}`,
|
2020-08-14 08:29:58 +02:00
|
|
|
value: this.arguments.map((a) => `\`${a.types.length === 1 && a.types.includes('FLAG') ? '--' : ''}${a.name}${a.usage ? ` ${a.usage}` : ''}\`: ${message.format(`A_${a.name.toUpperCase()}_${this.name.toUpperCase()}_DESCRIPTION`)}`).join('\n')
|
2020-07-26 22:10:55 +02:00
|
|
|
});
|
|
|
|
}
|
2021-05-03 16:55:46 +02:00
|
|
|
if (this.permissionRequired) {
|
|
|
|
let required = [];
|
|
|
|
if (type === 'discord') required = this.memberPermissions;
|
|
|
|
else if (type === 'grant') required = [this.resolveable];
|
|
|
|
else required = [this.resolveable, ...this.memberPermissions];
|
|
|
|
|
|
|
|
fields.push({
|
|
|
|
name: `》 ${message.format('GENERAL_PERMISSIONS')}`,
|
|
|
|
value: `${message.format('GENERAL_PERMISSION_TYPE', {
|
|
|
|
required: required.join('`, `')
|
|
|
|
})}`
|
|
|
|
});
|
|
|
|
}
|
2020-07-26 22:10:55 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
author: {
|
|
|
|
name: `${this.name}${this.module ? ` (${this.module.resolveable})` : ''}`
|
|
|
|
},
|
|
|
|
description: stripIndents`\`${prefix}${this.name}${this.usage ? ` ${this.usage}` : ''}\`${this.guildOnly ? ' *(guild-only)*' : ''}
|
|
|
|
${message.format(this.description)}`,
|
|
|
|
fields
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Command;
|