Skip to content

Commit

Permalink
add status uptime page
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Mar 24, 2024
1 parent 5db7593 commit 62be559
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main_twitch-mz-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'))
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions handlers/generic.js
Original file line number Diff line number Diff line change
@@ -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`)
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/inputParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class InputParser {
isAskingForAddBirthday (text) {
return text.toLowerCase().startsWith('!micumple')
}

isAskingForServerStatus (text) {
return text.toLowerCase().startsWith('!status')
}
}

module.exports = InputParser
4 changes: 4 additions & 0 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 62be559

Please sign in to comment.