discord-jellyfin-bot/src/interactivemsghandler.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-09-25 13:11:13 +02:00
const InterActivePlayMessage = require("./InterActivePlayMessage");
2020-09-30 17:27:09 +02:00
const CONFIG = require("../config.json");
2020-09-25 13:11:13 +02:00
var iapm;
2020-09-30 17:27:09 +02:00
var updateInterval;
function init (message, title, artist, imageURL, itemURL, getProgress, onPrevious, onPausePlay, onStop, onNext, onRepeat, playlistLenth) {
2020-09-25 13:11:13 +02:00
if (typeof iapm !== "undefined") {
destroy();
}
2020-09-30 17:27:09 +02:00
iapm = new InterActivePlayMessage(message, title, artist, imageURL, itemURL, getProgress, onPrevious, onPausePlay, onStop, onNext, onRepeat, playlistLenth);
2020-09-25 13:11:13 +02:00
}
function destroy () {
if (typeof iapm !== "undefined") {
iapm.destroy();
iapm = undefined;
} else {
throw Error("No Interactive Message Found");
}
2020-09-30 17:27:09 +02:00
if (updateInterval !== "undefined") {
clearInterval(updateInterval);
updateInterval = undefined;
}
2020-09-25 13:11:13 +02:00
}
function hasMessage () {
if (typeof iapm === "undefined") {
return false;
} else {
return true;
}
}
2020-09-30 17:27:09 +02:00
/**
*
* @param {Function} callback function to retrieve current ticks
*/
function startUpate (callback) {
2020-10-06 00:47:26 +02:00
if (typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" && CONFIG["interactive-seek-bar-update-intervall"] > 0) {
2020-10-05 23:22:31 +02:00
updateInterval = setInterval(() => {
iapm.updateProgress(callback());
}, CONFIG["interactive-seek-bar-update-intervall"]);
}
2020-09-30 17:27:09 +02:00
}
function updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) {
2020-09-30 17:37:26 +02:00
if (typeof iapm !== "undefined") {
iapm.updateCurrentSongMessage(title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth);
} else {
throw Error("No Interactive Message Found");
}
2020-09-30 17:27:09 +02:00
}
2020-09-25 13:11:13 +02:00
module.exports = {
init,
destroy,
2020-09-30 17:27:09 +02:00
hasMessage,
startUpate,
updateCurrentSongMessage
2020-09-25 13:11:13 +02:00
};