Skip to content

Commit

Permalink
timeout roulette
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Oct 21, 2024
1 parent b7aa8d4 commit 0d5a7e7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions handlers/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class Ban {
}
}

async timeoutRoulette(target, bot) {
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)
}
}

async updateBansList(target, bot) {
const bansList = await TwitchService.updateBannedUsers().catch((e) => {
console.error(e +'getBannedUsers on getBannedUsers')}
Expand Down
6 changes: 5 additions & 1 deletion lib/inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ class InputParser {
}

isAskingUnbanRoulette(text) {
return text.toLowerCase().startsWith('!ruleta')
return text.toLowerCase().startsWith('!ruletasuerte')
}

isAskingTimeoutRoulette(text) {
return text.toLowerCase().startsWith('!ruletarusa')
}

isAskingToSetTitle (text) {
Expand Down
6 changes: 5 additions & 1 deletion lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Messenger {
screenshotTF: false,
tf: false,
openai: false,
unbanRoulette: false
unbanRoulette: false,
timeoutRoulette: false
}
this.notifier = new Notifier(this.bot)
await this.notifier.notify()
Expand Down Expand Up @@ -158,6 +159,9 @@ 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.isAskingToTimeoutUser(textSplit[0]) && isAdmin(context))
return handlers.ban.ban(target, textSplit[1], this.bot, textSplit[2] || 600)

Expand Down
13 changes: 12 additions & 1 deletion services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ async function setGame(name) {
}
}

async function getCurrentUsers() {
const api = await broadcasterApiClient.getApiClient()
const users = await api.chat.getChattersPaginated(config.twitch.roomId)
let usersList = []
for await (const user of users) {
usersList.push(user)
}
return usersList
}

async function updateBannedUsers () {
const api = await broadcasterApiClient.getApiClient()
const bans = await api.moderation.getBannedUsersPaginated(config.twitch.roomId)
Expand Down Expand Up @@ -231,7 +241,8 @@ module.exports = {
addBan,
getBannedUsersCountByDate,
getTimeouts,
removeBan
removeBan,
getCurrentUsers
}


0 comments on commit 0d5a7e7

Please sign in to comment.