diff --git a/handlers/ban.js b/handlers/ban.js index 2fc5288..7053b21 100644 --- a/handlers/ban.js +++ b/handlers/ban.js @@ -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) } } @@ -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')} @@ -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){ diff --git a/lib/inputParser.js b/lib/inputParser.js index ae0dd10..0585230 100644 --- a/lib/inputParser.js +++ b/lib/inputParser.js @@ -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') } @@ -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') } diff --git a/lib/messenger.js b/lib/messenger.js index 69e5a71..6a18f9a 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -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() @@ -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)