Added saveRadios function & imported funcs in Client.ts

This commit is contained in:
Christer Warén 2021-09-06 04:22:35 +03:00
parent 235a02ca60
commit 60ef1cd138
2 changed files with 22 additions and 0 deletions

View File

@ -42,6 +42,8 @@ class RadioClient extends Client {
this.funcs.searchStation = require("./client/funcs/searchStation.js"); this.funcs.searchStation = require("./client/funcs/searchStation.js");
this.funcs.play = require("./client/funcs/play.js"); this.funcs.play = require("./client/funcs/play.js");
this.funcs.listStations = require("./client/funcs/listStations.js"); this.funcs.listStations = require("./client/funcs/listStations.js");
this.funcs.restoreRadios = require("./client/funcs/restoreRadios.js");
this.funcs.saveRadios = require("./client/funcs/saveRadios.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');

View File

@ -0,0 +1,20 @@
module.exports = async function saveRadios(client) {
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
while (!radio.done) {
let currentRadio = client.radio.get(radio.value);
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if (currentRadio) {
await client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
await client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
}
radio = currentRadios.next();
}
}