mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-07-01 10:23:37 +00:00
Added statistics command and datastore for statistics
This commit is contained in:
@ -38,14 +38,27 @@ module.exports = {
|
||||
const sstation = await searchStation(args.slice(1).join(' '), client);
|
||||
if (!sstation) return msg.channel.send(client.messageEmojis["x"] + client.messages.noSearchResults);
|
||||
url = sstation.stream[sstation.stream.default];
|
||||
station = sstation
|
||||
station = sstation;
|
||||
}
|
||||
|
||||
if (radio) {
|
||||
|
||||
if(!radio.currentGuild.statistics[radio.station.name]){
|
||||
radio.currentGuild.statistics[radio.station.name] = {};
|
||||
radio.currentGuild.statistics[radio.station.name].time = 0;
|
||||
radio.currentGuild.statistics[radio.station.name].used = 0;
|
||||
client.datastore.updateEntry(msg.guild, radio.currentGuild);
|
||||
}
|
||||
|
||||
radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.connection.dispatcher.streamTime.toFixed(0));
|
||||
radio.currentGuild.statistics[radio.station.name].used = parseInt(radio.currentGuild.statistics[radio.station.name].used)+1;
|
||||
client.datastore.updateEntry(msg.guild, radio.currentGuild);
|
||||
|
||||
radio.connection.dispatcher.destroy();
|
||||
radio.station = station;
|
||||
radio.textChannel = msg.channel;
|
||||
play(msg.guild, client, url);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -62,6 +75,17 @@ module.exports = {
|
||||
const connection = await voiceChannel.join();
|
||||
construct.connection = connection;
|
||||
play(msg.guild, client, url);
|
||||
|
||||
client.datastore.checkEntry(msg.guild.id);
|
||||
construct.currentGuild = client.datastore.getEntry(msg.guild.id);
|
||||
|
||||
if(!construct.currentGuild.statistics[construct.station.name]){
|
||||
construct.currentGuild.statistics[construct.station.name] = {};
|
||||
construct.currentGuild.statistics[construct.station.name].time = 0;
|
||||
construct.currentGuild.statistics[construct.station.name].used = 0;
|
||||
client.datastore.updateEntry(msg.guild, construct.currentGuild);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
client.radio.delete(msg.guild.id);
|
||||
return msg.channel.send(client.messageEmojis["x"] + `An error occured: ${error}`);
|
||||
|
59
commands/statistics.js
Normal file
59
commands/statistics.js
Normal file
@ -0,0 +1,59 @@
|
||||
module.exports = {
|
||||
name: 'statistics',
|
||||
alias: 'stats',
|
||||
usage: '',
|
||||
description: 'Show usage statistics.',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
execute(msg, args, client, Discord, command) {
|
||||
let stations = client.stations;
|
||||
let currentGuildStatistics = client.datastore.getEntry(msg.guild.id).statistics;
|
||||
let statistics;
|
||||
let i = 0;
|
||||
|
||||
Object.keys(client.stations).forEach(function(station) {
|
||||
if(currentGuildStatistics[stations[station].name]){
|
||||
if(i > 0){
|
||||
statistics += "**" + station + " " + stations[station].name + "** \n";
|
||||
statistics += "Time: " + msToTime(currentGuildStatistics[stations[station].name].time, "hh:mm:ss") + "\n";
|
||||
statistics += "Used: " + currentGuildStatistics[stations[station].name].used + "\n";
|
||||
} else {
|
||||
statistics = "**" + station + " " + stations[station].name + "** \n";
|
||||
statistics += "Time: " + msToTime(currentGuildStatistics[stations[station].name].time, "hh:mm:ss") + "\n";
|
||||
statistics += "Used: " + currentGuildStatistics[stations[station].name].used + "\n";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
if(!statistics){
|
||||
statistics = "You have not listened any radio station";
|
||||
}
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(client.messages.statisticsTitle)
|
||||
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, ''))
|
||||
.setColor(client.config.embedColor)
|
||||
.setDescription(statistics)
|
||||
.setFooter('EximiaBots by Warén Media', "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
||||
return msg.channel.send(embed);
|
||||
}
|
||||
};
|
||||
|
||||
function msToTime(duration, format) {
|
||||
var seconds = Math.floor((duration / 1000) % 60),
|
||||
minutes = Math.floor((duration / (1000 * 60)) % 60),
|
||||
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
|
||||
days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24);
|
||||
|
||||
days = (days < 10) ? "0" + days : days;
|
||||
hours = (hours < 10) ? "0" + hours : hours;
|
||||
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
||||
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
||||
|
||||
if (format === "hh:mm:ss") {
|
||||
return `${hours}:${minutes}:${seconds}`;
|
||||
} else if (format === "dd:hh:mm:ss") {
|
||||
return `${days}:${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
}
|
@ -8,6 +8,21 @@ module.exports = {
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const radio = client.radio.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
|
||||
client.datastore.checkEntry(msg.guild.id);
|
||||
radio.currentGuild = client.datastore.getEntry(msg.guild.id);
|
||||
if(!radio.currentGuild.statistics[radio.station.name]){
|
||||
radio.currentGuild.statistics[radio.station.name] = {};
|
||||
radio.currentGuild.statistics[radio.station.name].time = 0;
|
||||
radio.currentGuild.statistics[radio.station.name].used = 0;
|
||||
client.datastore.updateEntry(msg.guild, radio.currentGuild);
|
||||
}
|
||||
|
||||
radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.connection.dispatcher.streamTime.toFixed(0));
|
||||
radio.currentGuild.statistics[radio.station.name].used = parseInt(radio.currentGuild.statistics[radio.station.name].used)+1;
|
||||
client.datastore.updateEntry(msg.guild, radio.currentGuild);
|
||||
|
||||
|
||||
radio.connection.dispatcher.destroy();
|
||||
radio.voiceChannel.leave();
|
||||
client.radio.delete(msg.guild.id);
|
||||
|
Reference in New Issue
Block a user