From 3989cf277b37d5578c581b6f81ca9b516d231a60 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 26 Aug 2011 12:42:44 +0100 Subject: [PATCH] User commands use valMatch --- modules/user.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/user.js b/modules/user.js index a4c6095..244a656 100644 --- a/modules/user.js +++ b/modules/user.js @@ -8,33 +8,34 @@ var userCommands = function(dbot) { }, '~q': function(data, params) { - var q = data.message.match(/^~q ([\d\w\s]*)/) - if(q != undefined) { + var q = data.message.valMatch(/^~q ([\d\w\s]*)/, 2) + if(q) { dbot.say(data.channel, dbot.quotes.get(q[1].trim())); } }, '~qadd': function(data, params) { - var q = data.message.match(/^~qadd ([\d\w\s]*)=(.+)$/); - if(q != null && q.length >= 3) { + var q = data.message.valMatch(/^~qadd ([\d\w\s]*)=(.+)$/, 3); + if(q) { dbot.say(data.channel, dbot.quotes.add(q)); - dbot.save(); } else { dbot.say(data.channel, 'Burn the invalid syntax!'); } }, '~qset': function(data, params) { - var q = data.message.match(/^~qset ([\d\w\s]*)=(.+)$/); - if(q != undefined && q.length >= 3) { + var q = data.message.match(/^~qset ([\d\w\s]*)=(.+)$/, 3); + if(q) { dbot.say(data.channel, dbot.quotes.set(q)); + } else { + dbot.say(data.channel, 'Burn the invalid syntax!'); } }, '~qcount': function(data, params) { - var q = data.message.match(/^~qcount ([\d\w\s]*)/)[1].trim(); - if(q != undefined) { - dbot.say(data.channel, dbot.quotes.count(q)); + var q = data.message.valMatch(/^~qcount ([\d\w\s]*)/, 2); + if(q) { + dbot.say(data.channel, dbot.quotes.count(q[1].trim())); } }, @@ -66,9 +67,10 @@ var userCommands = function(dbot) { if(commands.hasOwnProperty(params[0])) { commands[params[0]](data, params); + dbot.save(); } else { - var q = data.message.match(/^~([\d\w\s]*)/) - if(q != undefined) { + var q = data.message.valMatch(/^~([\d\w\s]*)/, 2) + if(q) { dbot.say(data.channel, dbot.quotes.get(q[1].trim())); } }