print usage string on wrong syntax for regex

This commit is contained in:
Luke Slater 2012-12-02 16:18:59 +00:00
parent 54b8b00bda
commit 1ad20e9606
5 changed files with 20 additions and 2 deletions

View File

@ -71,7 +71,11 @@ var command = function(dbot) {
dbot.save();
} else {
if(commandName !== '~') {
event.reply(dbot.t('syntax_error'));
if(dbot.commands[commandName].hasOwnProperty('usage')){
event.reply('Usage: ' + dbot.commands[commandName].usage);
} else {
event.reply(dbot.t('syntax_error'));
}
}
}
}

View File

@ -32,6 +32,8 @@ var js = function(dbot) {
};
commands['~js'].regex = [/^~js (.*)/, 2];
commands['~ajs'].regex = [/^~ajs (.*)/, 2];
commands['~js'].usage = '~js [command]';
commands['~ajs'].usage = '~ajs [command]';
return {
'name': 'js',

View File

@ -207,13 +207,19 @@ var poll = function(dbot) {
}
}
};
commands['~newpoll'].regex = [/~newpoll (av )?([^ ]+) \[options=([^ ]+)\] (.+)/, 5];
commands['~newpoll'].regex = [/~newpoll (av )?([^ ]+) options=([^ ]+) (.+)/, 5];
commands['~addoption'].regex = [/~addoption ([^ ]+) ([^ ]+)/, 3];
commands['~rmoption'].regex = [/~rmoption ([^ ]+) ([^ ]+)/, 3];
commands['~vote'].regex = [/~vote ([^ ]+) ([^ ]+)/, 3];
commands['~pdesc'].regex = [/~pdesc ([^ ]+)/, 2];
commands['~count'].regex = [/~count ([^ ]+)/, 2];
commands['~newpoll'].usage = '~newpoll [pollname] options=[each,poll,option] [Poll Description]';
commands['~addoption'].usage = '~addoption [pollname] [newoption]';
commands['~rmoption'].usage= '~rmoption [pollname] [optiontoremove]';
commands['~vote'].usage= '~vote [pollname] [option]';
commands['~pdesc'].usage = '~pdesc [pollname]';
return {
'name': 'poll',
'ignorable': true,

View File

@ -218,6 +218,11 @@ var quotes = function(dbot) {
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~q'].usage = '~q [category]';
commands['~qsearch'].usage = '~qsearch [category]=[search]';
commands['~rmlast'].usage = '~rmlast [category]'
commands['~qadd'].usage = '~qadd [category]=[content]';
return {
'name': 'quotes',
'ignorable': true,

View File

@ -38,6 +38,7 @@ var report = function(dbot) {
};
commands['~report'].regex = [/^~report ([^ ]+) ([^ ]+) (.+)$/, 4];
commands['report'].usage = '~report [#channel] [username] [reason for reporting]';
return {
'name': 'report',