mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
add seek command + update README
This commit is contained in:
parent
f905d65973
commit
db6638724c
@ -14,12 +14,12 @@ summon | Join the channel the author of the message(now you can cast to the Bot
|
|||||||
disconnect | Disconnect from all current Voice Channels
|
disconnect | Disconnect from all current Voice Channels
|
||||||
play | Play the following item(can be the name of the song or the Stream URL)
|
play | Play the following item(can be the name of the song or the Stream URL)
|
||||||
pause/resume | Pause/Resume audio
|
pause/resume | Pause/Resume audio
|
||||||
|
seek | Where to Seek to in seconds or MM:SS
|
||||||
help | Display the help message
|
help | Display the help message
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
||||||
- Playlist (soon)
|
- Playlist (soon)
|
||||||
- Seek to functionality (soon)
|
|
||||||
- [Playing Video Content](https://support.discord.com/hc/en-us/community/posts/360059238512-Add-Go-Live-support-for-API) (if Discord ever adds this, I'll implement it into this Bot)
|
- [Playing Video Content](https://support.discord.com/hc/en-us/community/posts/360059238512-Add-Go-Live-support-for-API) (if Discord ever adds this, I'll implement it into this Bot)
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
@ -6,6 +6,9 @@ const {
|
|||||||
const {
|
const {
|
||||||
getAudioDispatcher
|
getAudioDispatcher
|
||||||
} = require("./dispachermanager");
|
} = require("./dispachermanager");
|
||||||
|
const {
|
||||||
|
hmsToSeconds
|
||||||
|
} = require("./util");
|
||||||
|
|
||||||
const discordclientmanager = require("./discordclientmanager");
|
const discordclientmanager = require("./discordclientmanager");
|
||||||
const jellyfinClientManager = require("./jellyfinclientmanager");
|
const jellyfinClientManager = require("./jellyfinclientmanager");
|
||||||
@ -41,6 +44,15 @@ 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){
|
||||||
|
return new Discord.MessageEmbed()
|
||||||
|
.setColor(0xff0000)
|
||||||
|
.setTitle("Error!")
|
||||||
|
.setTimestamp()
|
||||||
|
.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({
|
||||||
@ -100,11 +112,7 @@ async function playThis (message) {
|
|||||||
try {
|
try {
|
||||||
itemID = await searchForItemID(argument);
|
itemID = await searchForItemID(argument);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const noSong = new Discord.MessageEmbed()
|
const noSong = getDiscordEmbedError(e);
|
||||||
.setColor(0xff0000)
|
|
||||||
.setTitle("Error!")
|
|
||||||
.setTimestamp()
|
|
||||||
.setDescription("<:x:757935515445231651> " + 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;
|
||||||
@ -170,6 +178,15 @@ function handleChannelMessage (message) {
|
|||||||
} else {
|
} else {
|
||||||
playbackmanager.stop();
|
playbackmanager.stop();
|
||||||
}
|
}
|
||||||
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "seek")) {
|
||||||
|
const indexOfArgument = message.content.indexOf(CONFIG["discord-prefix"] + "seek") + (CONFIG["discord-prefix"] + "seek").length + 1;
|
||||||
|
const argument = message.content.slice(indexOfArgument);
|
||||||
|
try {
|
||||||
|
playbackmanager.seek(hmsToSeconds(argument)*10000000);
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = getDiscordEmbedError(error);
|
||||||
|
message.channel.send(errorMessage);
|
||||||
|
}
|
||||||
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) {
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) {
|
||||||
/* eslint-disable quotes */
|
/* eslint-disable quotes */
|
||||||
const reply = new Discord.MessageEmbed()
|
const reply = new Discord.MessageEmbed()
|
||||||
@ -187,6 +204,9 @@ function handleChannelMessage (message) {
|
|||||||
}, {
|
}, {
|
||||||
name: `${CONFIG["discord-prefix"]}pause/resume`,
|
name: `${CONFIG["discord-prefix"]}pause/resume`,
|
||||||
value: "Pause/Resume audio"
|
value: "Pause/Resume audio"
|
||||||
|
}, {
|
||||||
|
name: `${CONFIG["discord-prefix"]}seek`,
|
||||||
|
value: "Where to Seek to in seconds or MM:SS"
|
||||||
}, {
|
}, {
|
||||||
name: `${CONFIG["discord-prefix"]}help`,
|
name: `${CONFIG["discord-prefix"]}help`,
|
||||||
value: "Display this help message"
|
value: "Display this help message"
|
||||||
|
@ -52,6 +52,8 @@ 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{
|
||||||
|
throw Error("No Song Playing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/util.js
15
src/util.js
@ -7,7 +7,20 @@ function ticksToSeconds (ticks) {
|
|||||||
return ticks / 10000000;
|
return ticks / 10000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hmsToSeconds(str) {
|
||||||
|
var p = str.split(':'),
|
||||||
|
s = 0, m = 1;
|
||||||
|
|
||||||
|
while (p.length > 0) {
|
||||||
|
s += m * parseInt(p.pop(), 10);
|
||||||
|
m *= 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkJellyfinItemIDRegex,
|
checkJellyfinItemIDRegex,
|
||||||
ticksToSeconds
|
ticksToSeconds,
|
||||||
|
hmsToSeconds
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user