From 8db8115ce300128b592ac1d6b38951213406ba95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 4 Apr 2020 07:23:29 +0300 Subject: [PATCH] Unknown differences --- client/commands/maintenance.js | 32 ++-- client/commands/statistics.js | 76 +++++----- client/datastore.js | 252 +++++++++++++++---------------- client/emojis.js | 74 ++++----- client/funcs/msToTime.js | 32 ++-- client/funcs/statisticsUpdate.js | 48 +++--- client/messages.js | 70 ++++----- index.js | 2 +- 8 files changed, 293 insertions(+), 293 deletions(-) diff --git a/client/commands/maintenance.js b/client/commands/maintenance.js index 739ccea..bf9a3f0 100644 --- a/client/commands/maintenance.js +++ b/client/commands/maintenance.js @@ -1,17 +1,17 @@ -module.exports = { - name: 'maintenance', - alias: 'm', - usage: '', - description: 'Bot Maintenance', - permission: 'none', - category: 'info', - execute(msg, args, client, Discord, command) { - const embed = new Discord.MessageEmbed() - .setTitle(client.messages.maintenanceTitle) - .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) - .setDescription(client.messages.maintenanceDescription) - .setFooter('EximiaBots by Warén Media', "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - return msg.channel.send(embed); - } +module.exports = { + name: 'maintenance', + alias: 'm', + usage: '', + description: 'Bot Maintenance', + permission: 'none', + category: 'info', + execute(msg, args, client, Discord, command) { + const embed = new Discord.MessageEmbed() + .setTitle(client.messages.maintenanceTitle) + .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, '')) + .setColor(client.config.embedColor) + .setDescription(client.messages.maintenanceDescription) + .setFooter('EximiaBots by Warén Media', "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); + return msg.channel.send(embed); + } }; \ No newline at end of file diff --git a/client/commands/statistics.js b/client/commands/statistics.js index e849b0a..63b51aa 100644 --- a/client/commands/statistics.js +++ b/client/commands/statistics.js @@ -1,39 +1,39 @@ -module.exports = { - name: 'statistics', - alias: 'stats', - usage: '', - description: 'Show usage statistics.', - 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 = ""; - - 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(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"; - } - }); - } - - 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) - .setFooter('EximiaBots by Warén Media', "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - return msg.channel.send(embed); - } +module.exports = { + name: 'statistics', + alias: 'stats', + usage: '', + description: 'Show usage statistics.', + 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 = ""; + + 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(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"; + } + }); + } + + 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) + .setFooter('EximiaBots by Warén Media', "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); + return msg.channel.send(embed); + } }; \ No newline at end of file diff --git a/client/datastore.js b/client/datastore.js index 99d3485..0ae5c68 100644 --- a/client/datastore.js +++ b/client/datastore.js @@ -1,126 +1,126 @@ -const fs = require('fs'); -const path = require('path'); - -module.exports = class { - constructor() { - this.map = new Map(); - this.loadData(); - } - - loadData() { - //console.log(""); - const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'datastore')).filter(f => f.endsWith('.json')); - for (const file of dataFiles) { - try { - const json = require(`../datastore/${file}`); - this.map.set(json.guild.id, json); - //console.log('[LOADED] ' + file + " (" + json.guild.id + ")"); - //console.log(JSON.stringify(json, null, 4)); - } catch (error) { - //console.log('[ERROR] Loading ' + file + ' failed'); - } - } - //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); - //this.showEntry(this.getEntry(id)); - } else { - //this.showEntry(this.getEntry(id)); - } - } - - createEntry(id){ - let newData = {}; - newData.guild = {}; - newData.guild.id = id; - newData.statistics = {}; - this.map.set(id, newData); - this.saveEntry(id, newData); - } - - getEntry(id){ - return this.map.get(id); - } - - updateEntry(guild, newData) { - newData.guild.name = guild.name; - this.map.set(guild.id, newData); - this.saveEntry(guild.id, newData); - //this.showEntry(this.getEntry(guild.id)); - } - - showEntry(data){ - console.log(data); - } - - createTestFile () { - let newData = { - "guild": { - "id": "test", - "name": "Test" - }, - "statistics": { - "test": { - "time": 0, - "used": 0 - } - } - } - - this.updateEntry(newData.guild, newData); - } - - saveEntry(file, data) { - data = JSON.stringify(data, null, 4); - - fs.writeFile(path.join(path.dirname(__dirname), 'datastore') + "/" + file + ".json", data, 'utf8', function(err) { - if (err) { - //console.log(err); - } - }); - } -}; +const fs = require('fs'); +const path = require('path'); + +module.exports = class { + constructor() { + this.map = new Map(); + this.loadData(); + } + + loadData() { + //console.log(""); + const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'datastore')).filter(f => f.endsWith('.json')); + for (const file of dataFiles) { + try { + const json = require(`../datastore/${file}`); + this.map.set(json.guild.id, json); + //console.log('[LOADED] ' + file + " (" + json.guild.id + ")"); + //console.log(JSON.stringify(json, null, 4)); + } catch (error) { + //console.log('[ERROR] Loading ' + file + ' failed'); + } + } + //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); + //this.showEntry(this.getEntry(id)); + } else { + //this.showEntry(this.getEntry(id)); + } + } + + createEntry(id){ + let newData = {}; + newData.guild = {}; + newData.guild.id = id; + newData.statistics = {}; + this.map.set(id, newData); + this.saveEntry(id, newData); + } + + getEntry(id){ + return this.map.get(id); + } + + updateEntry(guild, newData) { + newData.guild.name = guild.name; + this.map.set(guild.id, newData); + this.saveEntry(guild.id, newData); + //this.showEntry(this.getEntry(guild.id)); + } + + showEntry(data){ + console.log(data); + } + + createTestFile () { + let newData = { + "guild": { + "id": "test", + "name": "Test" + }, + "statistics": { + "test": { + "time": 0, + "used": 0 + } + } + } + + this.updateEntry(newData.guild, newData); + } + + saveEntry(file, data) { + data = JSON.stringify(data, null, 4); + + fs.writeFile(path.join(path.dirname(__dirname), 'datastore') + "/" + file + ".json", data, 'utf8', function(err) { + if (err) { + //console.log(err); + } + }); + } +}; diff --git a/client/emojis.js b/client/emojis.js index 8e2b7bc..f196a47 100644 --- a/client/emojis.js +++ b/client/emojis.js @@ -1,38 +1,38 @@ -module.exports = { - name: 'emojis', - async execute(client) { - let customEmojis = { - logo: "<:RadioX:688765708808487072>", - eximiabots: "<:EximiaBots:693277919929303132>", - list: "<:RadioXList:688541155519889482>", - play: "<:RadioXPlay:688541155712827458>", - stop: "<:RadioXStop:688541155377414168>", - statistics: "<:RadioXStatistics:694954485507686421>", - maintenance: "<:RadioXMaintenance:695043843057254493>", - error: "<:RadioXError:688541155792781320>" - }; - - let fallbackEmojis = { - logo: "RadioX", - eximiabots: "EximiaBots", - list: "📜", - play: "▶️", - stop: "⏹️", - statistics: "📊", - maintenance: "🛠️", - error: "❌" - }; - - client.messageEmojis = {}; - - for (customEmojiName in customEmojis) { - customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, ''); - customEmoji = client.emojis.cache.get(customEmojiID); - if (customEmoji) { - client.messageEmojis[customEmojiName] = customEmojis[customEmojiName]; - } else { - client.messageEmojis[customEmojiName] = fallbackEmojis[customEmojiName]; - } - } - } +module.exports = { + name: 'emojis', + async execute(client) { + let customEmojis = { + logo: "<:RadioX:688765708808487072>", + eximiabots: "<:EximiaBots:693277919929303132>", + list: "<:RadioXList:688541155519889482>", + play: "<:RadioXPlay:688541155712827458>", + stop: "<:RadioXStop:688541155377414168>", + statistics: "<:RadioXStatistics:694954485507686421>", + maintenance: "<:RadioXMaintenance:695043843057254493>", + error: "<:RadioXError:688541155792781320>" + }; + + let fallbackEmojis = { + logo: "RadioX", + eximiabots: "EximiaBots", + list: "📜", + play: "▶️", + stop: "⏹️", + statistics: "📊", + maintenance: "🛠️", + error: "❌" + }; + + client.messageEmojis = {}; + + for (customEmojiName in customEmojis) { + customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, ''); + customEmoji = client.emojis.cache.get(customEmojiID); + if (customEmoji) { + client.messageEmojis[customEmojiName] = customEmojis[customEmojiName]; + } else { + client.messageEmojis[customEmojiName] = fallbackEmojis[customEmojiName]; + } + } + } } \ No newline at end of file diff --git a/client/funcs/msToTime.js b/client/funcs/msToTime.js index fbf66ae..14f3fdd 100644 --- a/client/funcs/msToTime.js +++ b/client/funcs/msToTime.js @@ -1,17 +1,17 @@ -module.exports = 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}`; - } +module.exports = 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}`; + } } \ No newline at end of file diff --git a/client/funcs/statisticsUpdate.js b/client/funcs/statisticsUpdate.js index 9e40c48..6e7fff2 100644 --- a/client/funcs/statisticsUpdate.js +++ b/client/funcs/statisticsUpdate.js @@ -1,25 +1,25 @@ -module.exports = function statisticsUpdate(client, guild, radio) { - - client.datastore.checkEntry(guild.id); - - radio.currentGuild = client.datastore.getEntry(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(guild, radio.currentGuild); - } - - if(!radio.connection.dispatcher){ - let date = new Date(); - radio.currentTime = date.getTime(); - radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime); - radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.playTime); - } else { - 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(guild, radio.currentGuild); +module.exports = function statisticsUpdate(client, guild, radio) { + + client.datastore.checkEntry(guild.id); + + radio.currentGuild = client.datastore.getEntry(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(guild, radio.currentGuild); + } + + if(!radio.connection.dispatcher){ + let date = new Date(); + radio.currentTime = date.getTime(); + radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime); + radio.currentGuild.statistics[radio.station.name].time = parseInt(radio.currentGuild.statistics[radio.station.name].time)+parseInt(radio.playTime); + } else { + 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(guild, radio.currentGuild); } \ No newline at end of file diff --git a/client/messages.js b/client/messages.js index 73a7eec..d1d1348 100644 --- a/client/messages.js +++ b/client/messages.js @@ -1,36 +1,36 @@ -module.exports = { - wrongVoiceChannel: "You need to be in the same voice channel as RadioX to use this command!", - noPerms: "You need the %command.permission% permission to use this command!", - notPlaying: "There is nothing playing!", - runningCommandFailed: "Running this command failed!", - noPermsEmbed: "I cannot send embeds (Embed links).", - bugTitle: "Found a bug with %client.user.username%?\nDM one of the core developers:", - bugDescription: "%client.developers%\nOr join the support server: %client.config.supportGuild%", - helpTitle: "%client.user.username% help:", - helpDescription: "%commands% \n %client.config.prefix%help to see more information about a command.", - helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%", - helpCommandDescription: "%command.description% \n Command Alias: %command.alias%", - inviteTitle: "Invite %client.user.username% to your Discord server!", - listTitle: "Radio Stations", - nowplayingTitle: "Now Playing", - nowplayingDescription: "**%radio.station.name%** \n Owner: %radio.station.owner% \n %client.funcs.msToTime(completed, \"hh:mm:ss\")%", - noVoiceChannel: "You need to be in a voice channel to play radio!", - noQuery: "You need to use a number or search for a supported station!", - noPermsConnect: "I cannot connect to your voice channel.", - noPermsSpeak: "I cannot speak in your voice channel.", - wrongStationNumber: "No such station!", - tooShortSearch: "Station must be over 2 characters!", - noSearchResults: "No stations found!", - errorPlaying: "An error has occured while playing radio!", - play: "Start playing: %radio.station.name%", - stop: "Stopped playback!", - currentVolume: "Current volume: **%radio.volume%**", - maxVolume: "The max volume is `100`!", - invalidVolume: "You need to enter a valid __number__.", - negativeVolume: "The volume needs to be a positive number!", - newVolume: "Volume is now: **%volume%**", - statisticsTitle: "Statistics", - maintenanceTitle: "Maintenance", - maintenanceDescription: "This command is not ready to be used by anyone.", - errorToGetPlaylist: "You can't use this bot because it has no playlist available. Check more information in our Discord support server %client.config.supportGuild% !" +module.exports = { + wrongVoiceChannel: "You need to be in the same voice channel as RadioX to use this command!", + noPerms: "You need the %command.permission% permission to use this command!", + notPlaying: "There is nothing playing!", + runningCommandFailed: "Running this command failed!", + noPermsEmbed: "I cannot send embeds (Embed links).", + bugTitle: "Found a bug with %client.user.username%?\nDM one of the core developers:", + bugDescription: "%client.developers%\nOr join the support server: %client.config.supportGuild%", + helpTitle: "%client.user.username% help:", + helpDescription: "%commands% \n %client.config.prefix%help to see more information about a command.", + helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%", + helpCommandDescription: "%command.description% \n Command Alias: %command.alias%", + inviteTitle: "Invite %client.user.username% to your Discord server!", + listTitle: "Radio Stations", + nowplayingTitle: "Now Playing", + nowplayingDescription: "**%radio.station.name%** \n Owner: %radio.station.owner% \n %client.funcs.msToTime(completed, \"hh:mm:ss\")%", + noVoiceChannel: "You need to be in a voice channel to play radio!", + noQuery: "You need to use a number or search for a supported station!", + noPermsConnect: "I cannot connect to your voice channel.", + noPermsSpeak: "I cannot speak in your voice channel.", + wrongStationNumber: "No such station!", + tooShortSearch: "Station must be over 2 characters!", + noSearchResults: "No stations found!", + errorPlaying: "An error has occured while playing radio!", + play: "Start playing: %radio.station.name%", + stop: "Stopped playback!", + currentVolume: "Current volume: **%radio.volume%**", + maxVolume: "The max volume is `100`!", + invalidVolume: "You need to enter a valid __number__.", + negativeVolume: "The volume needs to be a positive number!", + newVolume: "Volume is now: **%volume%**", + statisticsTitle: "Statistics", + maintenanceTitle: "Maintenance", + maintenanceDescription: "This command is not ready to be used by anyone.", + errorToGetPlaylist: "You can't use this bot because it has no playlist available. Check more information in our Discord support server %client.config.supportGuild% !" }; \ No newline at end of file diff --git a/index.js b/index.js index 32724a5..903ebfc 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ -const radioClient = require("./client/class.js"); +const radioClient = require("./client/class.js"); const client = new radioClient(); \ No newline at end of file