From 68230b25e6c2d54425dfe74df87cb306d6d866b3 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 30 Aug 2016 19:49:41 +0200 Subject: [PATCH 1/4] added channel limitation for normal users moved trigger check further back in the function --- bots/tipbot.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bots/tipbot.js b/bots/tipbot.js index 7d232f2..911e0f2 100644 --- a/bots/tipbot.js +++ b/bots/tipbot.js @@ -30,17 +30,21 @@ function respond(bot, data) { var tipper = data.user, channel = data.channel, words = data.text.trim().split(' ').filter( function(n){return n !== "";} ); - + + if (words[0] !== command) { + // if the received message isn't starting with the trigger -> ignore + return; + } + if (!lbry) { bot.postMessage(channel, 'Failed to connect to lbrycrd', {icon_emoji: ':exclamation:'}); return; } - if (words[0] !== command) { - // wtf? - 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); } - + var subcommand = words.length >= 2 ? words[1] : 'help'; if (subcommand === 'help') { From 3817ec8e330cb98fc3c645be13a390dd0344833a Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 30 Aug 2016 20:00:19 +0200 Subject: [PATCH 2/4] fixed condition --- bots/tipbot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bots/tipbot.js b/bots/tipbot.js index 911e0f2..9e4dfdc 100644 --- a/bots/tipbot.js +++ b/bots/tipbot.js @@ -41,7 +41,7 @@ function respond(bot, data) { return; } - if (!tipper.is_admin || !tipper.is_owner || channel.name !== "bot-sandbox" ){ + if ((!tipper.is_admin || !tipper.is_owner) && channel.name !== "bot-sandbox" ){ bot.postMessage(channel, 'Please help keep the channel clean: use #bot-sandbox', globalSlackParams); } From cf689927d99b8d6d52cd2206286d4e29fc8751da Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 30 Aug 2016 20:41:59 +0200 Subject: [PATCH 3/4] added obviously missing return --- bots/tipbot.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bots/tipbot.js b/bots/tipbot.js index 9e4dfdc..4444a12 100644 --- a/bots/tipbot.js +++ b/bots/tipbot.js @@ -42,7 +42,8 @@ function respond(bot, data) { } if ((!tipper.is_admin || !tipper.is_owner) && channel.name !== "bot-sandbox" ){ - bot.postMessage(channel, 'Please help keep the channel clean: use #bot-sandbox', globalSlackParams); + bot.postMessage(channel, 'Please help keep the channel clean: use #bot-sandbox', globalSlackParams); + return; } var subcommand = words.length >= 2 ? words[1] : 'help'; From 1d0252ab024ba19dda4a6ee4ad1ab7541e115623 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 30 Aug 2016 21:16:19 +0200 Subject: [PATCH 4/4] 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; }