From 1ad20e960699a039a749d5d0ac82113183674d01 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 2 Dec 2012 16:18:59 +0000 Subject: [PATCH] print usage string on wrong syntax for regex --- modules/command.js | 6 +++++- modules/js.js | 2 ++ modules/poll.js | 8 +++++++- modules/quotes.js | 5 +++++ modules/report.js | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/command.js b/modules/command.js index 5f78d8e..8cd23a1 100644 --- a/modules/command.js +++ b/modules/command.js @@ -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')); + } } } } diff --git a/modules/js.js b/modules/js.js index 83e1bf0..3ac75e4 100644 --- a/modules/js.js +++ b/modules/js.js @@ -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', diff --git a/modules/poll.js b/modules/poll.js index a09e3a9..5b016d1 100644 --- a/modules/poll.js +++ b/modules/poll.js @@ -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, diff --git a/modules/quotes.js b/modules/quotes.js index eba2a90..1cb915f 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -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, diff --git a/modules/report.js b/modules/report.js index 1e6f03d..f68813d 100644 --- a/modules/report.js +++ b/modules/report.js @@ -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',