mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-11-14 16:20:20 +00:00
Fix Stations class
This commit is contained in:
parent
24a6e80f26
commit
cbae9ae38f
@ -10,11 +10,9 @@ export interface station {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class Stations extends Array {
|
export default class Stations extends Array {
|
||||||
counter: number;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.counter = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch(options: { url: string, show?: boolean}){
|
async fetch(options: { url: string, show?: boolean}){
|
||||||
@ -26,19 +24,18 @@ export default class Stations extends Array {
|
|||||||
|
|
||||||
if(!stations) return;
|
if(!stations) return;
|
||||||
for (const station of stations){
|
for (const station of stations){
|
||||||
this.push(station.name);
|
this.push(station);
|
||||||
if(options.show) logger('Stations', station.name);
|
if(options.show) logger('Stations', station.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.counter = 0;
|
|
||||||
|
|
||||||
logger('Stations', 'Successfully fetched list');
|
logger('Stations', 'Successfully fetched list');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger('Stations', 'Fetching list failed');
|
logger('Stations', 'Fetching list failed');
|
||||||
console.error(error + "\n");
|
console.error(error + "\n");
|
||||||
|
|
||||||
this.counter = this.counter + 1;
|
if(this.length == 0) setTimeout( () => {
|
||||||
if(this.length == 0 && 5 < this.counter) this.fetch(options);
|
this.fetch(options)
|
||||||
|
}, 150 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +54,10 @@ export default class Stations extends Array {
|
|||||||
|
|
||||||
if(type == "direct"){
|
if(type == "direct"){
|
||||||
let foundStation;
|
let foundStation;
|
||||||
this.forEach(station => {
|
for(const station of this){
|
||||||
if(station.name != key) return false;
|
if(station.name != key) return false;
|
||||||
foundStation = station;
|
foundStation = station;
|
||||||
});
|
}
|
||||||
|
|
||||||
return foundStation;
|
return foundStation;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user