Folder re-structuring

This commit is contained in:
Christer Warén 2020-04-02 08:40:05 +03:00
parent 5667e2f0a9
commit f300d9c0df
21 changed files with 192 additions and 192 deletions

View File

@ -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);

View File

@ -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);
}
});
}
};

View File

@ -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];
}
}
}
}

View File

@ -32,6 +32,6 @@ module.exports = {
.then(res => res.json());
}, 3600000);
require(`../struct/emojis.js`).execute(client);
require(`./emojis.js`).execute(client);
}
}

View File

@ -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);
}
};

View File

@ -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);
}

View File

@ -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 <command> 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 <command> 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."
};

View File

@ -1,2 +1,2 @@
const radioClient = require("./struct/client.js");
const radioClient = require("./client/class.js");
const client = new radioClient();