Compare commits

...

12 Commits

9 changed files with 29 additions and 32 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "eximiabots-radiox", "name": "eximiabots-radiox",
"version": "0.3.9", "version": "0.3.11",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "eximiabots-radiox", "name": "eximiabots-radiox",
"version": "0.3.9", "version": "0.3.11",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@discordjs/builders": "^0.6.0", "@discordjs/builders": "^0.6.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "eximiabots-radiox", "name": "eximiabots-radiox",
"version": "0.3.9", "version": "0.3.11",
"description": "Internet Radio to your Discord guild", "description": "Internet Radio to your Discord guild",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -48,8 +48,11 @@ module.exports = class {
} }
loadEntry(id){ loadEntry(id){
const json = require(`../../../datastore/` + id + '.json'); try {
this.map.set(id, json); const json = require(`../../../datastore/` + id + '.json');
this.map.set(id, json);
} catch (error) {
}
} }
getEntry(id){ getEntry(id){

View File

@ -65,18 +65,8 @@ module.exports = class Radio extends Map {
construct.connection = connection; construct.connection = connection;
let date = new Date(); let date = new Date();
construct.startTime = date.getTime(); construct.startTime = date.getTime();
client.funcs.play(client, null, guild, station);
client.datastore.checkEntry(guild.id); client.datastore.checkEntry(guild.id);
construct.datastore = client.datastore.getEntry(guild.id); client.funcs.play(client, null, guild, station);
if (!construct.datastore.statistics[construct.station.name]) {
construct.datastore.statistics[construct.station.name] = {};
construct.datastore.statistics[construct.station.name].time = 0;
construct.datastore.statistics[construct.station.name].used = 0;
client.datastore.updateEntry(guild, construct.datastore);
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }

View File

@ -15,16 +15,18 @@ module.exports = class Stations extends Array {
.then(response => response.json()); .then(response => response.json());
if(list){ if(list){
this.logger('Stations'); this.length = 0;
this.forEach(oldStation => {
if(list.findIndex(station => station.name == oldStation.name)) return;
delete this[this.findIndex(station => station.name == oldStation.name)];
});
list.forEach(station => { list.forEach(station => {
console.log("- " + station.name);
this.push(station); this.push(station);
}); });
console.log("\n");
if(options.show){
this.logger('Stations');
list.forEach(station => {
console.log("- " + station.name);
});
console.log("\n");
}
} }
this.logger('Stations', 'Successfully fetched list'); this.logger('Stations', 'Successfully fetched list');

View File

@ -40,8 +40,9 @@ module.exports = class {
let streamers = this.map.keys(); let streamers = this.map.keys();
streamers.forEach(streamer => { streamers.forEach(streamer => {
if(client.stations.findIndex(station => station.name == streamer)) return; if(client.stations.findIndex(station => station.name == streamer) == -1){
this.stop(streamer); this.stop(streamer);
}
}); });
} }
@ -73,15 +74,12 @@ module.exports = class {
this.play(station); this.play(station);
}); });
audioPlayer audioPlayer
.on('playing', () => { .on('playing', () => {
this.logger('Streamer', station.name + " / " + "Playing"); this.logger('Streamer', station.name + " / " + "Playing");
}) })
.on('idle', () => { .on('idle', () => {
this.logger('Streamer', station.name + " / " + "Idle"); this.logger('Streamer', station.name + " / " + "Idle");
this.play(station);
}) })
.on('paused', () => { .on('paused', () => {
this.logger('Streamer', station.name + " / " + "Paused"); this.logger('Streamer', station.name + " / " + "Paused");

View File

@ -155,7 +155,7 @@ module.exports = {
client.config.maintenanceMode = true; client.config.maintenanceMode = true;
client.user.setStatus('idle'); client.user.setStatus('idle');
client.funcs.saveRadios(client); client.radio.save(client);
setInterval(() => { setInterval(() => {
if(client.radio.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){ if(client.radio.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){
@ -179,7 +179,7 @@ module.exports = {
client.config.maintenanceMode = true; client.config.maintenanceMode = true;
client.user.setStatus('idle'); client.user.setStatus('idle');
client.funcs.save(client); client.radio.save(client);
setInterval(() => { setInterval(() => {
if(client.radio.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){ if(client.radio.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){

View File

@ -42,12 +42,14 @@ module.exports = {
client.stations = new Stations(); client.stations = new Stations();
await client.stations.fetch({ await client.stations.fetch({
url: client.config.stationslistUrl url: client.config.stationslistUrl,
show: true
}); });
setInterval(async () => { setInterval(async () => {
await client.stations.fetch({ await client.stations.fetch({
url: client.config.stationslistUrl url: client.config.stationslistUrl,
show: false
}); });
}, 3600000); }, 3600000);

View File

@ -4,6 +4,8 @@ module.exports = function loadState(client, guild){
let state; let state;
state = data.state; state = data.state;
if(!state) return;
data.state = {}; data.state = {};
client.datastore.updateEntry(guild, data); client.datastore.updateEntry(guild, data);
return state; return state;