From dc7b14b11acc8e06323952292dc4dab31ba773e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Fri, 17 Sep 2021 23:14:24 +0300 Subject: [PATCH] Fix Stations class bug --- src/client/classes/Stations.js | 16 +++++++++------- src/client/events/ready.js | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/client/classes/Stations.js b/src/client/classes/Stations.js index 76493f5..fdd7668 100644 --- a/src/client/classes/Stations.js +++ b/src/client/classes/Stations.js @@ -15,16 +15,18 @@ module.exports = class Stations extends Array { .then(response => response.json()); if(list){ - this.logger('Stations'); - this.forEach(oldStation => { - if(list.findIndex(station => station.name == oldStation.name)) return; - delete this[this.findIndex(station => station.name == oldStation.name)]; - }); + this.length = 0; list.forEach(station => { - console.log("- " + station.name); this.push(station); }); - console.log("\n"); + + if(options.show){ + this.logger('Stations'); + list.forEach(station => { + console.log("- " + station.name); + }); + console.log("\n"); + } } this.logger('Stations', 'Successfully fetched list'); diff --git a/src/client/events/ready.js b/src/client/events/ready.js index 8ffcd6e..ccae145 100644 --- a/src/client/events/ready.js +++ b/src/client/events/ready.js @@ -42,12 +42,14 @@ module.exports = { client.stations = new Stations(); await client.stations.fetch({ - url: client.config.stationslistUrl + url: client.config.stationslistUrl, + show: true }); setInterval(async () => { await client.stations.fetch({ - url: client.config.stationslistUrl + url: client.config.stationslistUrl, + show: false }); }, 3600000);