Bugfixes and features

- fixed player bug
- added duration to play view
- fixed queue view
- added queue count
pull/33/head
Trivernis 6 years ago
parent 9ce38e4f3b
commit 36b6416531

@ -25,12 +25,13 @@ class Bot {
logger.verbose('Registering cleanup function'); logger.verbose('Registering cleanup function');
utils.Cleanup(() => { utils.Cleanup(() => {
for (let gh in Object.values(this.guildHandlers)) { for (let gh in Object.values(this.guildHandlers)) {
if (gh) if (gh instanceof guilding.GuildHandler)
gh.destroy(); gh.destroy();
} }
this.client.destroy().then(() => { this.client.destroy().then(() => {
logger.debug('destroyed client'); logger.debug('destroyed client');
}); });
this.maindb.close();
}); });
cmd.setLogger(logger); cmd.setLogger(logger);
logger.verbose('Verifying config'); logger.verbose('Verifying config');
@ -194,10 +195,12 @@ class Bot {
logger.debug('Destroying client...'); logger.debug('Destroying client...');
this.client.destroy().finally(() => { this.client.destroy().finally(() => {
logger.debug('Exiting server...') logger.debug('Exiting server...');
this.webServer.stop().then(() => { this.webServer.stop().then(() => {
logger.debug(`Exiting Process...`); logger.debug(`Exiting Process...`);
process.exit(0); process.exit(0);
}).catch(() => {
process.exit(0);
}); });
}); });
}); });

