mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-22 23:53:17 +00:00
Folder re-structuring
This commit is contained in:
parent
5667e2f0a9
commit
f300d9c0df
@ -2,7 +2,7 @@ const { Client, Collection } = require('discord.js');
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const events = '../events/';
|
const events = './events/';
|
||||||
const Datastore = require('./datastore.js');
|
const Datastore = require('./datastore.js');
|
||||||
|
|
||||||
module.exports = class extends Client {
|
module.exports = class extends Client {
|
||||||
@ -16,15 +16,16 @@ module.exports = class extends Client {
|
|||||||
this.radio = new Map();
|
this.radio = new Map();
|
||||||
|
|
||||||
this.funcs = {};
|
this.funcs = {};
|
||||||
this.funcs.check = require('../funcs/check.js');
|
this.funcs.check = require('./funcs/check.js');
|
||||||
this.funcs.msToTime = require('../funcs/msToTime.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');
|
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) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`../commands/${file}`);
|
const command = require(`./commands/${file}`);
|
||||||
command.uses = 0;
|
command.uses = 0;
|
||||||
this.commands.set(command.name, command);
|
this.commands.set(command.name, command);
|
||||||
this.commandAliases.set(command.alias, command);
|
this.commandAliases.set(command.alias, command);
|
@ -1,85 +1,85 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = class {
|
module.exports = class {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.map = new Map();
|
this.map = new Map();
|
||||||
this.loadData();
|
this.loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData() {
|
loadData() {
|
||||||
console.log("");
|
console.log("");
|
||||||
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'datastore')).filter(f => f.endsWith('.json'));
|
const dataFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'datastore')).filter(f => f.endsWith('.json'));
|
||||||
for (const file of dataFiles) {
|
for (const file of dataFiles) {
|
||||||
try {
|
try {
|
||||||
const json = require(`../datastore/${file}`);
|
const json = require(`../datastore/${file}`);
|
||||||
this.map.set(json.guild.id, json);
|
this.map.set(json.guild.id, json);
|
||||||
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
//console.log('[LOADED] ' + file + " (" + json.guild.id + ")");
|
||||||
//console.log(JSON.stringify(json, null, 4));
|
//console.log(JSON.stringify(json, null, 4));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log('[ERROR] Loading ' + file + ' failed');
|
//console.log('[ERROR] Loading ' + file + ' failed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("");
|
console.log("");
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEntry(id){
|
checkEntry(id){
|
||||||
if(!this.map.has(id)){
|
if(!this.map.has(id)){
|
||||||
this.createEntry(id);
|
this.createEntry(id);
|
||||||
//this.showEntry(this.getEntry(id));
|
//this.showEntry(this.getEntry(id));
|
||||||
} else {
|
} else {
|
||||||
//this.showEntry(this.getEntry(id));
|
//this.showEntry(this.getEntry(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createEntry(id){
|
createEntry(id){
|
||||||
let newData = {};
|
let newData = {};
|
||||||
newData.guild = {};
|
newData.guild = {};
|
||||||
newData.guild.id = id;
|
newData.guild.id = id;
|
||||||
newData.statistics = {};
|
newData.statistics = {};
|
||||||
this.map.set(id, newData);
|
this.map.set(id, newData);
|
||||||
this.saveEntry(id, newData);
|
this.saveEntry(id, newData);
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntry(id){
|
getEntry(id){
|
||||||
return this.map.get(id);
|
return this.map.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEntry(guild, newData) {
|
updateEntry(guild, newData) {
|
||||||
newData.guild.name = guild.name;
|
newData.guild.name = guild.name;
|
||||||
this.map.set(guild.id, newData);
|
this.map.set(guild.id, newData);
|
||||||
this.saveEntry(guild.id, newData);
|
this.saveEntry(guild.id, newData);
|
||||||
//this.showEntry(this.getEntry(guild.id));
|
//this.showEntry(this.getEntry(guild.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
showEntry(data){
|
showEntry(data){
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
createTestFile () {
|
createTestFile () {
|
||||||
let newData = {
|
let newData = {
|
||||||
"guild": {
|
"guild": {
|
||||||
"id": "test",
|
"id": "test",
|
||||||
"name": "Test"
|
"name": "Test"
|
||||||
},
|
},
|
||||||
"statistics": {
|
"statistics": {
|
||||||
"test": {
|
"test": {
|
||||||
"time": 0,
|
"time": 0,
|
||||||
"used": 0
|
"used": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateEntry(newData.guild, newData);
|
this.updateEntry(newData.guild, newData);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveEntry(file, data) {
|
saveEntry(file, data) {
|
||||||
data = JSON.stringify(data, null, 4);
|
data = JSON.stringify(data, null, 4);
|
||||||
|
|
||||||
fs.writeFile(path.join(path.dirname(__dirname), 'datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
fs.writeFile(path.join(path.dirname(__dirname), 'datastore') + "/" + file + ".json", data, 'utf8', function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,38 +1,38 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'emojis',
|
name: 'emojis',
|
||||||
async execute(client) {
|
async execute(client) {
|
||||||
let customEmojis = {
|
let customEmojis = {
|
||||||
logo: "<:RadioX:688765708808487072>",
|
logo: "<:RadioX:688765708808487072>",
|
||||||
eximiabots: "<:EximiaBots:693277919929303132>",
|
eximiabots: "<:EximiaBots:693277919929303132>",
|
||||||
list: "<:RadioXList:688541155519889482>",
|
list: "<:RadioXList:688541155519889482>",
|
||||||
play: "<:RadioXPlay:688541155712827458>",
|
play: "<:RadioXPlay:688541155712827458>",
|
||||||
stop: "<:RadioXStop:688541155377414168>",
|
stop: "<:RadioXStop:688541155377414168>",
|
||||||
statistics: "<:RadioXStatistics:694954485507686421>",
|
statistics: "<:RadioXStatistics:694954485507686421>",
|
||||||
maintenance: "<:RadioXMaintenance:695043843057254493>",
|
maintenance: "<:RadioXMaintenance:695043843057254493>",
|
||||||
error: "<:RadioXError:688541155792781320>"
|
error: "<:RadioXError:688541155792781320>"
|
||||||
};
|
};
|
||||||
|
|
||||||
let fallbackEmojis = {
|
let fallbackEmojis = {
|
||||||
logo: "RadioX",
|
logo: "RadioX",
|
||||||
eximiabots: "EximiaBots",
|
eximiabots: "EximiaBots",
|
||||||
list: "📜",
|
list: "📜",
|
||||||
play: "▶️",
|
play: "▶️",
|
||||||
stop: "⏹️",
|
stop: "⏹️",
|
||||||
statistics: "📊",
|
statistics: "📊",
|
||||||
maintenance: "🛠️",
|
maintenance: "🛠️",
|
||||||
error: "❌"
|
error: "❌"
|
||||||
};
|
};
|
||||||
|
|
||||||
client.messageEmojis = {};
|
client.messageEmojis = {};
|
||||||
|
|
||||||
for (customEmojiName in customEmojis) {
|
for (customEmojiName in customEmojis) {
|
||||||
customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, '');
|
customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, '');
|
||||||
customEmoji = client.emojis.cache.get(customEmojiID);
|
customEmoji = client.emojis.cache.get(customEmojiID);
|
||||||
if (customEmoji) {
|
if (customEmoji) {
|
||||||
client.messageEmojis[customEmojiName] = customEmojis[customEmojiName];
|
client.messageEmojis[customEmojiName] = customEmojis[customEmojiName];
|
||||||
} else {
|
} else {
|
||||||
client.messageEmojis[customEmojiName] = fallbackEmojis[customEmojiName];
|
client.messageEmojis[customEmojiName] = fallbackEmojis[customEmojiName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,6 @@ module.exports = {
|
|||||||
.then(res => res.json());
|
.then(res => res.json());
|
||||||
}, 3600000);
|
}, 3600000);
|
||||||
|
|
||||||
require(`../struct/emojis.js`).execute(client);
|
require(`./emojis.js`).execute(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -42,31 +42,4 @@ module.exports = {
|
|||||||
}, 120000);
|
}, 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);
|
|
||||||
|
|
||||||
}
|
|
26
client/funcs/statisticsUpdate.js
Normal file
26
client/funcs/statisticsUpdate.js
Normal 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);
|
||||||
|
|
||||||
|
}
|
@ -1,35 +1,35 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
wrongVoiceChannel: "You need to be in the same voice channel as RadioX to use this command!",
|
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!",
|
noPerms: "You need the %command.permission% permission to use this command!",
|
||||||
notPlaying: "There is nothing playing!",
|
notPlaying: "There is nothing playing!",
|
||||||
runningCommandFailed: "Running this command failed!",
|
runningCommandFailed: "Running this command failed!",
|
||||||
noPermsEmbed: "I cannot send embeds (Embed links).",
|
noPermsEmbed: "I cannot send embeds (Embed links).",
|
||||||
bugTitle: "Found a bug with %client.user.username%?\nDM one of the core developers:",
|
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%",
|
bugDescription: "%client.developers%\nOr join the support server: %client.config.supportGuild%",
|
||||||
helpTitle: "%client.user.username% help:",
|
helpTitle: "%client.user.username% help:",
|
||||||
helpDescription: "%commands% \n %client.config.prefix%help <command> to see more information about a command.",
|
helpDescription: "%commands% \n %client.config.prefix%help <command> to see more information about a command.",
|
||||||
helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%",
|
helpCommandTitle: "%client.config.prefix%%command.name% %command.usage%",
|
||||||
helpCommandDescription: "%command.description% \n Command Alias: %command.alias%",
|
helpCommandDescription: "%command.description% \n Command Alias: %command.alias%",
|
||||||
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
inviteTitle: "Invite %client.user.username% to your Discord server!",
|
||||||
listTitle: "Radio Stations",
|
listTitle: "Radio Stations",
|
||||||
nowplayingTitle: "Now Playing",
|
nowplayingTitle: "Now Playing",
|
||||||
nowplayingDescription: "**%radio.station.name%** \n Owner: %radio.station.owner% \n %client.funcs.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!",
|
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!",
|
noQuery: "You need to use a number or search for a supported station!",
|
||||||
noPermsConnect: "I cannot connect to your voice channel.",
|
noPermsConnect: "I cannot connect to your voice channel.",
|
||||||
noPermsSpeak: "I cannot speak in your voice channel.",
|
noPermsSpeak: "I cannot speak in your voice channel.",
|
||||||
wrongStationNumber: "No such station!",
|
wrongStationNumber: "No such station!",
|
||||||
tooShortSearch: "Station must be over 2 characters!",
|
tooShortSearch: "Station must be over 2 characters!",
|
||||||
noSearchResults: "No stations found!",
|
noSearchResults: "No stations found!",
|
||||||
errorPlaying: "An error has occured while playing radio!",
|
errorPlaying: "An error has occured while playing radio!",
|
||||||
play: "Start playing: %radio.station.name%",
|
play: "Start playing: %radio.station.name%",
|
||||||
stop: "Stopped playback!",
|
stop: "Stopped playback!",
|
||||||
currentVolume: "Current volume: **%radio.volume%**",
|
currentVolume: "Current volume: **%radio.volume%**",
|
||||||
maxVolume: "The max volume is `100`!",
|
maxVolume: "The max volume is `100`!",
|
||||||
invalidVolume: "You need to enter a valid __number__.",
|
invalidVolume: "You need to enter a valid __number__.",
|
||||||
negativeVolume: "The volume needs to be a positive number!",
|
negativeVolume: "The volume needs to be a positive number!",
|
||||||
newVolume: "Volume is now: **%volume%**",
|
newVolume: "Volume is now: **%volume%**",
|
||||||
statisticsTitle: "Statistics",
|
statisticsTitle: "Statistics",
|
||||||
maintenanceTitle: "Maintenance",
|
maintenanceTitle: "Maintenance",
|
||||||
maintenanceDescription: "This command is not ready to be used by anyone."
|
maintenanceDescription: "This command is not ready to be used by anyone."
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user