From bbd8a390c4b7a747d0734d1aab661f91a07cf7f9 Mon Sep 17 00:00:00 2001 From: Navy Date: Sun, 26 Jul 2020 23:10:55 +0300 Subject: [PATCH] embedUsage --- structure/interfaces/Command.js | 37 +++++++++++++++++++++++++++++++++ structure/interfaces/Setting.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/structure/interfaces/Command.js b/structure/interfaces/Command.js index 95c877c..4e4b9ce 100644 --- a/structure/interfaces/Command.js +++ b/structure/interfaces/Command.js @@ -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; \ No newline at end of file diff --git a/structure/interfaces/Setting.js b/structure/interfaces/Setting.js index 3e6bffa..166c8a0 100644 --- a/structure/interfaces/Setting.js +++ b/structure/interfaces/Setting.js @@ -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); @@ -92,6 +93,42 @@ class Setting extends Component { get display() { 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 + }; + + } }