From 62be55965da0130ad68416b86336641016a3aa69 Mon Sep 17 00:00:00 2001 From: Lluis Date: Sun, 24 Mar 2024 23:44:24 +0100 Subject: [PATCH] add status uptime page --- .github/workflows/main_twitch-mz-bot.yml | 1 + README.md | 3 +++ app.js | 5 +++++ config/index.js | 3 ++- handlers/generic.js | 10 ++++++++-- lib/inputParser.js | 4 ++++ lib/messenger.js | 4 ++++ 7 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main_twitch-mz-bot.yml b/.github/workflows/main_twitch-mz-bot.yml index cda1167..fc68da1 100644 --- a/.github/workflows/main_twitch-mz-bot.yml +++ b/.github/workflows/main_twitch-mz-bot.yml @@ -34,6 +34,7 @@ jobs: envKey_MYSQL_USER: ${{ secrets.MYSQL_USER }} envKey_MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} envKey_MYSQL_DB: ${{ secrets.MYSQL_DB }} + envKey_STATUS_URL: ${{ secrets.STATUS_URL }} - name: Set up Node.js version uses: actions/setup-node@v4 with: diff --git a/README.md b/README.md index bdf4b97..c0953c4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A twitch chatbot to get specific information about weather predictions, train timings and other information. +Status: https://uptime.311312.xyz/status/twitch + ## environment variables ```javascript @@ -20,6 +22,7 @@ MYSQL_HOST //mysql host ip/domain MYSQL_USER //mysql user MYSQL_PASSWORD //mysql password MYSQL_DB //mysql database +STATUS_URL //uptime url for /status tiwtch chat command ``` ## Weather diff --git a/app.js b/app.js index b65f3de..445ea0f 100644 --- a/app.js +++ b/app.js @@ -14,11 +14,16 @@ mongoose.connect(config.database).then(() => { app.use(express.static('public')) app.use('/images', express.static('images')) + app.get('/status', function (req, res) { + res.redirect(config.statusUrl) + }); + app.get('/:id', (req, res) => { res.sendFile(__dirname + `/public/images/${req.params.id}.jpg`) }); + const listener = app.listen(process.env.PORT, ()=> { console.log('Listening on port ', + listener.address().port) app.get('/', (req, res) => res.send('Live!')) diff --git a/config/index.js b/config/index.js index 366fe12..b4401dc 100644 --- a/config/index.js +++ b/config/index.js @@ -20,5 +20,6 @@ module.exports = { user: process.env.MYSQL_USER, password: process.env.MYSQL_PASSWORD, db: process.env.MYSQL_DB - } + }, + statusUrl: process.env.STATUS_URL } diff --git a/handlers/generic.js b/handlers/generic.js index a1690a3..d8ef1e9 100644 --- a/handlers/generic.js +++ b/handlers/generic.js @@ -1,12 +1,18 @@ +const config = require("../config") + class Generic { rollDice (target, bot) { const num = this._rollDice(); - bot.say(target, `Ha salido el número ${num}`); + bot.say(target, `Ha salido el número ${num}`) } _rollDice () { const sides = 6; - return Math.floor(Math.random() * sides) + 1; + return Math.floor(Math.random() * sides) + 1 + } + + status (target, bot) { + bot.say(target, `${config.externalUrl}/status`) } } diff --git a/lib/inputParser.js b/lib/inputParser.js index b042e8c..e0c0e97 100644 --- a/lib/inputParser.js +++ b/lib/inputParser.js @@ -34,6 +34,10 @@ class InputParser { isAskingForAddBirthday (text) { return text.toLowerCase().startsWith('!micumple') } + + isAskingForServerStatus (text) { + return text.toLowerCase().startsWith('!status') + } } module.exports = InputParser diff --git a/lib/messenger.js b/lib/messenger.js index e76e341..61d0263 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -92,6 +92,10 @@ class Messenger { if (textSplit.length === 2 && inputParser.isAskingForGetBirthday(textSplit[0]) && !textSplit[1].includes('-')) { return handlers.birthday.getBirthday(target, textSplit[1], this.bot) } + + if (textSplit.length > 0 && inputParser.isAskingForServerStatus(textSplit[0])) { + return handlers.generic.status(target, this.bot) + } } handleHosting (channel, target, viewers) {