From 45609381cce70b85ee67e05dd17f73cc22a0b379 Mon Sep 17 00:00:00 2001 From: Lluis Date: Wed, 31 Jan 2024 23:33:55 +0100 Subject: [PATCH] clean up and readme file update --- README.md | 37 +++++++++++++++++++++++++++++++++++++ handlers/generic.js | 1 - handlers/train.js | 3 +-- handlers/weather.js | 4 +--- helpers/sqlManager.js | 8 +------- lib/messenger.js | 3 --- services/aemet.js | 1 - 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 151eb07..e86abba 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/handlers/generic.js b/handlers/generic.js index e9c043d..a1690a3 100644 --- a/handlers/generic.js +++ b/handlers/generic.js @@ -8,7 +8,6 @@ class Generic { const sides = 6; return Math.floor(Math.random() * sides) + 1; } - } module.exports = Generic diff --git a/handlers/train.js b/handlers/train.js index af71482..bede8f3 100644 --- a/handlers/train.js +++ b/handlers/train.js @@ -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 \ No newline at end of file diff --git a/handlers/weather.js b/handlers/weather.js index 78ff49d..9fa0067 100644 --- a/handlers/weather.js +++ b/handlers/weather.js @@ -11,8 +11,6 @@ class Weather { bot.say(target, `${municipio.nombre} atardece a las ${ocaso}`); } } - - } -module.exports = Weather +module.exports = Weather \ No newline at end of file diff --git a/helpers/sqlManager.js b/helpers/sqlManager.js index f92ec1d..2f04f4e 100644 --- a/helpers/sqlManager.js +++ b/helpers/sqlManager.js @@ -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) @@ -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 = { diff --git a/lib/messenger.js b/lib/messenger.js index 72141eb..9d90029 100644 --- a/lib/messenger.js +++ b/lib/messenger.js @@ -7,7 +7,6 @@ const tmi = require('@twurple/auth-tmi') const { RefreshingAuthProvider } = require('@twurple/auth') const TokenService = require("../services/token"); - class Messenger { constructor () {} @@ -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) @@ -75,5 +73,4 @@ class Messenger { } } - module.exports = Messenger diff --git a/services/aemet.js b/services/aemet.js index fee14a3..0e3d267 100644 --- a/services/aemet.js +++ b/services/aemet.js @@ -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()