From 19bcc8154d44bc190cd1e46fcc92d46a1f52fecd Mon Sep 17 00:00:00 2001 From: Lluis Date: Thu, 28 Nov 2024 18:54:44 +0100 Subject: [PATCH] use usernames for !ruletarusa --- handlers/ban.js | 33 ++++++++++++++++++++++++++------- lib/messenger.js | 4 ++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/handlers/ban.js b/handlers/ban.js index 0c76044..23b2970 100644 --- a/handlers/ban.js +++ b/handlers/ban.js @@ -43,14 +43,34 @@ class Ban { } } - async timeoutRoulette(target, bot) { + async timeoutRoulette(target, bot, nicks) { const users = await TwitchService.getCurrentUsers() - if (users && users.length > 0) { - const randomUser = users[Math.floor(Math.random() * users.length)] - await TwitchService.banUser(randomUser.userId, 60) - const text = `¡Pum! ${randomUser.userDisplayName} se ha llevado un timeout de 1 minuto.` - await bot.say(target, text) + let players = [] + nicks.forEach(nick => { + const matchedUser = users.find(u => u.userDisplayName.toLowerCase() === nick.replace(/^@/, '').toLowerCase()) + if (matchedUser) { + players.push(matchedUser) + } + }) + + const chambers = 6 + let gun = Array(chambers).fill(false); + gun[0] = true + gun = gun.sort(() => Math.random() - 0.5) + + for (let i = 0; i < players.length; i++) { + const shot = gun.pop() + if (shot) { + const text = `¡Pum! ${players[i].userDisplayName} se ha llevado un disparo.` + await bot.say(target, text) + await TwitchService.banUser(players[i].userId, 60) + return; + } else { + await bot.say(target, `${players[i].userDisplayName} está a salvo.`) + } + await new Promise(resolve => setTimeout(resolve, 2000)) } + await bot.say(target, "¡Todo el mundo esta a salvo!") } async updateBansList(target, bot) { @@ -102,5 +122,4 @@ class Ban { } } - module.exports = Ban diff --git a/lib/messenger.js b/lib/messenger.js index fd13d86..f65412e 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -164,8 +164,8 @@ class Messenger { if (textSplit.length > 0 && inputParser.isAskingUnbanRoulette(textSplit[0]) && (isVip(context) || isAdmin(context) || isMod(context) || isBroadcaster(context)) && this._isNotCooldown('unbanRoulette',86400)) return handlers.ban.unbanRoulette(target, this.bot) - if (textSplit.length > 0 && inputParser.isAskingTimeoutRoulette(textSplit[0]) && (isVip(context) || isAdmin(context) || isMod(context) || isBroadcaster(context)) && this._isNotCooldown('timeoutRoulette',3600)) - return handlers.ban.timeoutRoulette(target, this.bot) + if (textSplit.length > 1 && inputParser.isAskingTimeoutRoulette(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)) && this._isNotCooldown('timeoutRoulette',600)) + return handlers.ban.timeoutRoulette(target, this.bot, textSplit.slice(1)) if (textSplit.length > 1 && inputParser.isAskingToTimeoutUser(textSplit[0]) && isAdmin(context)) return handlers.ban.ban(target, textSplit[1], this.bot, textSplit[2] || 600)