This commit is contained in:
KGT1 2020-10-06 00:47:26 +02:00
parent 927049f9a4
commit 9ec2d2aa73
4 changed files with 34 additions and 38 deletions

View File

@ -125,14 +125,13 @@ class InterActivePlayMessage {
}
updateProgress (ticks) {
if(typeof this.musicplayermessage !== "undefined" && typeof this.musicplayermessage.embeds[0] !== "undefined" && typeof this.musicplayermessage.embeds[0].fields[0] !== "undefined"){
if (typeof this.musicplayermessage !== "undefined" && typeof this.musicplayermessage.embeds[0] !== "undefined" && typeof this.musicplayermessage.embeds[0].fields[0] !== "undefined") {
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]);
}

View File

@ -38,7 +38,7 @@ function hasMessage () {
* @param {Function} callback function to retrieve current ticks
*/
function startUpate (callback) {
if(typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" && CONFIG["interactive-seek-bar-update-intervall"] > 0){
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"]);

View File

@ -53,17 +53,18 @@ async function searchForItemID (searchString) {
if (response.TotalRecordCount < 1) {
throw Error("Found nothing");
} else {
switch(response.SearchHints[0].Type){
case "Audio":
return [response.SearchHints[0].ItemId];
case "Playlist":
case "MusicAlbum":
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;
switch (response.SearchHints[0].Type) {
case "Audio":
return [response.SearchHints[0].ItemId];
case "Playlist":
case "MusicAlbum": {
const resp = await jellyfinClientManager.getJellyfinClient().getItems(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), { sortBy: "SortName", sortOrder: "Ascending", parentId: response.SearchHints[0].ItemId });
const itemArray = [];
resp.Items.forEach(element => {
itemArray.push(element.Id);
});
return itemArray;
}
}
}
}
@ -126,14 +127,13 @@ async function addThis (message) {
} else {
try {
items = await searchForItemID(argument);
console.log(items);
} catch (e) {
const noSong = getDiscordEmbedError(e);
message.channel.send(noSong);
return;
}
}
playbackmanager.addTracks(items);
}
@ -204,12 +204,10 @@ function handleChannelMessage (message) {
message.channel.send(errorMessage);
}
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "add")) {
const indexOfArgument = message.content.indexOf(CONFIG["discord-prefix"] + "add") + (CONFIG["discord-prefix"] + "add").length + 1;
const argument = message.content.slice(indexOfArgument);
addThis(message);
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "spawn")) {
try {
playbackmanager.spawnPlayMessage(message)
playbackmanager.spawnPlayMessage(message);
} catch (error) {
const errorMessage = getDiscordEmbedError(error);
message.channel.send(errorMessage);

View File

@ -53,18 +53,19 @@ function startPlaying (voiceconnection = discordclientmanager.getDiscordClient()
}
getAudioDispatcher().on("finish", () => {
if(isRepeat){
startPlaying(voiceconnection,undefined,currentPlayingPlaylistIndex,0)
}else{
if (currentPlayingPlaylist.length < playlistIndex) {
if (disconnectOnFinish) {
stop(voiceconnection, currentPlayingPlaylist[playlistIndex - 1]);
} else {
stop(undefined, currentPlayingPlaylist[playlistIndex - 1]);
}
if (isRepeat) {
startPlaying(voiceconnection, undefined, currentPlayingPlaylistIndex, 0);
} else {
startPlaying(voiceconnection, undefined, currentPlayingPlaylistIndex + 1, 0);
}}
if (currentPlayingPlaylist.length < playlistIndex) {
if (disconnectOnFinish) {
stop(voiceconnection, currentPlayingPlaylist[playlistIndex - 1]);
} else {
stop(undefined, currentPlayingPlaylist[playlistIndex - 1]);
}
} else {
startPlaying(voiceconnection, undefined, currentPlayingPlaylistIndex + 1, 0);
}
}
});
}
playasync().catch((rsn) => {
@ -83,7 +84,7 @@ async function spawnPlayMessage (message) {
playPause,
() => { stop(_disconnectOnFinish ? discordclientmanager.getDiscordClient().user.client.voice.connections.first() : undefined); },
nextTrack,
()=>{setIsRepeat(!isRepeat)},
() => { setIsRepeat(!isRepeat); },
currentPlayingPlaylist.length);
if (typeof CONFIG["interactive-seek-bar-update-intervall"] === "number") {
interactivemsghandler.startUpate(getPostitionTicks);
@ -94,12 +95,11 @@ async function spawnPlayMessage (message) {
}
async function updatePlayMessage () {
if(getItemId()!==undefined){
if (getItemId() !== undefined) {
const itemIdDetails = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), getItemId());
const imageURL = await jellyfinClientManager.getJellyfinClient().getImageUrl(itemIdDetails.AlbumId, { type: "Primary" });
interactivemsghandler.updateCurrentSongMessage(itemIdDetails.Name, itemIdDetails.Artists[0] || "VA", imageURL,
`${jellyfinClientManager.getJellyfinClient().serverAddress()}/web/index.html#!/details?id=${itemIdDetails.AlbumId}`, itemIdDetails.RunTimeTicks, currentPlayingPlaylistIndex + 1, currentPlayingPlaylist.length);
}
}
@ -115,11 +115,11 @@ function seek (toSeek = 0) {
}
}
/**
*
* @param {Array} itemID - array of itemIDs to be added
*
* @param {Array} itemID - array of itemIDs to be added
*/
function addTracks (itemID) {
currentPlayingPlaylist=currentPlayingPlaylist.concat(itemID);
currentPlayingPlaylist = currentPlayingPlaylist.concat(itemID);
}
function nextTrack () {
@ -263,7 +263,6 @@ function setIsRepeat (arg) {
isRepeat = !isRepeat;
}
}
console.log("img being called and setting",arg,isRepeat);
isRepeat = arg;
}