From 8ceb8c1098f7b3eaa49fedd3ba150bf0abd78623 Mon Sep 17 00:00:00 2001 From: unek Date: Sun, 23 Feb 2014 19:24:02 +0100 Subject: [PATCH] allow tipping amounts lesser than 1 --- README.md | 2 +- bin/tipbot.js | 7 ++++++- config/config.sample.yml | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 564c135..eac9007 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ rpcpassword= rpcallowip= ``` -To run the bot simply use `npm start` or `node bin/tipbot`. +To run the bot simply use `node bin/tipbot` or `npm start`. ## Commands diff --git a/bin/tipbot.js b/bin/tipbot.js index b418991..fdeed6a 100644 --- a/bin/tipbot.js +++ b/bin/tipbot.js @@ -178,7 +178,7 @@ client.addListener('message', function(from, channel, message) { switch(command) { case 'tip': - var match = message.match(/^.?tip (\S+) (\d+)/); + var match = message.match(/^.?tip (\S+) ([\d\.]+)/); if(match == null || match < 3) { client.say(channel, 'Usage: !tip ') return; @@ -186,6 +186,11 @@ client.addListener('message', function(from, channel, message) { var to = match[1]; var amount = Number(match[2]); + if(amount == NaN) { + client.say(channel, settings.messages.invalid_amount.expand({name: from, amount: match[2]})); + return; + } + if(to.toLowerCase() == from.toLowerCase()) { client.say(channel, settings.messages.self_tip.expand({name: from})); return; diff --git a/config/config.sample.yml b/config/config.sample.yml index bfdcfbe..ebc3b59 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -62,6 +62,7 @@ messages: invalid_address: 'Sorry %name%, the address you specified is invalid (%address%).' tip_too_small: 'Sorry %from%, your tip to %to% (%amount%%short_name%) is too small (min. %min_tip%%short_name%).' tip_self: "Sorry %name%, you can't tip yourself!" + invalid_amount: 'Sorry %name%, "%amount%" is not a correct amount.' withdraw_success: - '%name%: %amount%%short_name% has been withdrawn from your account to %address%' - 'You have been charged %withdrawal_fee%%short_name% withdrawal fee.'