eximiabots-radiox/src/client/commands/statistics.js

53 lines
3.3 KiB
JavaScript
Raw Normal View History

import Discord from "discord.js";
2021-09-05 19:37:26 +00:00
2021-06-08 09:01:56 +00:00
module.exports = {
name: 'statistics',
description: 'Show statistics',
2021-06-08 09:01:56 +00:00
category: 'info',
execute(interaction, client) {
2021-06-08 09:01:56 +00:00
let message = {};
let stations = client.stations;
2021-08-18 22:52:16 +00:00
let currentGuild = client.datastore.getEntry(interaction.guild.id);
2021-09-05 03:15:54 +00:00
let global = client.datastore.getEntry("global");
2021-06-08 09:01:56 +00:00
let statistics = "";
2021-09-09 09:44:50 +00:00
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply({
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
ephemeral: true
});
}
2021-06-08 09:01:56 +00:00
if(!currentGuild || currentGuild && !currentGuild.statistics){
2021-09-05 20:11:26 +00:00
statistics = "You have not listened any radio stations";
2021-06-08 09:01:56 +00:00
} else {
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){
2021-09-05 03:15:54 +00:00
statistics += `**${parseInt(station) + 1}. ` + stations[station].name + "** \n";
if(global && global.statistics[stations[station].name] && global.statistics[stations[station].name].time && parseInt(global.statistics[stations[station].name].time) > 0 && global.statistics[stations[station].name].used && parseInt(global.statistics[stations[station].name].used) > 0){
2021-09-05 20:11:26 +00:00
statistics += "Guild Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " (" + ((currentGuild.statistics[stations[station].name].time / global.statistics[stations[station].name].time) * 100).toFixed(0) + "%" + ")" + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + " (" + ((currentGuild.statistics[stations[station].name].used / global.statistics[stations[station].name].used) * 100).toFixed(0) + "%" + ")" + "\n";
2021-09-05 03:15:54 +00:00
statistics += "Global Time: " + client.funcs.msToTime(global.statistics[stations[station].name].time) + " / " + "Used: " + global.statistics[stations[station].name].used + "\n\n";
} else {
statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + "\n\n";
}
2021-06-08 09:01:56 +00:00
}
});
}
2021-09-09 09:44:50 +00:00
2021-06-08 09:01:56 +00:00
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.statisticsTitle)
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["statistics"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor)
.setDescription(statistics)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
2021-06-08 09:01:56 +00:00
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
2021-08-26 19:06:15 +00:00
interaction.reply({
embeds: [embed],
ephemeral: true
});
2021-06-08 09:01:56 +00:00
}
2021-09-09 09:44:50 +00:00
};