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,8 +125,7 @@ class InterActivePlayMessage {
} }
updateProgress (ticks) { 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] = { this.musicplayermessage.embeds[0].fields[0] = {
name: getProgressString(ticks / this.ticksLength), name: getProgressString(ticks / this.ticksLength),
value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`, value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`,

View File

@ -38,7 +38,7 @@ function hasMessage () {
* @param {Function} callback function to retrieve current ticks * @param {Function} callback function to retrieve current ticks
*/ */
function startUpate (callback) { 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(() => { updateInterval = setInterval(() => {
iapm.updateProgress(callback()); iapm.updateProgress(callback());
}, CONFIG["interactive-seek-bar-update-intervall"]); }, CONFIG["interactive-seek-bar-update-intervall"]);

View File

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

View File

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