From 34151fc92b47104bdb35b901a41f21d0fcba8ef5 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Tue, 4 Dec 2018 20:26:51 -0500 Subject: [PATCH] fix roletip --- bot/modules/tipbot.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bot/modules/tipbot.js b/bot/modules/tipbot.js index 63fe8bf..6f35c95 100644 --- a/bot/modules/tipbot.js +++ b/bot/modules/tipbot.js @@ -230,23 +230,26 @@ function doRoleTip(bot, message, tipper, words, helpmsg, MultiorRole) { doHelp(message, helpmsg); return; } - let prv = false; - let amountOffset = 2; - if (words.length >= 4 && words[1] === 'private') { - prv = true; - amountOffset = 3; - } + let isPrivateTip = words.length >= 4 && words[1] === 'private'; + let amountOffset = isPrivateTip ? 3 : 2; + let amount = getValidatedAmount(words[amountOffset]); - if (amount == null) { + if (amount === null) { message.reply("I don't know how to tip that amount of LBC...").then(message => message.delete(10000)); return; } - if (message.mentions.roles.first().id) { - if (message.mentions.roles.first().members.first().id) { - let userIDs = message.mentions.roles.first().members.map(member => member.user.id.replace('!', '')); - for (let i = 0; i < userIDs.length; i++) { - sendLBC(bot, message, tipper, userIDs[i].toString(), amount, prv, MultiorRole); - } + + let roleToTip = message.mentions.roles.first(); + if (roleToTip !== null) { + let membersOfRole = message.mentions.roles + .first() + .members.first() + .keyArray(); + if (membersOfRole.length > 0) { + let userIDs = membersOfRole.map(member => member.user.id.replace('!', '')); + userIDs.forEach(u => { + sendLBC(bot, message, tipper, u, amount, isPrivateTip, MultiorRole); + }); } else { return message.reply('Sorry, I could not find any users to tip in that role...').then(message => message.delete(10000)); } @@ -329,10 +332,7 @@ function inPrivateOrBotSandbox(msg) { } function getValidatedAmount(amount) { - amount = amount.trim(); - if (amount.toLowerCase().endsWith('lbc')) { - amount = amount.substring(0, amount.length - 3); - } + amount = amount.toLowerCase().replace('lbc', ''); return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null; }