Skip to content

Commit

Permalink
unban roulette
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Oct 20, 2024
1 parent 45a2d58 commit 0062129
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 102 deletions.
65 changes: 14 additions & 51 deletions handlers/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const moment = require('moment')
require('mathjs')

class Ban {
async getUnbanRequests(target, bot) {
async getBansCountAndUnbanRequests(target, bot) {
const result = await TwitchService.getUnbanRequests()
if (result !== null) {
const text = result.length > 0 ? `Hay ${result.length} solicitud/es de desbaneo pendientes de revisar (${this._getUserNames(result)})` : 'No hay solicitudes de desbaneo pendientes de revisar.'
const bans = await TwitchService.getBannedUsersCountByDate(moment().subtract(10, 'years').startOf('year').toDate())
if (result && bans) {
const text = `${bans.length} bans.` + result.length > 0 ? ` Hay ${result.length} solicitud/es de desbaneo pendientes de revisar (${this._getUserNames(result)})` : ' No hay solicitudes de desbaneo pendientes de revisar.'
await bot.say(target, text)
}
}
Expand All @@ -32,6 +33,16 @@ class Ban {
}
}

async unbanRoulette(target, username, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().subtract(10, 'years').startOf('year').toDate())
if (bans) {
const randomBan = bans[Math.floor(Math.random() * bans.length)]
await TwitchService.unBanUser(randomBan.userId)
const text = `Enhorabuena ${randomBan.userName}`
await bot.say(target, text)
}
}

async updateBansList(target, bot) {
const bansList = await TwitchService.updateBannedUsers().catch((e) => {
console.error(e +'getBannedUsers on getBannedUsers')}
Expand All @@ -51,54 +62,6 @@ class Ban {
}
}

async getTimeoutsCount(target, bot) {
const timeouts = await TwitchService.getTimeouts()
if (timeouts) {
const text = `${timeouts.length} timeouts total`
await bot.say(target, text)
}
}

async getTodayBansCount(target, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().startOf('day').toDate())
if (bans) {
const text = `${bans.length} bans hoy`
await bot.say(target, text)
}
}

async getWeeklyBansCount(target, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().startOf('week').toDate())
if (bans) {
const text = `${bans.length} bans esta semana`
await bot.say(target, text)
}
}

async getMonthlyBansCount(target, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().startOf('month').toDate())
if (bans) {
const text = `${bans.length} bans este mes`
await bot.say(target, text)
}
}

async getYearlyBansCount(target, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().startOf('year').toDate())
if (bans) {
const text = `${bans.length} bans este año`
await bot.say(target, text)
}
}

async getTotalBansCount(target, bot) {
const bans = await TwitchService.getBannedUsersCountByDate(moment().subtract(10, 'years').startOf('year').toDate())
if (bans) {
const text = `${bans.length} bans totales`
await bot.say(target, text)
}
}

_getUserNames (unbanRequests) {
let text
if (unbanRequests.length === 1){
Expand Down
32 changes: 6 additions & 26 deletions lib/inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ class InputParser {
return text.toLowerCase().startsWith('!estado')
}

isAskingForPendingUnbanRequests (text) {
return text.toLowerCase().startsWith('!bans')
}

isAskingForTFVisited (text) {
return text.toLowerCase().startsWith('!visto')
}
Expand Down Expand Up @@ -98,34 +94,18 @@ class InputParser {
return text.toLowerCase().startsWith('!updatebans')
}

isAskingTodayBansCount(text) {
return text.toLowerCase().startsWith('!banshoy')
}

isAskingWeeklyBansCount(text) {
return text.toLowerCase().startsWith('!banssemana')
}

isAskingMonthlyBansCount(text) {
return text.toLowerCase().startsWith('!bansmes')
}

isAskingYearlyBansCount(text) {
return text.toLowerCase().startsWith('!bansaño')
}

isAskingTotalBansCount(text) {
return text.toLowerCase().startsWith('!banstotal')
}

isAskingTimeoutsCount(text) {
return text.toLowerCase().startsWith('!timeoutstotal')
isAskingBans(text) {
return text.toLowerCase().startsWith('!bans')
}

isAskingLastTimeouts(text) {
return text.toLowerCase().startsWith('!timeouts')
}

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

isAskingToSetTitle (text) {
return text.toLowerCase().startsWith('!titulo')
}
Expand Down
32 changes: 7 additions & 25 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Messenger {
bans: false,
screenshotTF: false,
tf: false,
openai: false
openai: false,
unbanRoulette: false
}
this.notifier = new Notifier(this.bot)
await this.notifier.notify()
Expand Down Expand Up @@ -147,34 +148,15 @@ class Messenger {


// Bans
if (textSplit.length > 0 && inputParser.isAskingTodayBansCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getTodayBansCount(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingWeeklyBansCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getWeeklyBansCount(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingMonthlyBansCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getMonthlyBansCount(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingYearlyBansCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getYearlyBansCount(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingTotalBansCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getTotalBansCount(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingTimeoutsCount(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getTimeoutsCount(target, this.bot)
if (textSplit.length > 0 && inputParser.isAskingBans(textSplit[0]) &&
this._isNotCooldown('bans', 30) && (isAdmin(context) || isMod(context) || isBroadcaster(context)) )
return handlers.ban.getBansCountAndUnbanRequests(target, this.bot)

if (textSplit.length > 0 && inputParser.isAskingLastTimeouts(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getTimeouts(target, this.bot)




if (textSplit.length > 0 && inputParser.isAskingForPendingUnbanRequests(textSplit[0]) &&
this._isNotCooldown('bans', 30) &&
(isVip(context) || isMod(context) || isBroadcaster(context)))
return handlers.ban.getUnbanRequests(target, this.bot)
if (textSplit.length > 0 && inputParser.isAskingUnbanRoulette(textSplit[0]) && (isAdmin(context) || isMod(context) || isBroadcaster(context)) && this._isNotCooldown('unbanRoulette',86400))
return handlers.ban.unbanRoulette(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

0 comments on commit 0062129

Please sign in to comment.