diff --git a/app.js b/app.js index 558a164..a2cebbb 100644 --- a/app.js +++ b/app.js @@ -29,10 +29,13 @@ mongoose.connect(config.database).then(() => { app.get('/listado', function(req, res) { TempsDeFlorsService.getTFSpots(config.twitch.roomId).then((spots) => { + const percentage = parseFloat((spots.filter((s) => s.visited).length / spots.length * 100).toFixed(2)) res.render('pages/index',{ spots: spots, url: config.externalUrl, - channel: config.twitch.channels + channel: config.twitch.channels, + percentage: percentage, + bgClass: percentage > 50 ? 'bg-success' : (percentage > 25 ? 'bg-warning' : 'bg-danger') }); }) }); diff --git a/handlers/tempsDeFlors.js b/handlers/tempsDeFlors.js index 2ccb090..b15e8b7 100644 --- a/handlers/tempsDeFlors.js +++ b/handlers/tempsDeFlors.js @@ -9,7 +9,9 @@ class TempsDeFlors { const spotNumber = parseInt(text) if (typeof spotNumber === 'number') { const spot = await TempsDeFlorsService.getTFSpot(roomId, spotNumber) - this._printSpot(spot, target, bot) + if (spot) { + this._printSpot(spot, target, bot) + } } } @@ -30,7 +32,9 @@ class TempsDeFlors { const spotNumber = parseInt(text) if (typeof spotNumber === 'number') { const spot = await TempsDeFlorsService.setTFVisited(roomId, spotNumber, isVisited) - this._printSpot(spot, target, bot) + if (spot) { + this._printSpot(spot, target, bot) + } } } @@ -38,10 +42,17 @@ class TempsDeFlors { const spotNumber = parseInt(text) if (typeof spotNumber === 'number') { const spot = await TempsDeFlorsService.setTFVisited(roomId, spotNumber, true, true) - if (spot){ + if (spot) { await TwitchService.setActiveSpot(spotNumber) + bot.say(target, `Punto: ${this._getText(spot)} activo para !foto`) } - bot.say(target, `Punto: ${this._getText(spot)} activo para !foto`) + } + } + + async setDeactivate (target, bot) { + const oldActiveSpot = await TwitchService.setActiveSpot(0) + if (oldActiveSpot !== 0) { + bot.say(target, `Punto ${oldActiveSpot} desactivado.`) } } @@ -97,7 +108,7 @@ class TempsDeFlors { return text } - _getScreenshotText(spot ){ + _getScreenshotText(spot){ let text = '' if (spot.screenshot) { text = ` ${config.externalUrl}/i/${spot.screenshot}` diff --git a/lib/messenger.js b/lib/messenger.js index a6cccd5..77e4eda 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -155,7 +155,7 @@ class Messenger { if (textSplit.length > 0 && inputParser.isAskingForTFDeactivateSpot(textSplit[0]) && (this._isVip(context) || this._isMod(context) || this._isBroadcaster(context))) { - return handlers.tempsDeFlors.setActive(target, 0, this.bot, context['room-id']) + return handlers.tempsDeFlors.setDeactivate(target, this.bot) } if (textSplit.length > 1 && inputParser.isAskingForTFActiveSpot(textSplit[0]) && @@ -174,7 +174,7 @@ class Messenger { } if (textSplit.length > 0 && inputParser.isAskingForTakeScreenshot(textSplit[0])){ - if (!this.cooldown.screenshot) { + if (!this.cooldown.screenshot && !this.cooldown.screenshotTF) { this.cooldown.screenshot = true setTimeout(() => { this.cooldown.screenshot = false diff --git a/services/twitch.js b/services/twitch.js index 1da12b3..bbf9274 100644 --- a/services/twitch.js +++ b/services/twitch.js @@ -65,7 +65,7 @@ async function saveLastUpdate () { } async function setActiveSpot (activeSpot) { - await dbManager.updateChannel(config.twitch.channels, { activeSpot: activeSpot }) + return dbManager.updateChannel(config.twitch.channels, { activeSpot: activeSpot }) } async function _getHeaders () { diff --git a/views/pages/comandos.ejs b/views/pages/comandos.ejs index aa75342..c552bfa 100644 --- a/views/pages/comandos.ejs +++ b/views/pages/comandos.ejs @@ -57,12 +57,12 @@