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 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);
await client.stations.fetch({
url: client.config.stationslistUrl
});
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 () => {
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;