Fix Stations class bug

This commit is contained in:
Christer Warén 2021-09-17 23:14:24 +03:00
parent 0f5022df15
commit dc7b14b11a
2 changed files with 13 additions and 9 deletions

View File

@ -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');

View File

@ -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);