From 5470a511240bc3ee4577ab4be165a656a03669a8 Mon Sep 17 00:00:00 2001 From: Zack Campbell Date: Thu, 30 Mar 2017 12:21:24 -0500 Subject: [PATCH] Update Command#_respond -> respond, simplify Command doc blocks --- src/lib/command/Command.ts | 71 ++++++------------- src/lib/command/base/Eval.ts | 10 +-- src/lib/command/base/Reload.ts | 4 +- src/lib/command/base/SetPrefix.ts | 8 +-- src/lib/command/base/Version.ts | 2 +- .../command/base/groupcontrol/ClearLimit.ts | 4 +- .../command/base/groupcontrol/DisableGroup.ts | 6 +- .../command/base/groupcontrol/EnableGroup.ts | 6 +- src/lib/command/base/groupcontrol/Limit.ts | 8 +-- .../command/base/groupcontrol/ListGroups.ts | 2 +- 10 files changed, 45 insertions(+), 76 deletions(-) diff --git a/src/lib/command/Command.ts b/src/lib/command/Command.ts index 5c89d532..0cc83fb0 100644 --- a/src/lib/command/Command.ts +++ b/src/lib/command/Command.ts @@ -35,92 +35,72 @@ export class Command public constructor(bot: T, info: CommandInfo = null) { /** - * Bot instance - * @memberof Command - * @type {Bot} - * @name bot - * @instance + * YAMDBF Client instance + * @name Command#client + * @type {Client} */ this.bot = bot; /** * The name of the command, used by the dispatcher * to determine the command being executed - * @memberof Command + * @name Command#name * @type {string} - * @name name - * @instance */ /** * A brief description of the command, displayed * in the commands list via the Help command - * @memberof Command + * @name Command#description * @type {string} - * @name description - * @instance */ /** * An example of command usage. The token '<prefix>' will * be replaced by the guild-specific command prefix in the Help command when * 'help <command>' is called - * @memberof Command + * @name Command#usage * @type {string} - * @name usage - * @instance */ /** * Extra information about the command to be displayed * by the Help command when 'help <command>' is called - * @memberof Command + * @name Command#extraHelp * @type {string} - * @name extraHelp - * @instance */ /** * The command group that the command belongs to. Allows commands to be * grouped for disabling. The group 'base' cannot be disabled. - * @memberof Command + * @name Command#group * @type {string} - * @name group - * @instance */ /** * Aliases the command can be called by other than its name - * @memberof Command + * @name Command#aliases * @type {string[]} - * @name aliases - * @instance */ /** * Whether or not a command can only be used within a * guild text channel - * @memberof Command + * @name Command#guildOnly * @type {boolean} - * @name guildOnly - * @instance */ /** * Whether or not the command is to be hidden from the * commands list via the default help command - * @memberof Command + * @name Command#hidden * @type {boolean} - * @name hidden - * @instance */ /** * Options for how arguments should be parsed. See: {@link ArgOpts} - * @memberof Command + * @name Command#argOpts * @type {ArgOpts} - * @name argOpts - * @instance */ /** @@ -128,10 +108,8 @@ export class Command * caller to be able to execute the command in the guild the command is called in. *

* If any permissions are provided the command's `guildOnly` property will be automatically set to true - * @memberof Command + * @name Command#permissions * @type {external:PermissionResolvable[]} - * @name permissions - * @instance */ /** @@ -139,18 +117,14 @@ export class Command * has any of the roles in the array, they will be able to use the command *

