From 07c58104d48e3ec7c0ca3076998118c04fd6ea5c Mon Sep 17 00:00:00 2001 From: Peber Date: Sat, 28 Dec 2024 15:31:17 -0500 Subject: [PATCH 1/4] updating the initial sync and healthchecks --- src/commands.js | 9 ++------ .../{utility => events}/archive_event.js | 0 .../{utility => events}/create_event.js | 0 .../{utility => events}/get_all_events.js | 0 src/commands/{utility => events}/get_event.js | 0 .../{utility => events}/update_event.js | 0 .../{utility => strava}/connect_strava.js | 0 .../{utility => strava}/get_all_bikes.js | 0 .../{utility => strava}/get_bike_by_name.js | 0 .../{utility => strava}/get_last_ride.js | 0 .../{utility => strava}/i_waxed_my_chain.js | 0 .../{utility => strava}/sync_bikes.js | 0 src/strava_webhook.js | 22 ++++++++++++++++--- 13 files changed, 21 insertions(+), 10 deletions(-) rename src/commands/{utility => events}/archive_event.js (100%) rename src/commands/{utility => events}/create_event.js (100%) rename src/commands/{utility => events}/get_all_events.js (100%) rename src/commands/{utility => events}/get_event.js (100%) rename src/commands/{utility => events}/update_event.js (100%) rename src/commands/{utility => strava}/connect_strava.js (100%) rename src/commands/{utility => strava}/get_all_bikes.js (100%) rename src/commands/{utility => strava}/get_bike_by_name.js (100%) rename src/commands/{utility => strava}/get_last_ride.js (100%) rename src/commands/{utility => strava}/i_waxed_my_chain.js (100%) rename src/commands/{utility => strava}/sync_bikes.js (100%) diff --git a/src/commands.js b/src/commands.js index 3503b9f..b524854 100644 --- a/src/commands.js +++ b/src/commands.js @@ -46,17 +46,12 @@ const rest = new REST().setToken(discordToken); (async () => { try { console.log(`Started refreshing ${commands.length} application (/) commands.`); - // The put method is used to fully refresh all commands in the guild with the current set - const data = await rest.put( - Routes.applicationGuildCommands(appId, guildId), - { body: commands }, - ); - await rest.put( + const data = await rest.put( Routes.applicationCommands(appId), { body: commands }, ); - console.log(`Successfully reloaded ${data.length} application (/) commands.`); + console.log(`Successfully reloaded ${data.length} application (/) commands.`); } catch (error) { // And of course, make sure you catch and log any errors! console.error(error); diff --git a/src/commands/utility/archive_event.js b/src/commands/events/archive_event.js similarity index 100% rename from src/commands/utility/archive_event.js rename to src/commands/events/archive_event.js diff --git a/src/commands/utility/create_event.js b/src/commands/events/create_event.js similarity index 100% rename from src/commands/utility/create_event.js rename to src/commands/events/create_event.js diff --git a/src/commands/utility/get_all_events.js b/src/commands/events/get_all_events.js similarity index 100% rename from src/commands/utility/get_all_events.js rename to src/commands/events/get_all_events.js diff --git a/src/commands/utility/get_event.js b/src/commands/events/get_event.js similarity index 100% rename from src/commands/utility/get_event.js rename to src/commands/events/get_event.js diff --git a/src/commands/utility/update_event.js b/src/commands/events/update_event.js similarity index 100% rename from src/commands/utility/update_event.js rename to src/commands/events/update_event.js diff --git a/src/commands/utility/connect_strava.js b/src/commands/strava/connect_strava.js similarity index 100% rename from src/commands/utility/connect_strava.js rename to src/commands/strava/connect_strava.js diff --git a/src/commands/utility/get_all_bikes.js b/src/commands/strava/get_all_bikes.js similarity index 100% rename from src/commands/utility/get_all_bikes.js rename to src/commands/strava/get_all_bikes.js diff --git a/src/commands/utility/get_bike_by_name.js b/src/commands/strava/get_bike_by_name.js similarity index 100% rename from src/commands/utility/get_bike_by_name.js rename to src/commands/strava/get_bike_by_name.js diff --git a/src/commands/utility/get_last_ride.js b/src/commands/strava/get_last_ride.js similarity index 100% rename from src/commands/utility/get_last_ride.js rename to src/commands/strava/get_last_ride.js diff --git a/src/commands/utility/i_waxed_my_chain.js b/src/commands/strava/i_waxed_my_chain.js similarity index 100% rename from src/commands/utility/i_waxed_my_chain.js rename to src/commands/strava/i_waxed_my_chain.js diff --git a/src/commands/utility/sync_bikes.js b/src/commands/strava/sync_bikes.js similarity index 100% rename from src/commands/utility/sync_bikes.js rename to src/commands/strava/sync_bikes.js diff --git a/src/strava_webhook.js b/src/strava_webhook.js index aeb3ea9..ae00cfa 100644 --- a/src/strava_webhook.js +++ b/src/strava_webhook.js @@ -7,9 +7,22 @@ const fs = require('node:fs'); const { firstTimeAuth, getStravaAuthentication } = require('./shared_library/strava_authentication.js'); const app = express(); app.use(express.json()); -const discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); +require('dotenv').config() +let discordToken; + +if (process.env.NODE_ENV === 'production') { + discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); +} else { + discordToken = process.env.discordToken; +} + client.login(discordToken); +app.get('/', (req, res) => { + // send a 200 response to the root path + res.sendStatus(200); +}); + app.post('/webhook', async (req, res) => { console.log("webhook event received!", req.body); // get the object_id and owner id @@ -107,13 +120,16 @@ async function setupBikes(athleteId, userId, strava_access_token) { // get the athlete page // Fetch details for each bike from Strava's /gear endpoint and update the database for (const bike of athleteResponse.data.bikes) { + const bikeData = await axios.get(`https://www.strava.com/api/v3/gear/${bike.id}`, { + headers: { Authorization: `Bearer ${strava_access_token}` } + }); // Update the database with the bike details await BikesTable.upsert({ bikeId: bike.id, userId: userId, name: bike.name, - brand: bike.brand_name, - model: bike.model_name, + brand: bikeData.data.brand_name, + model: bikeData.data.model_name, distance: bike.distance }); } From 2cf47c47952ea49b9ef471e8bf1645bec7659214 Mon Sep 17 00:00:00 2001 From: "GitHub-Actions[bot]" Date: Sat, 28 Dec 2024 20:37:44 +0000 Subject: [PATCH 2/4] Bot: Updating CHANGELOG, README and package.json for release based on #25 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8908963..a8a3e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +### Version 1.1.0 + +#### bugfix +* PR [#25](https://github.com/petercort/FBF-Buddy/pull/25) - updating the initial sync and healthchecks + + + ### Version 1.0.2 #### bugfix diff --git a/package.json b/package.json index 661ab11..83c7a36 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fbf-event-buddy", "private": true, - "version": "1.0.2", + "version": "1.1.0", "description": "Cycling event app for Discord", "main": "app.js", "engines": { From 5876cad197319df15e3e913fd3aeb843645c8353 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 28 Dec 2024 15:51:41 -0500 Subject: [PATCH 3/4] Update app.version --- app.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.version b/app.version index 21e8796..6d7de6e 100644 --- a/app.version +++ b/app.version @@ -1 +1 @@ -1.0.3 +1.0.2 From 571c10208b3b286da7c4776e3e4c201abe14e789 Mon Sep 17 00:00:00 2001 From: "GitHub-Actions[bot]" Date: Sat, 28 Dec 2024 20:52:05 +0000 Subject: [PATCH 4/4] Bot: Updating CHANGELOG, README, app.version and package.json for release based on #25 --- app.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.version b/app.version index 6d7de6e..9084fa2 100644 --- a/app.version +++ b/app.version @@ -1 +1 @@ -1.0.2 +1.1.0