diff --git a/src/InterActivePlayMessage.js b/src/InterActivePlayMessage.js index 8d9c4c2..4728fb7 100644 --- a/src/InterActivePlayMessage.js +++ b/src/InterActivePlayMessage.js @@ -34,7 +34,7 @@ function getMaxWidthString (string) { class InterActivePlayMessage { // musicplayermessage - // probably should have done events instead of. + // probably should have done events instead of callbacks /** * * @param {Object} message @@ -125,14 +125,17 @@ class InterActivePlayMessage { } updateProgress (ticks) { - this.musicplayermessage.embeds[0].fields[0] = { - name: getProgressString(ticks / this.ticksLength), - value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`, - inline: false - }; + if(typeof this.musicplayermessage !== "undefined" && typeof this.musicplayermessage.embeds[0] !== "undefined" && typeof this.musicplayermessage.embeds[0].fields[0] !== "undefined"){ - this.musicplayermessage.timestamp = new Date(); - this.musicplayermessage.edit(this.musicplayermessage.embeds[0]); + this.musicplayermessage.embeds[0].fields[0] = { + name: getProgressString(ticks / this.ticksLength), + value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`, + inline: false + }; + + this.musicplayermessage.timestamp = new Date(); + this.musicplayermessage.edit(this.musicplayermessage.embeds[0]); + } } updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) { diff --git a/src/interactivemsghandler.js b/src/interactivemsghandler.js index b86f886..7655954 100644 --- a/src/interactivemsghandler.js +++ b/src/interactivemsghandler.js @@ -38,9 +38,11 @@ function hasMessage () { * @param {Function} callback function to retrieve current ticks */ function startUpate (callback) { - updateInterval = setInterval(() => { - iapm.updateProgress(callback()); - }, CONFIG["interactive-seek-bar-update-intervall"]); + if(typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" && CONFIG["interactive-seek-bar-update-intervall"] > 0){ + updateInterval = setInterval(() => { + iapm.updateProgress(callback()); + }, CONFIG["interactive-seek-bar-update-intervall"]); + } } function updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) { diff --git a/src/messagehandler.js b/src/messagehandler.js index b192fb7..38504d7 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -47,13 +47,26 @@ function getRandomDiscordColor () { async function searchForItemID (searchString) { const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ searchTerm: searchString, - includeItemTypes: "Audio" + includeItemTypes: "Audio,MusicAlbum,Playlist" }); if (response.TotalRecordCount < 1) { - throw Error("Found no Song"); + throw Error("Found nothing"); } else { - return response.SearchHints[0].ItemId; + console.log(response); + switch(response.SearchHints[0].Type){ + case "Audio": + return [response.SearchHints[0].ItemId]; + case "Playlist": + case "MusicAlbum": + console.log("Hey its a Music Album") + let resp = await jellyfinClientManager.getJellyfinClient().getItems(jellyfinClientManager.getJellyfinClient().getCurrentUserId(),{sortBy:"SortName", sortOrder:"Ascending",parentId:response.SearchHints[0].ItemId}); + let itemArray = []; + resp.Items.forEach(element => { + itemArray.push(element.Id) + }); + return itemArray; + } } } @@ -88,7 +101,7 @@ async function playThis (message) { // check if play command was used with itemID const regexresults = checkJellyfinItemIDRegex(argument); if (regexresults) { - itemID = regexresults[0]; + itemID = regexresults; } else { try { itemID = await searchForItemID(argument); @@ -101,7 +114,7 @@ async function playThis (message) { } discordClient.user.client.voice.connections.forEach((element) => { - playbackmanager.startPlaying(element, [itemID], 0, 0, isSummendByPlay); + playbackmanager.startPlaying(element, itemID, 0, 0, isSummendByPlay); playbackmanager.spawnPlayMessage(message); }); }