From 7503eacf14275c271ab153dc393a3a5449e04fd3 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 31 Aug 2016 10:14:26 -0400 Subject: [PATCH] ignore LBC at end of tip amounts --- bots/tipbot.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bots/tipbot.js b/bots/tipbot.js index 6a761d8..f6fd691 100644 --- a/bots/tipbot.js +++ b/bots/tipbot.js @@ -99,9 +99,9 @@ function doWithdraw(bot, channel, tipper, words) { } var address = words[2], - amount = words[3]; + amount = getValidatedAmount(words[3]); - if (!validateAmount(amount)) { + if (amount === null) { bot.postMessage(channel, '<@' + tipper + '>: I dont know how to withdraw that many credits', globalSlackParams); return; } @@ -124,9 +124,9 @@ function doTip(bot, channel, tipper, words) { } var user = words[1], - amount = words[2]; + amount = getValidatedAmount(words[2]); - if (!validateAmount(amount)) { + if (amount === null) { bot.postMessage(channel, '<@' + tipper + '>: I dont know how to tip that many credits', globalSlackParams); return; } @@ -204,8 +204,12 @@ function getAddress(userId, cb) { } -function validateAmount(amount) { - return amount.match(/^[0-9]+(\.[0-9]+)?$/); +function getValidatedAmount(amount) { + amount = amount.trim(); + if (amount.toLowerCase().endsWith('lbc')) { + amount = amount.substring(0, amount.length-3); + } + return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null; }