From 1d0252ab024ba19dda4a6ee4ad1ab7541e115623 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 30 Aug 2016 21:16:19 +0200 Subject: [PATCH] added support for tipping in every channel --- bots/tipbot.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bots/tipbot.js b/bots/tipbot.js index 4444a12..55b3785 100644 --- a/bots/tipbot.js +++ b/bots/tipbot.js @@ -41,12 +41,16 @@ function respond(bot, data) { return; } - if ((!tipper.is_admin || !tipper.is_owner) && channel.name !== "bot-sandbox" ){ - bot.postMessage(channel, 'Please help keep the channel clean: use #bot-sandbox', globalSlackParams); - return; - } - var subcommand = words.length >= 2 ? words[1] : 'help'; + var isAllowedTip = false; + if ((!tipper.is_admin || !tipper.is_owner) && channel.name !== 'bot-sandbox' ){ + //to check if the command is a tip (hence allowed to pass through) we need to check against all the other commands) + if (subcommand === 'help' || subcommand === 'balance' || subcommand === 'deposit' || subcommand === 'withdraw'){ + bot.postMessage(channel, 'Please help keep the channel clean: use #bot-sandbox', globalSlackParams); + return; + } + isAllowedTip = true; + } if (subcommand === 'help') { doHelp(bot, channel); @@ -61,7 +65,7 @@ function respond(bot, data) { doWithdraw(bot, channel, tipper, words); } else { - doTip(bot, channel, tipper, words); + doTip(bot, channel, tipper, words, isAllowedTip); } } @@ -116,9 +120,11 @@ function doWithdraw(bot, channel, tipper, words) { } -function doTip(bot, channel, tipper, words) { +function doTip(bot, channel, tipper, words, isAllowedTip) { if (words.length < 3) { - doHelp(bot, channel); + //necessary to avoid the help menu opening up on all channels + if (!isAllowedTip) + doHelp(bot, channel); return; }