@ -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() { stop() {
this.playing = false;
this.queue = []; this.queue = [];
this.current = null;
logger.verbose("Stopping music..."); logger.verbose("Stopping music...");
try { try {
if (this.disp) { if (this.disp) {
@ -248,6 +251,7 @@ exports.DJ = class {
if (this.voiceChannel) { if (this.voiceChannel) {
this.voiceChannel.leave(); this.voiceChannel.leave();
logger.debug("Left VoiceChannel"); logger.debug("Left VoiceChannel");
logger.info(`Disconnected from Voicechannel ${this.voiceChannel.name}`);
} }
} catch (error) { } catch (error) {
logger.verbose(JSON.stringify(error)); logger.verbose(JSON.stringify(error));

@ -62,7 +62,7 @@ exports.WebServer = class {
stop() { stop() {
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.server) if (this.server)
this.server.close(() => resolve()); this.server.close(resolve);
else else
resolve(); resolve();
}) })
@ -245,6 +245,18 @@ class DJ {
return this.dj.playing; 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() { get volume() {
return this.dj.volume; return this.dj.volume;
} }

@ -28,12 +28,15 @@ type GuildMember {
} }
type DJ { type DJ {
queue(first: Int = 10, offset: Int = 0, id: String): [MediaEntry] queue(first: Int = 10, offset: Int = 0, id: String): [MediaEntry]
playing: Boolean queueCount: Int!
songStartTime: String
playing: Boolean!
volume: Float volume: Float
repeat: Boolean repeat: Boolean
currentSong: MediaEntry currentSong: MediaEntry
quality: String quality: String
voiceChannel: String voiceChannel: String
connected: Boolean!
} }
type Guild { type Guild {
id: ID! id: ID!

@ -11,7 +11,6 @@
<body> <body>
<div id="content"> <div id="content">
<div class="column" id="column-left"> <div class="column" id="column-left">
<pre class="cell text-left" id="bot-config"></pre>
<h2 class="cell">Logs</h2> <h2 class="cell">Logs</h2>
<div id="log-container" class="listContainer"></div> <div id="log-container" class="listContainer"></div>
</div> </div>
@ -70,18 +69,24 @@
<span class="label text-right">Repeat: </span> <span class="label text-right">Repeat: </span>
<span class="text-left" id="dj-repeat"></span> <span class="text-left" id="dj-repeat"></span>
</div> </div>
<a class="cell listContainer" id="dj-songinfo" style="display: none">
<div class="cell"> <div class="cell">
<span class="label text-right">Voice Channel: </span> <span class="label text-right">Voice Channel: </span>
<span class="text-left" id="dj-voiceChannel"></span> <span class="text-left" id="dj-voiceChannel"></span>
</div> </div>
<div id="songinfo-container"> <div class="cell listContainer" id="dj-songinfo" style="display: none">
<a id="songinfo-container">
<span id="dj-songname"></span> <span id="dj-songname"></span>
<img id="dj-songImg" src="" alt=""/> <img id="dj-songImg" src="" alt=""/>
<span style="font-weight: bold">Next 5 Songs</span> <div id="dj-songProgress">
<div id="dj-songQueue"></div> <span id="dj-songCurrentTS"></span>
</div> </div>
</a> </a>
<div id="dj-queue-container">
<span class="cell label" id="Queue Song count"><span id="dj-queueCount"></span> Songs in Queue</span>
<span class="cell">Next <span id="dj-queueDisplayCount">0</span> Songs:</span>
<div id="dj-songQueue"></div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

@ -120,6 +120,8 @@ div.cell > *
padding: 2px padding: 2px
margin: 5px margin: 5px
border-radius: 5px border-radius: 5px
text-decoration: none
color: $cPrimary
.songEntry > * .songEntry > *
display: table-column display: table-column
@ -130,6 +132,7 @@ div.cell > *
max-width: 20% max-width: 20%
height: auto height: auto
width: auto width: auto
border-radius: 2px
.songEntry a .songEntry a
width: 80% width: 80%
@ -184,11 +187,6 @@ div.cell > *
#status-indicator[status=offline] #status-indicator[status=offline]
background-color: $cOffline background-color: $cOffline
#bot-config
background: darken($cBackground, 3)
word-wrap: break-word
display: none
#guild-select #guild-select
background: $cBackgroundVariant background: $cBackgroundVariant
color: $cPrimary color: $cPrimary
@ -211,14 +209,19 @@ div.cell > *
border-radius: 25% border-radius: 25%
#dj-songinfo #dj-songinfo
display: block
background-color: $cBackgroundVariant
border-radius: 20px
#songinfo-container
display: list-item
text-decoration: none text-decoration: none
color: $cPrimary color: $cPrimary
padding: 10px padding: 10px
width: calc(100% - 20px)
#songinfo-container dj-queue-container
background-color: $cBackgroundVariant display: list-item
border-radius: 20px
padding: 10px
#dj-songname #dj-songname
font-weight: bold font-weight: bold

@ -1,5 +1,4 @@
let latestLogs = []; let latestLogs = [];
let latestSongs = [];
let status = { let status = {
0: 'ready', 0: 'ready',
@ -48,13 +47,11 @@ function queryStatic() {
avatar avatar
} }
} }
config
}`; }`;
postQuery(query).then((res) => { postQuery(query).then((res) => {
let d = res.data; let d = res.data;
document.querySelector('#user-avatar').setAttribute('src', d.client.user.avatar); document.querySelector('#user-avatar').setAttribute('src', d.client.user.avatar);
document.querySelector('#user-tag').innerText = d.client.user.tag; document.querySelector('#user-tag').innerText = d.client.user.tag;
document.querySelector('#bot-config').innerText = d.config;
}) })
} }
@ -121,13 +118,16 @@ function queryGuildStatus(guildId) {
guilds(id: "${guildId}") { guilds(id: "${guildId}") {
dj { dj {
playing playing
connected
repeat repeat
voiceChannel voiceChannel
songStartTime
currentSong { currentSong {
name name
url url
thumbnail thumbnail
} }
queueCount
queue(first: 5) { queue(first: 5) {
id id
name name
@ -141,37 +141,47 @@ function queryGuildStatus(guildId) {
}`; }`;
postQuery(query).then((res) => { postQuery(query).then((res) => {
let guild = res.data.client.guilds[0]; let guild = res.data.client.guilds[0];
document.querySelector('#guild-djStatus').innerText = guild.dj.playing? 'playing' : 'idle';
document.querySelector('#dj-repeat').innerText = guild.dj.repeat? 'on': 'off'; document.querySelector('#dj-repeat').innerText = guild.dj.repeat? 'on': 'off';
if (guild.dj.playing) { document.querySelector('#guild-djStatus').innerText = guild.dj.connected? 'connected' : 'disconnected';
if (guild.dj.connected) {
$('#dj-songinfo').show(); $('#dj-songinfo').show();
document.querySelector('#guild-djStatus').innerText = guild.dj.playing? 'playing' : 'connected';
document.querySelector('#dj-voiceChannel').innerText = guild.dj.voiceChannel; document.querySelector('#dj-voiceChannel').innerText = guild.dj.voiceChannel;
document.querySelector('#dj-songinfo').setAttribute('href', guild.dj.currentSong.url); let songinfoContainer = $('#dj-songinfo');
if (guild.dj.playing) {
if (songinfoContainer.is(':hidden'))
songinfoContainer.show();
document.querySelector('#songinfo-container').setAttribute('href', guild.dj.currentSong.url);
document.querySelector('#dj-songname').innerText = guild.dj.currentSong.name; document.querySelector('#dj-songname').innerText = guild.dj.currentSong.name;
document.querySelector('#dj-songImg').setAttribute('src', guild.dj.currentSong.thumbnail); document.querySelector('#dj-songImg').setAttribute('src', guild.dj.currentSong.thumbnail.replace('maxresdefault', 'mqdefault'));
let songSd = getSplitDuration(Date.now() - guild.dj.songStartTime);
document.querySelector('#dj-songCurrentTS').innerText = `${songSd.minutes}:${songSd.seconds.toString().padStart(2, '0')}`;
document.querySelector('#dj-songCurrentTS').setAttribute('start-ts', guild.dj.songStartTime);
document.querySelector('#dj-queueCount').innerText = guild.dj.queueCount;
let songContainer = document.querySelector('#dj-songQueue'); let songContainer = document.querySelector('#dj-songQueue');
$('.songEntry').remove();
for (let song of guild.dj.queue) { for (let song of guild.dj.queue) {
if ($(`.songEntry[song-id=${song.id}]`).length === 0) { let songEntry = document.createElement('a');
let songEntry = document.createElement('div'); songEntry.setAttribute('href', song.url);
songEntry.setAttribute('class', 'songEntry'); songEntry.setAttribute('class', 'songEntry');
songEntry.setAttribute('song-id', song.id); songEntry.setAttribute('song-id', song.id);
let imageEntry = document.createElement('img'); let imageEntry = document.createElement('img');
imageEntry.setAttribute('src', song.thumbnail); imageEntry.setAttribute('src', song.thumbnail.replace('maxresdefault', 'mqdefault'));
songEntry.appendChild(imageEntry); songEntry.appendChild(imageEntry);
let nameEntry = document.createElement('a'); let nameEntry = document.createElement('a');
nameEntry.setAttribute('href', song.url);
nameEntry.innerText = song.name; nameEntry.innerText = song.name;
songEntry.appendChild(nameEntry); songEntry.appendChild(nameEntry);
songContainer.appendChild(songEntry); songContainer.appendChild(songEntry);
} }
document.querySelector('#dj-queueDisplayCount').innerText = document.querySelectorAll('.songEntry').length;
} else {
if (songinfoContainer.is(':not(:hidden)'))
songinfoContainer.hide();
} }
let songEntries = $('.songEntry');
if (songEntries.length > 5) {
document.querySelector('#dj-songQueue').firstElementChild.remove();
}
let latestSongs = guild.dj.queue;
} else { } else {
$('#dj-songinfo').hide(); $('#dj-songinfo').hide();
document.querySelector('#dj-voiceChannel').innerText = 'None';
} }
}); });
} }
@ -201,7 +211,11 @@ function queryStatus() {
.innerText = `${sd.days}d ${sd.hours}h ${sd.minutes}min ${sd.seconds}s`; .innerText = `${sd.days}d ${sd.hours}h ${sd.minutes}min ${sd.seconds}s`;
document.querySelector('#client-guildCount').innerText = d.client.guildCount; document.querySelector('#client-guildCount').innerText = d.client.guildCount;
if (d.client.status !== 0) {
document.querySelector('#status-indicator').setAttribute('status', 'offline');
} else {
document.querySelector('#status-indicator').setAttribute('status', d.client.user.presence.status); document.querySelector('#status-indicator').setAttribute('status', d.client.user.presence.status);
}
document.querySelector('#user-game').innerText = d.client.user.presence.game; document.querySelector('#user-game').innerText = d.client.user.presence.game;
setTimeout(() => { setTimeout(() => {
@ -283,4 +297,8 @@ function startUpdating() {
let guildId = ev.target.value; let guildId = ev.target.value;
queryGuild(guildId); queryGuild(guildId);
}); });
setInterval(() => {
let songSd = getSplitDuration(Date.now() - $('#dj-songCurrentTS').attr('start-ts'));
document.querySelector('#dj-songCurrentTS').innerText = `${songSd.minutes}:${songSd.seconds.toString().padStart(2, '0')}`;
}, 500);
} }
Loading…
Cancel
Save