diff --git a/commands/maintenance.js b/commands/maintenance.js index 641e742..739ccea 100644 --- a/commands/maintenance.js +++ b/commands/maintenance.js @@ -14,22 +14,4 @@ module.exports = { .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}`; - } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/commands/nowplaying.js b/commands/nowplaying.js index dd28240..af20a2e 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -13,7 +13,7 @@ module.exports = { message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name); message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner); - message.nowplayingDescription = message.nowplayingDescription.replace("%msToTime(completed, \"hh:mm:ss\")%", msToTime(completed, "hh:mm:ss")); + message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed, \"hh:mm:ss\")%", client.funcs.msToTime(completed, "hh:mm:ss")); const embed = new Discord.MessageEmbed() .setTitle(client.messages.nowplayingTitle) @@ -23,21 +23,4 @@ module.exports = { .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}`; - } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/commands/statistics.js b/commands/statistics.js index fded586..5828f07 100644 --- a/commands/statistics.js +++ b/commands/statistics.js @@ -18,11 +18,11 @@ module.exports = { if(currentGuild.statistics[stations[station].name]){ if(i > 0){ statistics += "**" + station + " " + stations[station].name + "** \n"; - statistics += "Time: " + msToTime(currentGuild.statistics[stations[station].name].time, "hh:mm:ss") + "\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 = "**" + station + " " + stations[station].name + "** \n"; - statistics += "Time: " + msToTime(currentGuild.statistics[stations[station].name].time, "hh:mm:ss") + "\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++; @@ -38,22 +38,4 @@ module.exports = { .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}`; - } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/struct/check.js b/funcs/check.js similarity index 100% rename from struct/check.js rename to funcs/check.js diff --git a/funcs/msToTime.js b/funcs/msToTime.js new file mode 100644 index 0000000..fbf66ae --- /dev/null +++ b/funcs/msToTime.js @@ -0,0 +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}`; + } +} \ No newline at end of file diff --git a/struct/client.js b/struct/client.js index 21ca272..ac7e8fb 100644 --- a/struct/client.js +++ b/struct/client.js @@ -14,10 +14,13 @@ module.exports = class extends Client { this.commands = new Collection(); this.commandAliases = new Collection(); this.radio = new Map(); + this.funcs = {}; + this.funcs.check = require('../funcs/check.js'); + this.funcs.msToTime = require('../funcs/msToTime.js'); + this.config = require('../config.js'); this.messages = require('./messages.js'); - this.funcs.check = require('./check.js'); const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js')); for (const file of commandFiles) { diff --git a/struct/messages.js b/struct/messages.js index 5ba3203..780caf4 100644 --- a/struct/messages.js +++ b/struct/messages.js @@ -13,7 +13,7 @@ module.exports = { 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 %msToTime(completed, \"hh:mm:ss\")%", + 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.",