Skip to content

Commit

Permalink
use usernames for !ruletarusa
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Nov 28, 2024
1 parent 374b31f commit 19bcc81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
33 changes: 26 additions & 7 deletions handlers/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -102,5 +122,4 @@ class Ban {
}
}


module.exports = Ban
4 changes: 2 additions & 2 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 19bcc81

Please sign in to comment.