Files
xiao/framework/Command.js
T
2024-04-19 17:44:53 -04:00

66 lines
2.1 KiB
JavaScript

const Argument = require('./Argument');
module.exports = class Command {
constructor(client, options) {
Object.defineProperty(this, 'client', { value: client });
this.name = options.name.toLowerCase();
this.aliases = options.aliases ? options.aliases.map(alias => alias.toLowerCase()) : [];
this.groupID = options.group.toLowerCase();
this.memberName = options.memberName.toLowerCase();
this.description = options.description;
this.details = options.details || null;
this.flags = options.flags || [];
this.args = options.args ? options.args.map(arg => new Argument(client, arg)) : [];
this.patterns = options.patterns || [];
this.clientPermissions = options.clientPermissions || [];
this.userPermissions = options.userPermissions || [];
this.ownerOnly = options.ownerOnly || false;
this.nsfw = options.nsfw || false;
this.guildOnly = options.guildOnly || false;
this.game = options.game || false;
this.guarded = options.guarded || false;
this.unknown = options.unknown || false;
this.throttling = options.throttling || { usages: 2, duration: 5 };
this.credit = options.credit || [];
this.credit.push({
name: 'Dragon Fire',
url: 'https://github.com/dragonfire535',
reason: 'Code'
});
this.uses = 0;
this.lastRun = null;
this.throttles = new Map();
this._timeouts = new Map();
this._enabled = true;
}
get group() {
return this.client.registry.groups.get(this.groupID);
}
usage(noArgs = false) {
const args = noArgs ? '' : this.args
.map(arg => {
const hasDefault = arg.default !== null;
return `${hasDefault ? '[' : '<'}${arg.label || arg.key}${hasDefault ? ']' : '>'}`
}).join(' ');
return `\`${this.client.commandPrefix}${this.name} ${args}\` or \`@${this.client.user.tag} ${this.name} ${args}\``;
}
disable() {
this._enabled = false;
}
enable() {
this._enabled = true;
}
reload() {
delete require.cache[require.resolve(`../commands/${this.groupID}/${this.memberName}.js`)];
const NewCmd = require(`../commands/${this.groupID}/${this.memberName}.js`);
this.client.registry.commands.delete(this.name);
this.client.registry.registerCommand(new NewCmd(this.client));
}
};