Skip to content

Commit

Permalink
add event tarraco manga
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Jul 9, 2024
1 parent 3dd9d6d commit 6af27e0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions handlers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ config = require("../config")
const TwitchService = require('../services/twitch')

class Events {
async sendEvents() {
async sendTarracoMangaEvent() {
if (config.twitch.channels.startsWith('m')) {
await TwitchService.sendAnnouncement(`28 y 29 de septiembre quedada en la Tarraco Manga`, 'orange')
}
await TwitchService.sendAnnouncement(`¡28 y 29 de septiembre quedada en la Tarraco Manga con followers!`, 'orange')
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class InputParser {
isAskingForTFSpotsCount (text) {
return text.toLowerCase().startsWith('!puntos') || text.toLowerCase().startsWith('!flores')
}

isAskingForTarracoMangaEvent (text) {
const words = ['tarraco', 'tarracomanga', 'tarragona']
return words.some(word => text.toLowerCase().startsWith(`!${word}`))
}
}

module.exports = InputParser
4 changes: 4 additions & 0 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ class Messenger {
return handlers.stream.captureScreenshot(target, this.bot, this.notifier.bot, context['display-name'], context['room-id'])
}
}

if (textSplit.length > 0 && inputParser.isAskingForTarracoMangaEvent(textSplit[0])){
return handlers.events.sendTarracoMangaEvent()
}
}

handleHosting (channel, target, viewers) {
Expand Down
2 changes: 1 addition & 1 deletion lib/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Notifier {
})

cron.schedule('0/15 * * * *', async () => {
await handlers.events.sendEvents(this.twitchBot, this.target)
await handlers.events.sendTarracoMangaEvent()
})

return Promise.resolve()
Expand Down
14 changes: 6 additions & 8 deletions services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,22 @@ async function getUnbanRequests () {
}

async function sendAnnouncement(text, color) {
let result
const options = await _getHeaders()
options.method = 'POST'
const channel = await dbManager.getChannel(config.twitch.channels).lean()
const endpoint = `${endpointPrefix}/chat/announcements?broadcaster_id=${channel.roomId}&moderator_id=${config.twitch.userId}`

const body = {
data : {
message: text,
color: color
}
message: text,
color: color
}

options.body = JSON.stringify(body)

try {
await fetch(endpoint, options)
} catch {
result = null
} catch (e) {
console.log('error sending announcement: ' + e)
}
}

Expand All @@ -96,7 +93,8 @@ async function _getHeaders () {
return {
headers: {
'Client-Id': config.twitch.clientId,
'Authorization': 'Bearer ' + token.accessToken
'Authorization': 'Bearer ' + token.accessToken,
'Content-Type': 'application/json'
}
}
}
Expand Down

0 comments on commit 6af27e0

Please sign in to comment.