Update ready event

This commit is contained in:
Christer Warén 2021-09-16 04:52:41 +03:00
parent c7ddc6ec5b
commit acc7ab1727

View File

@ -1,8 +1,8 @@
import Datastore from "../classes/Datastore.js"; import Datastore from "../classes/Datastore.js";
import Radio from "../classes/Radio.js"; import Radio from "../classes/Radio.js";
import Stations from "../classes/Stations.js";
import Streamer from "../classes/Streamer.js"; import Streamer from "../classes/Streamer.js";
const _importDynamic = new Function('modulePath', 'return import(modulePath)'); import Statistics from "../classes/Statistics.js";
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
module.exports = { module.exports = {
name: 'ready', name: 'ready',
@ -39,42 +39,22 @@ module.exports = {
console.log("\n"); console.log("\n");
/*STATIONS*/ /*STATIONS*/
try { client.stations = new Stations();
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'); await client.stations.fetch({
client.stations.forEach(station => { url: client.config.stationslistUrl
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");
}
setInterval(async () => { setInterval(async () => {
try { await client.stations.fetch({
client.funcs.logger('Stations', 'Started fetching list ' + client.config.stationslistUrl); url: 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);
}
}, 3600000); }, 3600000);
client.streamer = new Streamer(); client.streamer = new Streamer();
client.streamer.init(client); client.streamer.init(client);
if(!client.stations) { if(!client.stations.list) {
client.user.setStatus('dnd'); client.user.setStatus('dnd');
} }
@ -91,7 +71,8 @@ module.exports = {
client.funcs.logger('Guilds', 'Successfully fetched list'); client.funcs.logger('Guilds', 'Successfully fetched list');
/*STATISTICS*/ /*STATISTICS*/
client.datastore.calculateGlobal(client); client.statistics = new Statistics();
client.statistics.calculateGlobal(client);
/*EMOJIS*/ /*EMOJIS*/
require(`../emojis.js`).execute(client); require(`../emojis.js`).execute(client);
@ -99,13 +80,16 @@ module.exports = {
/*COMMANDS*/ /*COMMANDS*/
require(`../commands.js`).execute(client); require(`../commands.js`).execute(client);
/*RADIO*/
client.radio = new Radio();
setTimeout(function () { setTimeout(function () {
/*RESTORE RADIOS*/ /*RESTORE RADIOS*/
client.funcs.restoreRadios(client, guilds); client.radio.restore(client, guilds);
}, 5000); }, 5000);
setTimeout(function () { setTimeout(function () {
if(client.stations) { if(client.stations.list) {
/*MAINTENANCE MODE*/ /*MAINTENANCE MODE*/
client.funcs.logger("Maintenance Mode", "Disabled"); client.funcs.logger("Maintenance Mode", "Disabled");
client.config.maintenanceMode = false; client.config.maintenanceMode = false;