diff --git a/handlers/events.js b/handlers/events.js index 6416cba..70179af 100644 --- a/handlers/events.js +++ b/handlers/events.js @@ -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') + } } } diff --git a/lib/inputParser.js b/lib/inputParser.js index 437c75a..b5c98d5 100644 --- a/lib/inputParser.js +++ b/lib/inputParser.js @@ -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 diff --git a/lib/messenger.js b/lib/messenger.js index 2689403..723be09 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -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) { diff --git a/lib/notifier.js b/lib/notifier.js index 38c29bc..f6538b8 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -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() diff --git a/services/twitch.js b/services/twitch.js index 5c380fd..5c41e1d 100644 --- a/services/twitch.js +++ b/services/twitch.js @@ -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) } } @@ -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' } } }