From f300d9c0df9d1aad6dc104009b34f6f9152e0582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Thu, 2 Apr 2020 08:40:05 +0300 Subject: [PATCH] Folder re-structuring --- struct/client.js => client/class.js | 13 +- {commands => client/commands}/bug.js | 0 {commands => client/commands}/help.js | 0 {commands => client/commands}/invite.js | 0 {commands => client/commands}/list.js | 0 {commands => client/commands}/maintenance.js | 0 {commands => client/commands}/nowplaying.js | 0 {commands => client/commands}/play.js | 0 {commands => client/commands}/statistics.js | 0 {commands => client/commands}/stop.js | 0 {commands => client/commands}/volume.js | 0 {struct => client}/datastore.js | 170 +++++++++--------- {struct => client}/emojis.js | 74 ++++---- {events => client/events}/msg.js | 0 {events => client/events}/ready.js | 2 +- {events => client/events}/voiceStateUpdate.js | 29 +-- {funcs => client/funcs}/check.js | 0 {funcs => client/funcs}/msToTime.js | 0 client/funcs/statisticsUpdate.js | 26 +++ {struct => client}/messages.js | 68 +++---- index.js | 2 +- 21 files changed, 192 insertions(+), 192 deletions(-) rename struct/client.js => client/class.js (76%) rename {commands => client/commands}/bug.js (100%) rename {commands => client/commands}/help.js (100%) rename {commands => client/commands}/invite.js (100%) rename {commands => client/commands}/list.js (100%) rename {commands => client/commands}/maintenance.js (100%) rename {commands => client/commands}/nowplaying.js (100%) rename {commands => client/commands}/play.js (100%) rename {commands => client/commands}/statistics.js (100%) rename {commands => client/commands}/stop.js (100%) rename {commands => client/commands}/volume.js (100%) rename {struct => client}/datastore.js (96%) rename {struct => client}/emojis.js (97%) rename {events => client/events}/msg.js (100%) rename {events => client/events}/ready.js (95%) rename {events => client/events}/voiceStateUpdate.js (59%) rename {funcs => client/funcs}/check.js (100%) rename {funcs => client/funcs}/msToTime.js (100%) create mode 100644 client/funcs/statisticsUpdate.js rename {struct => client}/messages.js (98%) diff --git a/struct/client.js b/client/class.js similarity index 76% rename from struct/client.js rename to client/class.js index ac7e8fb..544fe6b 100644 --- a/struct/client.js +++ b/client/class.js @@ -2,7 +2,7 @@ const { Client, Collection } = require('discord.js'); const Discord = require('discord.js'); const fs = require('fs'); const path = require('path'); -const events = '../events/'; +const events = './events/'; const Datastore = require('./datastore.js'); module.exports = class extends Client { @@ -16,15 +16,16 @@ module.exports = class extends Client { this.radio = new Map(); this.funcs = {}; - this.funcs.check = require('../funcs/check.js'); - this.funcs.msToTime = require('../funcs/msToTime.js'); + this.funcs.check = require('./funcs/check.js'); + this.funcs.msToTime = require('./funcs/msToTime.js'); + this.funcs.statisticsUpdate = require('./funcs/statisticsUpdate.js'); - this.config = require('../config.js'); + this.config = require('./config.js'); this.messages = require('./messages.js'); - const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js')); + const commandFiles = fs.readdirSync(path.join('commands')).filter(f => f.endsWith('.js')); for (const file of commandFiles) { - const command = require(`../commands/${file}`); + const command = require(`./commands/${file}`); command.uses = 0; this.commands.set(command.name, command); this.commandAliases.set(command.alias, command); diff --git a/commands/bug.js b/client/commands/bug.js similarity index 100% rename from commands/bug.js rename to client/commands/bug.js diff --git a/commands/help.js b/client/commands/help.js similarity index 100% rename from commands/help.js rename to client/commands/help.js diff --git a/commands/invite.js b/client/commands/invite.js similarity index 100% rename from commands/invite.js rename to client/commands/invite.js diff --git a/commands/list.js b/client/commands/list.js similarity index 100% rename from commands/list.js rename to client/commands/list.js diff --git a/commands/maintenance.js b/client/commands/maintenance.js similarity index 100% rename from commands/maintenance.js rename to client/commands/maintenance.js diff --git a/commands/nowplaying.js b/client/commands/nowplaying.js similarity index 100% rename from commands/nowplaying.js rename to client/commands/nowplaying.js diff --git a/commands/play.js b/client/commands/play.js similarity index 100% rename from commands/play.js rename to client/commands/play.js diff --git a/commands/statistics.js b/client/commands/statistics.js similarity index 100% rename from commands/statistics.js rename to client/commands/statistics.js diff --git a/commands/stop.js b/client/commands/stop.js similarity index 100% rename from commands/stop.js rename to client/commands/stop.js diff --git a/commands/volume.js b/client/commands/volume.js similarity index 100% rename from commands/volume.js rename to client/commands/volume.js diff --git a/struct/datastore.js b/client/datastore.js similarity index 96% rename from struct/datastore.js rename to client/datastore.js index d034e25..c2f3ef2 100644 --- a/struct/datastore.js +++ b/client/datastore.js @@ -1,85 +1,85 @@ -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(""); - } - - 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(""); + } + + 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/struct/emojis.js b/client/emojis.js similarity index 97% rename from struct/emojis.js rename to client/emojis.js index f196a47..8e2b7bc 100644 --- a/struct/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/events/msg.js b/client/events/msg.js similarity index 100% rename from events/msg.js rename to client/events/msg.js diff --git a/events/ready.js b/client/events/ready.js similarity index 95% rename from events/ready.js rename to client/events/ready.js index 1a0809c..3296d68 100644 --- a/events/ready.js +++ b/client/events/ready.js @@ -32,6 +32,6 @@ module.exports = { .then(res => res.json()); }, 3600000); - require(`../struct/emojis.js`).execute(client); + require(`./emojis.js`).execute(client); } } \ No newline at end of file diff --git a/events/voiceStateUpdate.js b/client/events/voiceStateUpdate.js similarity index 59% rename from events/voiceStateUpdate.js rename to client/events/voiceStateUpdate.js index 93f06d0..c8490e7 100644 --- a/events/voiceStateUpdate.js +++ b/client/events/voiceStateUpdate.js @@ -42,31 +42,4 @@ module.exports = { }, 120000); } } -}; - -function statisticsUpdate(client, currentState, radio) { - - client.datastore.checkEntry(currentState.guild.id); - - radio.currentGuild = client.datastore.getEntry(currentState.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(currentState.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(currentState.guild, radio.currentGuild); - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/funcs/check.js b/client/funcs/check.js similarity index 100% rename from funcs/check.js rename to client/funcs/check.js diff --git a/funcs/msToTime.js b/client/funcs/msToTime.js similarity index 100% rename from funcs/msToTime.js rename to client/funcs/msToTime.js diff --git a/client/funcs/statisticsUpdate.js b/client/funcs/statisticsUpdate.js new file mode 100644 index 0000000..d2ffa4f --- /dev/null +++ b/client/funcs/statisticsUpdate.js @@ -0,0 +1,26 @@ +module.exports = function statisticsUpdate(client, currentState, radio) { + + client.datastore.checkEntry(currentState.guild.id); + + radio.currentGuild = client.datastore.getEntry(currentState.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(currentState.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(currentState.guild, radio.currentGuild); + +} \ No newline at end of file diff --git a/struct/messages.js b/client/messages.js similarity index 98% rename from struct/messages.js rename to client/messages.js index 780caf4..c2bd248 100644 --- a/struct/messages.js +++ b/client/messages.js @@ -1,35 +1,35 @@ -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." +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." }; \ No newline at end of file diff --git a/index.js b/index.js index 30dfbd5..32724a5 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ -const radioClient = require("./struct/client.js"); +const radioClient = require("./client/class.js"); const client = new radioClient(); \ No newline at end of file