Added saveState & loadState functions

This commit is contained in:
Christer Warén 2021-09-03 01:21:55 +03:00
parent f2158ba8ae
commit e546001be8
3 changed files with 30 additions and 1 deletions

View File

@ -37,6 +37,8 @@ class RadioClient extends Client {
this.funcs.logger = require("./client/funcs/logger.js"); this.funcs.logger = require("./client/funcs/logger.js");
this.funcs.msToTime = require("./client/funcs/msToTime.js"); this.funcs.msToTime = require("./client/funcs/msToTime.js");
this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js"); this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js");
this.funcs.saveState = require("./client/funcs/saveState.js");
this.funcs.loadState = require("./client/funcs/loadState.js");
console.log('RadioX ' + this.config.version); console.log('RadioX ' + this.config.version);
console.log('Internet Radio to your Discord guild'); console.log('Internet Radio to your Discord guild');
@ -53,7 +55,6 @@ class RadioClient extends Client {
this.on("ready", () => { this.on("ready", () => {
require(`${events}ready`).execute(this); require(`${events}ready`).execute(this);
this.datastore = new Datastore();
}); });
this.on("messageCreate", msg => { this.on("messageCreate", msg => {

View File

@ -0,0 +1,10 @@
module.exports = function loadState(client, guild){
let data = client.datastore.getEntry(guild.id);
if(!data) return;
let state;
state = data.state;
data.state = {};
client.datastore.updateEntry(guild, data);
return state;
}

View File

@ -0,0 +1,18 @@
module.exports = function saveState(client, guild, radio){
client.datastore.checkEntry(guild.id);
let date = new Date();
let data = client.datastore.getEntry(guild.id);
data.state = {};
data.state.channels = {};
data.state.channels.text = radio.textChannel.id;
data.state.channels.voice = radio.voiceChannel.id;
data.state.date = date.toISOString();
data.state.station = {};
data.state.station.name = radio.station.name;
data.state.station.owner = radio.station.owner;
client.datastore.updateEntry(guild, data);
}