Skip to content

Commit

Permalink
Re-implement noCommandErr, rename to unknownCommandError
Browse files Browse the repository at this point in the history
I forgot to reimplement this when I was rewriting the command dispatcher
  • Loading branch information
zajrik committed Mar 30, 2017
1 parent ecd1396 commit 03eb421
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/lib/bot/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Bot extends Client
public commandsDir: string;
public statusText: string;
public readyText: string;
public noCommandErr: boolean;
public unknownCommandError: boolean;
public selfbot: boolean;
public passive: boolean;
public version: string;
Expand Down Expand Up @@ -95,13 +95,13 @@ export class Bot extends Client
/**
* Whether or not a generic 'command not found' message
* should be given in DMs to instruct the user to
* use the `help` command. Set to false to disable
* this message
* use the `help` command. <code>true</code> by default
* @name Bot#noCommandErr
* @type {string}
* @instance
*/
this.noCommandErr = botOptions.noCommandErr === undefined ? true : botOptions.noCommandErr;
this.unknownCommandError = botOptions.unknownCommandError === undefined ?
true : botOptions.unknownCommandError;

/**
* Whether or not the bot is a selfbot
Expand Down
18 changes: 17 additions & 1 deletion src/lib/command/CommandDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export class CommandDispatcher<T extends Bot>
if (await this.isBlacklisted(message.author, message, dm)) return;

const [commandCalled, command, prefix, name]: [boolean, Command<T>, string, string] = await this.isCommandCalled(message);
if (!commandCalled) return;
if (!commandCalled)
{
if (dm && this._bot.unknownCommandError)
message.channel.send(this.unknownCommandError());
return;
}
if (command.ownerOnly && !this._bot.isOwner(message.author)) return;

// Check ratelimits
Expand Down Expand Up @@ -256,6 +261,17 @@ export class CommandDispatcher<T extends Bot>
});
}

/**
* Return an error for unknown commands in DMs
*/
private unknownCommandError(): string
{
return `Sorry, I didn't recognize any command in your message.\n`
+ `Try saying "help" to view a list of commands you can use in `
+ `this DM, or try calling the\nhelp command in a server channel `
+ `to see what commands you can use there!`;
}

/**
* Return an error for guild only commands
*/
Expand Down
4 changes: 2 additions & 2 deletions src/lib/types/BotOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type BotOptions = {
commandsDir?: string;
statusText?: string;
readyText?: string;
noCommandErr?: boolean;
unknownCommandError?: boolean;
selfbot?: boolean;
passive?: boolean;
version?: string;
Expand All @@ -26,7 +26,7 @@ export type BotOptions = {
* @property {string} [commandsDir] See: {@link Bot#commandsDir}
* @property {string} [statusText=null] See: {@link Bot#statusText}
* @property {string} [readyText='Ready!'] See: {@link Bot#readyText}
* @property {boolean} [noCommandErr=true] See: {@link Bot#noCommandErr}
* @property {boolean} [unknownCommandError=true] See: {@link Bot#unknownCommandError}
* @property {boolean} [selfbot=false] See: {@link Bot#selfbot}
* @property {boolean} [passive=false] see {@link Bot#passive}
* @property {string} [version='0.0.0'] See: {@link Bot#version}
Expand Down
3 changes: 2 additions & 1 deletion test/client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const client = new Bot({
name: 'test',
token: config.token,
config: config,
commandsDir: path.join(__dirname, 'commands')
commandsDir: path.join(__dirname, 'commands'),
unknownCommandError: false
}).start();

client.on('waiting', () => client.emit('finished'));
Expand Down

0 comments on commit 03eb421

Please sign in to comment.