embedUsage

This commit is contained in:
Erik 2020-07-26 23:10:55 +03:00
parent 9229eedd29
commit bbd8a390c4
2 changed files with 74 additions and 0 deletions

View File

@ -1,4 +1,5 @@
const Component = require('./Component.js');
const { stripIndents } = require('common-tags');
class Command extends Component {
@ -54,6 +55,42 @@ class Command extends Component {
return `${this.module.id}:${this.id}`;
}
usageEmbed(message, verbose = false) {
const { guild } = message;
const prefix = guild?.prefix || this.client.prefix;
const fields = [];
if (this.examples.length) {
fields.push({
name: `${message.format('GENERAL_EXAMPLES')}`,
value: this.examples.map((e) => this.rawExamples ? `\`${prefix}${e}\`` : `\`${prefix}${this.name} ${e}\``).join('\n')
});
}
if (this.aliases.length && verbose) {
fields.push({
name: `${message.format('GENERAL_ALIASES')}`,
value: this.aliases.join(', ')
});
}
if (this.arguments.length && verbose) {
fields.push({
name: `${message.format('GENERAL_ARGUMENTS')}`,
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`)}`)
});
}
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
};
}
}
module.exports = Command;

View File

@ -20,6 +20,7 @@ class Setting extends Component {
this.description = opts.description || `S_${opts.name.toUpperCase()}_DESCRIPTION`;
this.examples = opts.examples || [];
this.rawExamples = Boolean(opts.rawExamples);
this.usage = opts.usage || '';
this.archivable = opts.archivable === undefined ? true : Boolean(opts.archivable);
@ -93,6 +94,42 @@ class Setting extends Component {
return this.name.toLowerCase();
}
usageEmbed(message, verbose = false) {
const { guild } = message;
const prefix = guild?.prefix || this.client.prefix;
const fields = [];
if (this.examples.length) {
fields.push({
name: `${message.format('GENERAL_EXAMPLES')}`,
value: this.examples.map((e) => this.rawExamples ? `\`${prefix}${e}\`` : `\`${prefix}${this.name} ${e}\``).join('\n')
});
}
if (this.aliases.length && verbose) {
fields.push({
name: `${message.format('GENERAL_ALIASES')}`,
value: this.aliases.join(', ')
});
}
if (this.arguments.length && verbose) {
fields.push({
name: `${message.format('GENERAL_ARGUMENTS')}`,
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`)}`)
});
}
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
};
}
}
module.exports = Setting;