From acc7ab1727f80b6127854056e5161eb42b318598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Thu, 16 Sep 2021 04:52:41 +0300 Subject: [PATCH] Update ready event --- src/client/events/ready.js | 50 +++++++++++++------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/src/client/events/ready.js b/src/client/events/ready.js index 6cbd876..368e60b 100644 --- a/src/client/events/ready.js +++ b/src/client/events/ready.js @@ -1,8 +1,8 @@ import Datastore from "../classes/Datastore.js"; import Radio from "../classes/Radio.js"; +import Stations from "../classes/Stations.js"; import Streamer from "../classes/Streamer.js"; -const _importDynamic = new Function('modulePath', 'return import(modulePath)'); -const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args)); +import Statistics from "../classes/Statistics.js"; module.exports = { name: 'ready', @@ -39,42 +39,22 @@ module.exports = { console.log("\n"); /*STATIONS*/ - try { - client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl); - client.stations = await fetch(client.config.stationslistUrl) - .then(client.funcs.checkFetchStatus) - .then(response => response.json()); + client.stations = new Stations(); - client.funcs.logger('Stations'); - client.stations.forEach(station => { - console.log("- " + station.name); - }); - console.log("\n"); - - client.funcs.logger('Stations', 'Successfully fetched list'); - } catch (error) { - client.funcs.logger('Stations', 'Fetching list failed'); - console.error(error + "\n"); - } + await client.stations.fetch({ + url: client.config.stationslistUrl + }); setInterval(async () => { - try { - client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl); - client.stations = await fetch(client.config.stationslistUrl) - .then(client.funcs.checkFetchStatus) - .then(response => response.json()); - - client.funcs.logger('Stations', 'Successfully fetched list'); - } catch (error) { - client.funcs.logger('Stations', 'Fetching list failed'); - //console.error(error); - } + await client.stations.fetch({ + url: client.config.stationslistUrl + }); }, 3600000); client.streamer = new Streamer(); client.streamer.init(client); - if(!client.stations) { + if(!client.stations.list) { client.user.setStatus('dnd'); } @@ -91,7 +71,8 @@ module.exports = { client.funcs.logger('Guilds', 'Successfully fetched list'); /*STATISTICS*/ - client.datastore.calculateGlobal(client); + client.statistics = new Statistics(); + client.statistics.calculateGlobal(client); /*EMOJIS*/ require(`../emojis.js`).execute(client); @@ -99,13 +80,16 @@ module.exports = { /*COMMANDS*/ require(`../commands.js`).execute(client); + /*RADIO*/ + client.radio = new Radio(); + setTimeout(function () { /*RESTORE RADIOS*/ - client.funcs.restoreRadios(client, guilds); + client.radio.restore(client, guilds); }, 5000); setTimeout(function () { - if(client.stations) { + if(client.stations.list) { /*MAINTENANCE MODE*/ client.funcs.logger("Maintenance Mode", "Disabled"); client.config.maintenanceMode = false;