Skip to content

Commit

Permalink
clean up and readme file update
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Jan 31, 2024
1 parent cd468fa commit 4560938
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# twitch-mz-bot

A twitch chatbot to get specific information about weather predictions, train timings and other information.

## environment variables

```javascript
TWITCH_CLIENT_ID //twitch client id from your chatbot app (https://dev.twitch.tv/)
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
PORT //port of the running app
```

## Weather
Information from weather comes from AEMET OpenData to get Spain weather predictions.

### commands
```javascript
!atardecer girona
//result: Girona atardece a las 17:59
```

## Train
Find next departure time of the train from a given origin and destination. It uses the renfe open datasets (https://data.renfe.com/)

### commands

```javascript
!md girona figueres
```

```javascript
!ave girona sants
```
1 change: 0 additions & 1 deletion handlers/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Generic {
const sides = 6;
return Math.floor(Math.random() * sides) + 1;
}

}

module.exports = Generic
3 changes: 1 addition & 2 deletions handlers/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Train {
bot.say(target, `Próximo AVE de ${result.origin_stop} a ${result.destination_stop} sale a las ${result.time}`);
}
}

}

module.exports = Train
module.exports = Train
4 changes: 1 addition & 3 deletions handlers/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Weather {
bot.say(target, `${municipio.nombre} atardece a las ${ocaso}`);
}
}


}

module.exports = Weather
module.exports = Weather
8 changes: 1 addition & 7 deletions helpers/sqlManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const sql = require('mssql')
const config = require('../config')
const Token = require("../models/token");

async function getCloserFutureTrain (origin, destination, type) {
try {
this.pool = await sql.connect(config.sql.connectionString)
Expand Down Expand Up @@ -40,12 +38,8 @@ where CD.date = DATEADD(hour, 1, GETDATE()) )
AND A.departure_time > CONVERT (time, DATEADD(hour, 1, GETDATE()))
ORDER BY ABS( DATEDIFF(minute, A.departure_time, CONVERT (time, DATEADD(hour, 1, GETDATE()))) )`)
//const result = await sql.query
console.log(result.recordset[0])
return result.recordset[0]
} catch (err) {
console.log(err)
}
} catch (err) {}
}

module.exports = {
Expand Down
3 changes: 0 additions & 3 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const tmi = require('@twurple/auth-tmi')
const { RefreshingAuthProvider } = require('@twurple/auth')
const TokenService = require("../services/token");


class Messenger {
constructor () {}

Expand Down Expand Up @@ -53,7 +52,6 @@ class Messenger {
const text = msg.trim();
const textSplit = text.split(' ')


if (textSplit.length > 0 && inputParser.isAskingForRollDice(textSplit[0]))
return handlers.generic.rollDice(target, this.bot)

Expand All @@ -75,5 +73,4 @@ class Messenger {
}
}


module.exports = Messenger
1 change: 0 additions & 1 deletion services/aemet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async function getTimePrediction(name) {

return result[0].prediccion.dia[0].ocaso
}

async function getAemetData(url) {
const response = await fetch(url)
return await response.json()
Expand Down

0 comments on commit 4560938

Please sign in to comment.