Skip to content

Commit

Permalink
fix when spot is not defined.
Browse files Browse the repository at this point in the history
- add progress bar for index page
  • Loading branch information
lluisd committed May 13, 2024
1 parent 2e0acb8 commit d8ce131
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
})
});
Expand Down
21 changes: 16 additions & 5 deletions handlers/tempsDeFlors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -30,18 +32,27 @@ 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)
}
}
}

async setActive (target, text, bot, roomId) {
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.`)
}
}

Expand Down Expand Up @@ -97,7 +108,7 @@ class TempsDeFlors {
return text
}

_getScreenshotText(spot ){
_getScreenshotText(spot){
let text = ''
if (spot.screenshot) {
text = ` ${config.externalUrl}/i/${spot.screenshot}`
Expand Down
4 changes: 2 additions & 2 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) &&
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions views/pages/comandos.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
</thead>
<tbody>
<tr>
<th scope="row">!activo 2 o !activar 2</th>
<th scope="row">!activo 2</th>
<td>Poner el punto X en activo para que cualquier viewer pueda hacer una !foto, luego se desactiva y se guarda o sobreescribe la foto para ese punto. También se marca com visto.</td>
</tr>
<tr>
<th scope="row">!desactivar</th>
<td>Desactiva un punto activo, és lo mismo que !activo 0. Útil si activamos un punto por error o ya no se quiere sacar !foto.</td>
<td>Desactiva si hay un punto activo. Útil si activamos un punto por error o ya no se quiere sacar !foto.</td>
</tr>
<tr>
<th scope="row">!visto 2</th>
Expand Down
4 changes: 4 additions & 0 deletions views/pages/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</head>
<body>
<h3>Temps de Flors '24 - <a href="https://twitch.tv/<%= channel %>" target="_blank"><%= channel %></a></h3>
<span></span>
<div class="progress">
<div class="progress-bar <%= bgClass %>" role="progressbar" style="width: <%= percentage %>%;" aria-valuenow="<%= percentage %>" aria-valuemin="0" aria-valuemax="100"><%= spots.filter((s) => s.visited).length %>/<%= spots.length %></div>
</div>
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#"><strong>Listado</strong></a>
Expand Down

0 comments on commit d8ce131

Please sign in to comment.