From 76506e8c7c80b152a4370343f0bd8c4c6f4e459a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 4 Apr 2020 06:50:37 +0300 Subject: [PATCH] Made changes to statistics command --- client/commands/statistics.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/client/commands/statistics.js b/client/commands/statistics.js index d413247..e849b0a 100644 --- a/client/commands/statistics.js +++ b/client/commands/statistics.js @@ -6,27 +6,24 @@ module.exports = { permission: 'none', category: 'info', execute(msg, args, client, Discord, command) { + let message = {}; let stations = client.stations; let currentGuild = client.datastore.getEntry(msg.guild.id); - let statistics; - let i = 0; + let statistics = ""; + if(!client.stations) { + message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); + return msg.channel.send(client.messageEmojis["error"] + message.errorToGetPlaylist); + } + if(!currentGuild || currentGuild && !currentGuild.statistics){ statistics = "You have not listened any radio station"; } else { - Object.keys(client.stations).forEach(function(station) { - if(currentGuild.statistics[stations[station].name]){ - if(i > 0){ - statistics += `**${parseInt(station) + 1}** ` + stations[station].name + " \n"; - statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time, "hh:mm:ss") + "\n"; - statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n"; - } else { - statistics = `**${parseInt(station) + 1}** ` + stations[station].name + " \n"; - statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time, "hh:mm:ss") + "\n"; - statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n"; - } - - i++; + 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){ + statistics += `**${parseInt(station) + 1}** ` + stations[station].name + " \n"; + statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time, "hh:mm:ss") + "\n"; + statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n"; } }); }