* If any roles are provided the command's `guildOnly` property will be automatically set to true - * @memberof Command + * @name Command#roles * @type {string[]} - * @name roles - * @instance */ /** * Whether or not the command can be used by the bot owner(s). - * @memberof Command + * @name Command#ownerOnly * @type {boolean} - * @name ownerOnly - * @instance * @see [Bot#config.owner]{@link Bot#config} */ @@ -158,10 +132,8 @@ export class Command * The name of a base command to overload. Commands may only overload * base commands so the {@link Command#group} must be set to 'base' in * order to overload. Commands may only be overloaded by name, not by alias - * @memberof Command + * @name Command#overloads * @type {string} - * @name overloads - * @instance */ // Middleware function storage for the Command instance @@ -179,8 +151,7 @@ export class Command * are what command actions will be passed by the {@link CommandDispatcher} whenever * a command is called. Be sure to receive these in proper order when writing * new commands - * @memberof Command - * @instance + * @method Command#action * @param {external:Message} message Discord.js message object * @param {any[]} args An array containing the args parsed from the command calling message.
* Will contain strings unless middleware is used to transform the args @@ -193,8 +164,7 @@ export class Command /** * Assert {@link Command#action} is typeof Function, finishing the * command creation process.
Called by {@link CommandRegistry#register} - * @memberof Command - * @instance + * @method Command#register */ public register(): void { @@ -264,8 +234,7 @@ export class Command * Note: Middleware functions should only be added to a command one time each, * and thus should be added in the Command's constructor. Multiple middleware * functions can be added to a command via multiple calls to this method - * @memberof Command - * @instance + * @method Command#use * @param {MiddlewareFunction} fn Middleware function. (message, args) => [message, args] * @returns {Command} This command instance */ @@ -281,7 +250,7 @@ export class Command * or not the bot is a selfbot and/or a codeblock language is given * @protected */ - protected _respond(message: Message, response: string, code?: string): Promise + protected respond(message: Message, response: string, code?: string): Promise { if (this.bot.selfbot && !code) return message.edit(response); if (this.bot.selfbot && code) return message.editCode(code, response); diff --git a/src/lib/command/base/Eval.ts b/src/lib/command/base/Eval.ts index f861c98b..1b3bf63c 100644 --- a/src/lib/command/base/Eval.ts +++ b/src/lib/command/base/Eval.ts @@ -22,7 +22,7 @@ export default class extends Command const code: string = message.content.split(this.name).slice(1).join(this.name).trim(); if (!code) { - this._respond(message, '**ERROR:** ```xl\nNo code provided to evaluate.\n```'); + this.respond(message, '**ERROR:** ```xl\nNo code provided to evaluate.\n```'); return; } @@ -33,7 +33,7 @@ export default class extends Command } catch (err) { - return this._respond(message, + return this.respond(message, `**INPUT:**\n\`\`\`js\n${code}\n\`\`\`\n**ERROR:**\n\`\`\`xl\n${this._clean(err)}\n\`\`\``); } if (evaled instanceof Promise) @@ -41,19 +41,19 @@ export default class extends Command evaled.then(res => { if (typeof res !== 'string') res = inspect(res, { depth: 0 }); - this._respond(message, + this.respond(message, `**INPUT:**\n\`\`\`js\n${code}\n\`\`\`\n**OUTPUT:**\n\`\`\`xl\n${this._clean(res)}\n\`\`\``); }) .catch(err => { - this._respond(message, + this.respond(message, `**INPUT:**\n\`\`\`js\n${code}\n\`\`\`\n**ERROR:**\n\`\`\`xl\n${this._clean(err)}\n\`\`\``); }); } else { if (typeof evaled !== 'string') evaled = inspect(evaled, { depth: 0 }); - return this._respond(message, + return this.respond(message, `**INPUT:**\n\`\`\`js\n${code}\n\`\`\`\n**OUTPUT:**\n\`\`\`xl\n${this._clean(evaled)}\n\`\`\``); } } diff --git a/src/lib/command/base/Reload.ts b/src/lib/command/base/Reload.ts index d03ec2d8..e783bc86 100644 --- a/src/lib/command/base/Reload.ts +++ b/src/lib/command/base/Reload.ts @@ -22,7 +22,7 @@ export default class extends Command const command: Command = this.bot.commands.findByNameOrAlias(commandName); if (commandName && !command) - return this._respond(message, `Command "${commandName}" could not be found.`); + return this.respond(message, `Command "${commandName}" could not be found.`); if (command) this.bot.loadCommand(command.name); else this.bot.loadCommand('all'); @@ -30,6 +30,6 @@ export default class extends Command const end: number = now(); const name: string = command ? command.name : null; const text: string = name ? ` "${name}"` : 's'; - return this._respond(message, `Command${text} reloaded. (${(end - start).toFixed(3)} ms)`); + return this.respond(message, `Command${text} reloaded. (${(end - start).toFixed(3)} ms)`); } } diff --git a/src/lib/command/base/SetPrefix.ts b/src/lib/command/base/SetPrefix.ts index 66639faa..fb6a3803 100644 --- a/src/lib/command/base/SetPrefix.ts +++ b/src/lib/command/base/SetPrefix.ts @@ -23,15 +23,15 @@ export default class extends Command public async action(message: Message, [prefix]: [string]): Promise { if (!prefix) - return this._respond(message, `${this.bot.getPrefix(message.guild) + return this.respond(message, `${this.bot.getPrefix(message.guild) ? `Current prefix is \`${this.bot.getPrefix(message.guild)}\`` : 'There is currently no prefix.'}`); if (prefix.length > 10) - return this._respond(message, `Prefixes may only be up to 10 chars in length.`); + return this.respond(message, `Prefixes may only be up to 10 chars in length.`); if (/[\\`]/.test(prefix)) - return this._respond(message, `Prefixes may not contain backticks or backslashes.`); + return this.respond(message, `Prefixes may not contain backticks or backslashes.`); if (prefix === 'noprefix') prefix = ''; @@ -40,7 +40,7 @@ export default class extends Command await guild.settings.set('prefix', prefix); else await this.bot.storage.guilds.get(message.guild.id).settings.set('prefix', prefix); - this._respond(message, prefix === '' ? 'Command prefix removed.' + this.respond(message, prefix === '' ? 'Command prefix removed.' : `Command prefix set to \`${prefix}\``); } } diff --git a/src/lib/command/base/Version.ts b/src/lib/command/base/Version.ts index 76d4b168..aeb5f495 100644 --- a/src/lib/command/base/Version.ts +++ b/src/lib/command/base/Version.ts @@ -15,6 +15,6 @@ export default class extends Command public action(message: Message): void { - this._respond(message, `Current version is: **${this.bot.version}**`); + this.respond(message, `Current version is: **${this.bot.version}**`); } } diff --git a/src/lib/command/base/groupcontrol/ClearLimit.ts b/src/lib/command/base/groupcontrol/ClearLimit.ts index 48654097..2a1d6102 100644 --- a/src/lib/command/base/groupcontrol/ClearLimit.ts +++ b/src/lib/command/base/groupcontrol/ClearLimit.ts @@ -23,13 +23,13 @@ export default class extends Command public async action(message: Message, [commandName]: [string]): Promise { let command: Command = this.bot.commands.find(c => Util.normalize(c.name) === Util.normalize(commandName)); - if (!command) return this._respond(message, `Failed to find a command with the name \`${commandName}\``); + if (!command) return this.respond(message, `Failed to find a command with the name \`${commandName}\``); const storage: GuildStorage = message.guild.storage; let limitedCommands: { [name: string]: string[] } = await storage.settings.get('limitedCommands') || {}; delete limitedCommands[command.name]; storage.settings.set('limitedCommands', limitedCommands); - return this._respond(message, `Successfully cleared role limits for command: \`${command.name}\``); + return this.respond(message, `Successfully cleared role limits for command: \`${command.name}\``); } } diff --git a/src/lib/command/base/groupcontrol/DisableGroup.ts b/src/lib/command/base/groupcontrol/DisableGroup.ts index 2eec0d89..5b78dece 100644 --- a/src/lib/command/base/groupcontrol/DisableGroup.ts +++ b/src/lib/command/base/groupcontrol/DisableGroup.ts @@ -27,14 +27,14 @@ export default class extends Command DISABLED: `Command group "${group}" is already disabled or is not allowed to be disabled.` }; - if (!this.bot.commands.groups.includes(group)) return this._respond(message, err.NO_EXIST); + if (!this.bot.commands.groups.includes(group)) return this.respond(message, err.NO_EXIST); const disabledGroups: string[] = await message.guild.storage.settings.get('disabledGroups') || []; if (group === 'base' || disabledGroups.includes(group)) - return this._respond(message, err.DISABLED); + return this.respond(message, err.DISABLED); disabledGroups.push(group); await message.guild.storage.settings.set('disabledGroups', disabledGroups); - this._respond(message, `**Disabled command group "${group}"**`); + this.respond(message, `**Disabled command group "${group}"**`); } } diff --git a/src/lib/command/base/groupcontrol/EnableGroup.ts b/src/lib/command/base/groupcontrol/EnableGroup.ts index 7583f247..d380e1ea 100644 --- a/src/lib/command/base/groupcontrol/EnableGroup.ts +++ b/src/lib/command/base/groupcontrol/EnableGroup.ts @@ -27,14 +27,14 @@ export default class extends Command ENABLED: `Command group ${group} is already enabled.` }; - if (!this.bot.commands.groups.includes(group)) return this._respond(message, err.NO_EXIST); + if (!this.bot.commands.groups.includes(group)) return this.respond(message, err.NO_EXIST); const disabledGroups: string[] = await message.guild.storage.settings.get('disabledGroups') || []; if (group === 'base' || !disabledGroups.includes(group)) - return this._respond(message, err.ENABLED); + return this.respond(message, err.ENABLED); disabledGroups.splice(disabledGroups.indexOf(group), 1); await message.guild.storage.settings.set('disabledGroups', disabledGroups); - this._respond(message, `**Enabled command group "${group}"**`); + this.respond(message, `**Enabled command group "${group}"**`); } } diff --git a/src/lib/command/base/groupcontrol/Limit.ts b/src/lib/command/base/groupcontrol/Limit.ts index c55e8d15..cfacf8b9 100644 --- a/src/lib/command/base/groupcontrol/Limit.ts +++ b/src/lib/command/base/groupcontrol/Limit.ts @@ -26,8 +26,8 @@ export default class extends Command public async action(message: Message, [commandName, ...roleNames]: [string, string]): Promise { const command: Command = this.bot.commands.find(c => Util.normalize(commandName) === Util.normalize(c.name)); - if (!command) return this._respond(message, `Failed to find a command with the name \`${commandName}\``); - if (command.group === 'base') this._respond(message, `Cannot limit base commands.`); + if (!command) return this.respond(message, `Failed to find a command with the name \`${commandName}\``); + if (command.group === 'base') this.respond(message, `Cannot limit base commands.`); const storage: GuildStorage = message.guild.storage; let limitedCommands: { [name: string]: string[] } = await storage.settings.get('limitedCommands') || {}; @@ -46,13 +46,13 @@ export default class extends Command if (invalidRoles.length > 0) message.channel.send(`Couldn't find role${ invalidRoles.length > 1 ? 's' : ''}: \`${invalidRoles.join('`, `')}\``); - if (roles.length === 0) return this._respond(message, `Failed to add any roles to the command.`); + if (roles.length === 0) return this.respond(message, `Failed to add any roles to the command.`); newLimit = newLimit.concat(roles.map(role => role.id)); limitedCommands[command.name] = newLimit; await storage.settings.set('limitedCommands', limitedCommands); - return this._respond(message, `Successfully added role${roles.length > 1 ? 's' : ''}: \`${ + return this.respond(message, `Successfully added role${roles.length > 1 ? 's' : ''}: \`${ roles.map(role => role.name).join('`, `')}\` to the limiter for command: \`${command.name}\``); } } diff --git a/src/lib/command/base/groupcontrol/ListGroups.ts b/src/lib/command/base/groupcontrol/ListGroups.ts index f7b80076..e1584de3 100644 --- a/src/lib/command/base/groupcontrol/ListGroups.ts +++ b/src/lib/command/base/groupcontrol/ListGroups.ts @@ -25,6 +25,6 @@ export default class extends Command let output: string = 'Command groups:\n'; for (const group of groups) output += `${disabledGroups.includes(group) ? '*' : ' '}${group}\n`; - this._respond(message, output, 'ldif'); + this.respond(message, output, 'ldif'); } }