mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
add add command
This commit is contained in:
parent
5843a15faf
commit
41434ec805
@ -53,13 +53,11 @@ async function searchForItemID (searchString) {
|
|||||||
if (response.TotalRecordCount < 1) {
|
if (response.TotalRecordCount < 1) {
|
||||||
throw Error("Found nothing");
|
throw Error("Found nothing");
|
||||||
} else {
|
} else {
|
||||||
console.log(response);
|
|
||||||
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":
|
||||||
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 resp = await jellyfinClientManager.getJellyfinClient().getItems(jellyfinClientManager.getJellyfinClient().getCurrentUserId(),{sortBy:"SortName", sortOrder:"Ascending",parentId:response.SearchHints[0].ItemId});
|
||||||
let itemArray = [];
|
let itemArray = [];
|
||||||
resp.Items.forEach(element => {
|
resp.Items.forEach(element => {
|
||||||
@ -97,14 +95,14 @@ function summonMessage (message) {
|
|||||||
async function playThis (message) {
|
async function playThis (message) {
|
||||||
const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1;
|
const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1;
|
||||||
const argument = message.content.slice(indexOfItemID);
|
const argument = message.content.slice(indexOfItemID);
|
||||||
let itemID;
|
let items;
|
||||||
// check if play command was used with itemID
|
// check if play command was used with itemID
|
||||||
const regexresults = checkJellyfinItemIDRegex(argument);
|
const regexresults = checkJellyfinItemIDRegex(argument);
|
||||||
if (regexresults) {
|
if (regexresults) {
|
||||||
itemID = regexresults;
|
items = regexresults;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
itemID = await searchForItemID(argument);
|
items = await searchForItemID(argument);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const noSong = getDiscordEmbedError(e);
|
const noSong = getDiscordEmbedError(e);
|
||||||
message.channel.send(noSong);
|
message.channel.send(noSong);
|
||||||
@ -113,10 +111,30 @@ async function playThis (message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
discordClient.user.client.voice.connections.forEach((element) => {
|
playbackmanager.startPlaying(discordClient.user.client.voice.connections.first(), items, 0, 0, isSummendByPlay);
|
||||||
playbackmanager.startPlaying(element, itemID, 0, 0, isSummendByPlay);
|
playbackmanager.spawnPlayMessage(message);
|
||||||
playbackmanager.spawnPlayMessage(message);
|
}
|
||||||
});
|
|
||||||
|
async function addThis (message) {
|
||||||
|
const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "add") + (CONFIG["discord-prefix"] + "add").length + 1;
|
||||||
|
const argument = message.content.slice(indexOfItemID);
|
||||||
|
let items;
|
||||||
|
// check if play command was used with itemID
|
||||||
|
const regexresults = checkJellyfinItemIDRegex(argument);
|
||||||
|
if (regexresults) {
|
||||||
|
items = regexresults;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
items = await searchForItemID(argument);
|
||||||
|
console.log(items);
|
||||||
|
} catch (e) {
|
||||||
|
const noSong = getDiscordEmbedError(e);
|
||||||
|
message.channel.send(noSong);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playbackmanager.addTracks(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChannelMessage (message) {
|
function handleChannelMessage (message) {
|
||||||
@ -188,12 +206,7 @@ function handleChannelMessage (message) {
|
|||||||
} 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 indexOfArgument = message.content.indexOf(CONFIG["discord-prefix"] + "add") + (CONFIG["discord-prefix"] + "add").length + 1;
|
||||||
const argument = message.content.slice(indexOfArgument);
|
const argument = message.content.slice(indexOfArgument);
|
||||||
try {
|
addThis(message);
|
||||||
playbackmanager.addTrack(argument);
|
|
||||||
} catch (error) {
|
|
||||||
const errorMessage = getDiscordEmbedError(error);
|
|
||||||
message.channel.send(errorMessage);
|
|
||||||
}
|
|
||||||
} 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)
|
||||||
@ -215,6 +228,9 @@ function handleChannelMessage (message) {
|
|||||||
}, {
|
}, {
|
||||||
name: `${CONFIG["discord-prefix"]}play`,
|
name: `${CONFIG["discord-prefix"]}play`,
|
||||||
value: "Play the following item"
|
value: "Play the following item"
|
||||||
|
}, {
|
||||||
|
name: `${CONFIG["discord-prefix"]}add`,
|
||||||
|
value: "Add the following item to the current playlist"
|
||||||
}, {
|
}, {
|
||||||
name: `${CONFIG["discord-prefix"]}pause/resume`,
|
name: `${CONFIG["discord-prefix"]}pause/resume`,
|
||||||
value: "Pause/Resume audio"
|
value: "Pause/Resume audio"
|
||||||
|
@ -80,7 +80,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,
|
()=>{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);
|
||||||
@ -91,10 +91,13 @@ async function spawnPlayMessage (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updatePlayMessage () {
|
async function updatePlayMessage () {
|
||||||
const itemIdDetails = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), getItemId());
|
if(getItemId()!==undefined){
|
||||||
const imageURL = await jellyfinClientManager.getJellyfinClient().getImageUrl(itemIdDetails.AlbumId, { type: "Primary" });
|
const itemIdDetails = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), getItemId());
|
||||||
interactivemsghandler.updateCurrentSongMessage(itemIdDetails.Name, itemIdDetails.Artists[0] || "VA", imageURL,
|
const imageURL = await jellyfinClientManager.getJellyfinClient().getImageUrl(itemIdDetails.AlbumId, { type: "Primary" });
|
||||||
`${jellyfinClientManager.getJellyfinClient().serverAddress()}/web/index.html#!/details?id=${itemIdDetails.AlbumId}`, itemIdDetails.RunTimeTicks, currentPlayingPlaylistIndex + 1, currentPlayingPlaylist.length);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,9 +111,12 @@ function seek (toSeek = 0) {
|
|||||||
throw Error("No Song Playing");
|
throw Error("No Song Playing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
function addTrack (itemID) {
|
*
|
||||||
currentPlayingPlaylist.push(itemID);
|
* @param {Array} itemID - array of itemIDs to be added
|
||||||
|
*/
|
||||||
|
function addTracks (itemID) {
|
||||||
|
currentPlayingPlaylist=currentPlayingPlaylist.concat(itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextTrack () {
|
function nextTrack () {
|
||||||
@ -235,6 +241,7 @@ function getItemId () {
|
|||||||
if (typeof currentPlayingPlaylist !== "undefined") {
|
if (typeof currentPlayingPlaylist !== "undefined") {
|
||||||
return currentPlayingPlaylist[currentPlayingPlaylistIndex];
|
return currentPlayingPlaylist[currentPlayingPlaylistIndex];
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIsPaused () {
|
function getIsPaused () {
|
||||||
@ -253,6 +260,7 @@ function setIsRepeat (arg) {
|
|||||||
isRepeat = !isRepeat;
|
isRepeat = !isRepeat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("img being called and setting",arg,isRepeat);
|
||||||
isRepeat = arg;
|
isRepeat = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +293,7 @@ module.exports = {
|
|||||||
setIsRepeat,
|
setIsRepeat,
|
||||||
nextTrack,
|
nextTrack,
|
||||||
previousTrack,
|
previousTrack,
|
||||||
addTrack,
|
addTracks,
|
||||||
getPostitionTicks,
|
getPostitionTicks,
|
||||||
spawnPlayMessage
|
spawnPlayMessage
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user