allowed dm commands

This commit is contained in:
Niko Storni 2016-08-30 22:15:05 +02:00
commit 98bc0ce942

View file

@ -30,28 +30,23 @@ 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;
}
var subcommand = words.length >= 2 ? words[1] : 'help';
var isAllowedTip = false;
//uncomment the next block when the new lower-level API is added (is_admin and is_owner must be included in the data dump)
if (/*(!tipper.is_admin || !tipper.is_owner) && */(channel.name !== 'C1TEEBS2Z' && !channel.name.startsWith("D") )){
//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;
var moveToBotSandbox = /*!tipper.is_admin && !tipper.is_owner && */channel !== 'C1TEEBS2Z' && ['help', 'balance', 'deposit', 'withdraw'].indexOf(subcommand) != -1 && !channel.name.startsWith("D")
if (moveToBotSandbox) {
bot.postMessage(channel, 'Please use <#C1TEEBS2Z|bot-sandbox> to talk to bots.', globalSlackParams);
return;
}
if (subcommand === 'help') {
@ -67,7 +62,7 @@ function respond(bot, data) {
doWithdraw(bot, channel, tipper, words);
}
else {
doTip(bot, channel, tipper, words, isAllowedTip);
doTip(bot, channel, tipper, words);
}
}
@ -122,11 +117,9 @@ function doWithdraw(bot, channel, tipper, words) {
}
function doTip(bot, channel, tipper, words, isAllowedTip) {
function doTip(bot, channel, tipper, words) {
if (words.length < 3) {
//necessary to avoid the help menu opening up on all channels
if (!isAllowedTip)
doHelp(bot, channel);
doHelp(bot, channel);
return;
}
@ -157,6 +150,7 @@ function doTip(bot, channel, tipper, words, isAllowedTip) {
function doHelp(bot, channel) {
bot.postMessage(channel,
'*USE <#bot-sandbox> FOR EVERYTHING EXCEPT ACTUAL TIPPING*\n' +
'`' + command + ' help`: this message\n' +
'`' + command + ' balance`: get your balance\n' +
'`' + command + ' deposit`: get address for deposits\n' +