This commit is contained in:
KGT1 2020-09-23 17:42:13 +02:00
parent db6638724c
commit a719ccecd9
3 changed files with 12 additions and 13 deletions

View File

@ -44,7 +44,7 @@ function getRandomDiscordColor () {
return ("#" + ("00" + (randomNumber(rS, rE)).toString(16)).substr(-2) + ("00" + (randomNumber(gS, gE)).toString(16)).substr(-2) + ("00" + (randomNumber(bS, bE)).toString(16)).substr(-2)); return ("#" + ("00" + (randomNumber(rS, rE)).toString(16)).substr(-2) + ("00" + (randomNumber(gS, gE)).toString(16)).substr(-2) + ("00" + (randomNumber(bS, bE)).toString(16)).substr(-2));
} }
function getDiscordEmbedError(e){ function getDiscordEmbedError (e) {
return new Discord.MessageEmbed() return new Discord.MessageEmbed()
.setColor(0xff0000) .setColor(0xff0000)
.setTitle("Error!") .setTitle("Error!")
@ -52,7 +52,6 @@ function getDiscordEmbedError(e){
.setDescription("<:x:757935515445231651> " + e); .setDescription("<:x:757935515445231651> " + e);
} }
// Song Search, return the song itemID // Song Search, return the song itemID
async function searchForItemID (searchString) { async function searchForItemID (searchString) {
const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({
@ -114,7 +113,7 @@ async function playThis (message) {
} catch (e) { } catch (e) {
const noSong = getDiscordEmbedError(e); const noSong = getDiscordEmbedError(e);
message.channel.send(noSong); message.channel.send(noSong);
playbackmanager.stop(isSummendByPlay?discordClient.user.client.voice.connections.first():undefined); playbackmanager.stop(isSummendByPlay ? discordClient.user.client.voice.connections.first() : undefined);
return; return;
} }
} }
@ -182,7 +181,7 @@ function handleChannelMessage (message) {
const indexOfArgument = message.content.indexOf(CONFIG["discord-prefix"] + "seek") + (CONFIG["discord-prefix"] + "seek").length + 1; const indexOfArgument = message.content.indexOf(CONFIG["discord-prefix"] + "seek") + (CONFIG["discord-prefix"] + "seek").length + 1;
const argument = message.content.slice(indexOfArgument); const argument = message.content.slice(indexOfArgument);
try { try {
playbackmanager.seek(hmsToSeconds(argument)*10000000); playbackmanager.seek(hmsToSeconds(argument) * 10000000);
} catch (error) { } catch (error) {
const errorMessage = getDiscordEmbedError(error); const errorMessage = getDiscordEmbedError(error);
message.channel.send(errorMessage); message.channel.send(errorMessage);

View File

@ -52,7 +52,7 @@ function seek (toSeek = 0) {
if (getAudioDispatcher()) { if (getAudioDispatcher()) {
startPlaying(undefined, undefined, ticksToSeconds(toSeek), _disconnectOnFinish); startPlaying(undefined, undefined, ticksToSeconds(toSeek), _disconnectOnFinish);
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
}else{ } else {
throw Error("No Song Playing"); throw Error("No Song Playing");
} }
} }

View File

@ -7,16 +7,16 @@ function ticksToSeconds (ticks) {
return ticks / 10000000; return ticks / 10000000;
} }
function hmsToSeconds(str) { function hmsToSeconds (str) {
var p = str.split(':'), var p = str.split(":");
s = 0, m = 1; var s = 0; var m = 1;
while (p.length > 0) { while (p.length > 0) {
s += m * parseInt(p.pop(), 10); s += m * parseInt(p.pop(), 10);
m *= 60; m *= 60;
} }
return s; return s;
} }
module.exports = { module.exports = {