Skip to content

Commit

Permalink
Update Command#respond, clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Jul 15, 2017
1 parent aa102f3 commit ea6975e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/command/Command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PermissionResolvable, Permissions, Message } from 'discord.js';
import { PermissionResolvable, Permissions, Message, MessageOptions } from 'discord.js';
import { Client } from '../client/Client';
import { MiddlewareFunction } from '../types/MiddlewareFunction';
import { CommandInfo } from '../types/CommandInfo';
Expand Down Expand Up @@ -268,20 +268,19 @@ export class Command<T extends Client = Client>
}

/**
* Send provided response text to the provided message's channel
* via edit or send, with or without a codeblock language, depending
* on whether or not the client is a selfbot and whether or not a
* codeblock language is given
* Send provided response to the provided message's channel
* via edit or send, depending on whether or not the client is
* a selfbot
* @protected
* @param {external:Message} message Discord.js Message object
* @param {string} response String to send
* @param {string} [code] Language to use if a codeblock is desired
* @param {external:MessageOptions} [opetions] Optional Discord.js MessageOptions
* @returns {Promise<external:Message | external:Message[]>}
*/
protected respond(message: Message, response: string, code?: string): Promise<Message | Message[]>
protected respond(message: Message, response: string, options?: MessageOptions): Promise<Message | Message[]>
{
if (this.client.selfbot) return message.edit(response, { code });
return message.channel.send(response, { code });
if (this.client.selfbot) return message.edit(response, options);
return message.channel.send(response, options);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/command/base/Reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export default class extends Command
const command: Command = this.client.commands.findByNameOrAlias(commandName);

if (commandName && !command)
return this.respond(message, res('CMD_RELOAD_ERR_UNKNOWN_COMMAND',
{ commandName: commandName }));
return this.respond(message, res('CMD_RELOAD_ERR_UNKNOWN_COMMAND', { commandName }));

if (command) this.client.loadCommand(command.name);
else this.client.loadCommand('all');
Expand Down
2 changes: 1 addition & 1 deletion src/command/base/groupcontrol/ClearLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class extends Command
{
let command: Command = this.client.commands.find(c => Util.normalize(c.name) === Util.normalize(commandName));
if (!command) return this.respond(message,
res('CMD_CLEARLIMIT_UNKNOWN_COMMAND', { commandName: commandName }));
res('CMD_CLEARLIMIT_UNKNOWN_COMMAND', { commandName }));

const storage: GuildStorage = message.guild.storage;
let limitedCommands: { [name: string]: string[] } = await storage.settings.get('limitedCommands') || {};
Expand Down
2 changes: 1 addition & 1 deletion src/command/base/groupcontrol/Limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class extends Command
Util.normalize(commandName) === Util.normalize(c.name));

if (!command) return this.respond(message,
res('CMD_LIMIT_ERR_UNKNOWN_COMMAND', { commandName: commandName }));
res('CMD_LIMIT_ERR_UNKNOWN_COMMAND', { commandName }));
if (command.group === 'base') return this.respond(message, res('CMD_LIMIT_ERR_INVALID_GROUP'));

const storage: GuildStorage = message.guild.storage;
Expand Down
2 changes: 1 addition & 1 deletion src/command/base/groupcontrol/ListGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export default class extends Command
let output: string = res('CMD_LISTGROUPS_GROUPS',
{ groups: groups.join(', '), disabledGroups: disabledGroups.join(', ') });

this.respond(message, output, 'ldif');
this.respond(message, output, { code: 'ldif '});
}
}

0 comments on commit ea6975e

Please sign in to comment.