mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-23 05:13:17 +00:00
Update Stations class
This commit is contained in:
parent
dbedb83104
commit
ccb386e3b3
@ -1,9 +1,8 @@
|
|||||||
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
||||||
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||||
|
|
||||||
module.exports = class {
|
module.exports = class Stations extends Array {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.list = new Array();
|
|
||||||
this.logger = require("../funcs/logger.js");
|
this.logger = require("../funcs/logger.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,15 +13,16 @@ module.exports = class {
|
|||||||
.then(this.checkFetchStatus)
|
.then(this.checkFetchStatus)
|
||||||
.then(response => response.json());
|
.then(response => response.json());
|
||||||
|
|
||||||
if(!this.list){
|
if(list){
|
||||||
this.logger('Stations');
|
this.logger('Stations');
|
||||||
this.list.forEach(station => {
|
list.forEach(station => {
|
||||||
console.log("- " + station.name);
|
console.log("- " + station.name);
|
||||||
});
|
});
|
||||||
console.log("\n");
|
console.log("\n");
|
||||||
|
|
||||||
|
this = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.list = list;
|
|
||||||
this.logger('Stations', 'Successfully fetched list');
|
this.logger('Stations', 'Successfully fetched list');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger('Stations', 'Fetching list failed');
|
this.logger('Stations', 'Fetching list failed');
|
||||||
@ -41,12 +41,12 @@ module.exports = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search(key) {
|
search(key) {
|
||||||
if (this.list === null) return false;
|
if (this === null) return false;
|
||||||
let foundStations = [];
|
let foundStations = [];
|
||||||
if (!key) return false;
|
if (!key) return false;
|
||||||
if (key == "radio") return false;
|
if (key == "radio") return false;
|
||||||
|
|
||||||
this.list
|
this
|
||||||
.filter(
|
.filter(
|
||||||
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
|
x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key
|
||||||
)
|
)
|
||||||
@ -57,7 +57,7 @@ module.exports = class {
|
|||||||
if (key.startsWith("radio ")) key = key.slice(6);
|
if (key.startsWith("radio ")) key = key.slice(6);
|
||||||
const probabilityIncrement = 100 / key.split(" ").length / 2;
|
const probabilityIncrement = 100 / key.split(" ").length / 2;
|
||||||
for (let i = 0; i < key.split(" ").length; i++) {
|
for (let i = 0; i < key.split(" ").length; i++) {
|
||||||
this.list
|
this
|
||||||
.filter(
|
.filter(
|
||||||
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
|
x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user