Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Mar 6, 2024
1 parent d60f21c commit 200cf65
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ TWITCH_CLIENT_SECRET //twitch client secret from you chatbot app
TWITCH_CHANNELS //channels to automatically join separated by comma
TWITCH_USER_ID //twitch user id (https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/)
MONGODB_URI //mongoodb uri for the access/refresh tokens.
AEMET_API_KEY //aemet api key to get spanish weather (https://opendata.aemet.es/centrodedescargas/inicio)
SQL_CONNECTION //sql connection string for the train information
AEMET_API_KEY //aemet api key to get spanish weather (https://opendata.aemet.es/centrodedescargas/inicio)
PORT //port of the running app
TELEGRAM_TOKEN //Telegram bot API token to send notifications
TELEGRAM_CHAT_ID //Telegram chat id to send the notifications
EXTERNAL_URL //external url of the running app to create the public image urls
BROWSERLESS_URL //browserless websocket url to take screenshots
MYSQL_HOST //mysql host ip/domain
MYSQL_USER //mysql user
MYSQL_PASSWORD //mysql password
MYSQL_DB //mysql database
```

## Weather
Expand Down
4 changes: 0 additions & 4 deletions handlers/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ class Stream {
const msg = await telegramBot.sendMessage(config.telegram.chatId, text, options)
await telegramBot.pinChatMessage(config.telegram.chatId, msg.message_id).catch((err) => { console.error(`cannot pin chat: ${err}`)})
await TwitchService.saveLastMessage(msg)
await TwitchService.saveTitle(result.title)

await BrowserService.startAndWarmUpBrowserIfNeeded().catch(() => { console.error('startAndWarmUpBrowserIfNeeded on live')})
} else if (result && result.type === 'finished' && result.messageId) {
await telegramBot.unpinChatMessage(config.telegram.chatId, {message_id: result.messageId}).catch((err) => { console.error(`cannot unpin chat: ${err}`)})
await telegramBot.deleteMessage(config.telegram.chatId, result.messageId)
await TwitchService.deleteLastMessage()
await this._sendStreamScreenshots(telegramBot, result.streamId)
await BrowserService.closeBrowser().catch(() => { console.error('closeBrowser on finished')})
} else if (result && result.type === 'stillLive' && result.messageId && (result.lastTitle !== result.title || (result.lastUpdate && moment().diff(moment(result.lastUpdate)) > 300000))) {
Expand All @@ -57,7 +54,6 @@ class Stream {
parse_mode: 'Markdown'
}
await telegramBot.editMessageText(this._getText(result), options).catch(() => {})
await TwitchService.saveTitle(result.title)
await BrowserService.startAndWarmUpBrowserIfNeeded().catch(() => { console.error('startAndWarmUpBrowserIfNeeded on stillLive')})
} else if (result && result.type === 'notLive') {
await BrowserService.closeBrowserIfNeeded().catch(() => { console.error('closeBrowserIfNeeded on notLive')})
Expand Down
16 changes: 3 additions & 13 deletions services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ async function getStream() {

const channel = await dbManager.getChannel(config.twitch.channels).lean()
if (liveData && !channel.live) {
await dbManager.updateChannel(config.twitch.channels, { live: true, streamId: liveData.id })
await dbManager.updateChannel(config.twitch.channels, { live: true, streamId: liveData.id, title: liveData.title })
result = liveData
} else if (!liveData && channel.live) {
await dbManager.updateChannel(config.twitch.channels, { live: false, streamId: null })
await dbManager.updateChannel(config.twitch.channels, { live: false, streamId: null, lastMessageId: null })
result = { type: 'finished', messageId: channel.lastMessageId, streamId: channel.streamId}
} else if (liveData && channel.live) {
await dbManager.updateChannel(config.twitch.channels, { streamId: liveData.id })
await dbManager.updateChannel(config.twitch.channels, { streamId: liveData.id, title: liveData.title })
result = { ...liveData, type: 'stillLive', messageId: channel.lastMessageId, lastTitle: channel.title}
}

Expand All @@ -48,19 +48,9 @@ async function saveLastMessage (msg) {
await dbManager.updateChannel(config.twitch.channels, { lastMessageId: msg.message_id })
}

async function deleteLastMessage () {
await dbManager.updateChannel(config.twitch.channels, { lastMessageId: null })
}

async function saveTitle (title) {
await dbManager.updateChannel(config.twitch.channels, { title: title })
}


module.exports = {
getStream,
saveLastMessage,
deleteLastMessage,
saveTitle,
getChannel
}

0 comments on commit 200cf65

Please sign in to comment.