mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-22 22:13:16 +00:00
Added calculateGlobal function to datastore and if playlist doesnt exist then bot's status is dnd.
This commit is contained in:
parent
76506e8c7c
commit
ac6cdf9f2f
@ -23,6 +23,47 @@ module.exports = class {
|
||||
//console.log("");
|
||||
}
|
||||
|
||||
calculateGlobal(client){
|
||||
let guilds = this.map.keys();
|
||||
let stations = client.stations;
|
||||
let statistics = {};
|
||||
|
||||
if(!client.stations) return;
|
||||
|
||||
let calculation = guilds.next();
|
||||
|
||||
while (!calculation.done) {
|
||||
let currentGuild = this.getEntry(calculation.value);
|
||||
if(calculation.value == 'global'){
|
||||
return calculation = guilds.next();
|
||||
}
|
||||
|
||||
if(stations){
|
||||
Object.keys(stations).forEach(function(station) {
|
||||
if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && !parseInt(currentGuild.statistics[stations[station].name].time) == 0 && currentGuild.statistics[stations[station].name].used && !parseInt(currentGuild.statistics[stations[station].name].used) == 0){
|
||||
if(!statistics[stations[station].name]){
|
||||
statistics[stations[station].name] = {};
|
||||
statistics[stations[station].name].time = 0;
|
||||
statistics[stations[station].name].used = 0;
|
||||
}
|
||||
|
||||
statistics[stations[station].name].time = parseInt(statistics[stations[station].name].time)+parseInt(currentGuild.statistics[stations[station].name].time);
|
||||
statistics[stations[station].name].used = parseInt(statistics[stations[station].name].used)+parseInt(currentGuild.statistics[stations[station].name].used);
|
||||
}
|
||||
});
|
||||
}
|
||||
calculation = guilds.next();
|
||||
}
|
||||
|
||||
let newData = {};
|
||||
newData.guild = {};
|
||||
newData.guild.id = "global";
|
||||
newData.guild.name = "global";
|
||||
newData.statistics = statistics;
|
||||
this.updateEntry(newData.guild, newData);
|
||||
}
|
||||
|
||||
|
||||
checkEntry(id){
|
||||
if(!this.map.has(id)){
|
||||
this.createEntry(id);
|
||||
|
@ -23,7 +23,6 @@ module.exports = {
|
||||
client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json')
|
||||
.then(res => res.json());
|
||||
} catch (err) {
|
||||
client.stations = null;
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
@ -32,6 +31,12 @@ module.exports = {
|
||||
.then(res => res.json());
|
||||
}, 3600000);
|
||||
|
||||
if(!client.stations) {
|
||||
client.user.setStatus('dnd');
|
||||
}
|
||||
|
||||
client.datastore.calculateGlobal(client);
|
||||
require(`../emojis.js`).execute(client);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user