diff --git a/bot.js b/bot.js index 9997b5d..a6ba469 100644 --- a/bot.js +++ b/bot.js @@ -25,12 +25,13 @@ class Bot { logger.verbose('Registering cleanup function'); utils.Cleanup(() => { for (let gh in Object.values(this.guildHandlers)) { - if (gh) + if (gh instanceof guilding.GuildHandler) gh.destroy(); } this.client.destroy().then(() => { logger.debug('destroyed client'); }); + this.maindb.close(); }); cmd.setLogger(logger); logger.verbose('Verifying config'); @@ -194,10 +195,12 @@ class Bot { logger.debug('Destroying client...'); this.client.destroy().finally(() => { - logger.debug('Exiting server...') + logger.debug('Exiting server...'); this.webServer.stop().then(() => { logger.debug(`Exiting Process...`); process.exit(0); + }).catch(() => { + process.exit(0); }); }); }); diff --git a/lib/music.js b/lib/music.js index fa8c80e..c74e0e1 100644 --- a/lib/music.js +++ b/lib/music.js @@ -228,10 +228,13 @@ exports.DJ = class { } /** - * Stops playing music by ending the Dispatcher and disconnecting + * Stops playing music by ending the Dispatcher and disconnecting. + * Also sets playing to false and clears the queue and the current song. */ stop() { + this.playing = false; this.queue = []; + this.current = null; logger.verbose("Stopping music..."); try { if (this.disp) { @@ -248,6 +251,7 @@ exports.DJ = class { if (this.voiceChannel) { this.voiceChannel.leave(); logger.debug("Left VoiceChannel"); + logger.info(`Disconnected from Voicechannel ${this.voiceChannel.name}`); } } catch (error) { logger.verbose(JSON.stringify(error)); @@ -441,4 +445,4 @@ exports.nowPlaying = function (guildId) { */ exports.shuffle = function (guildId) { djs[guildId].shuffle(); -}; \ No newline at end of file +}; diff --git a/lib/webapi.js b/lib/webapi.js index fdcfd0e..7c01981 100644 --- a/lib/webapi.js +++ b/lib/webapi.js @@ -62,7 +62,7 @@ exports.WebServer = class { stop() { return new Promise((resolve) => { if (this.server) - this.server.close(() => resolve()); + this.server.close(resolve); else resolve(); }) @@ -245,6 +245,18 @@ class DJ { return this.dj.playing; } + get connected() { + return this.dj.connected; + } + + get queueCount() { + return this.dj.queue.length; + } + + get songStartTime() { + return this.dj.disp.player.streamingData.startTime; + } + get volume() { return this.dj.volume; } @@ -411,4 +423,4 @@ class LogEntry { this.timestamp = entry.timestamp; this.level = entry.level; } -} \ No newline at end of file +} diff --git a/web/graphql/schema.graphql b/web/graphql/schema.graphql index 383948f..0083f16 100644 --- a/web/graphql/schema.graphql +++ b/web/graphql/schema.graphql @@ -28,12 +28,15 @@ type GuildMember { } type DJ { queue(first: Int = 10, offset: Int = 0, id: String): [MediaEntry] - playing: Boolean + queueCount: Int! + songStartTime: String + playing: Boolean! volume: Float repeat: Boolean currentSong: MediaEntry quality: String voiceChannel: String + connected: Boolean! } type Guild { id: ID! @@ -75,4 +78,4 @@ type Query { config: String prefix: String logs(first: Int, offset: Int = 0, id: String, last: Int = 10, level: String): [LogEntry] -} \ No newline at end of file +} diff --git a/web/http/index.html b/web/http/index.html index 1b44a15..fb27838 100644 --- a/web/http/index.html +++ b/web/http/index.html @@ -11,7 +11,6 @@