This commit is contained in:
KGT1 2020-09-24 13:37:17 +02:00
parent e019f4c6e5
commit 0fe1c80f88
3 changed files with 48 additions and 61 deletions

View File

@ -3,9 +3,6 @@ const Discord = require("discord.js");
const { const {
checkJellyfinItemIDRegex checkJellyfinItemIDRegex
} = require("./util"); } = require("./util");
const {
getAudioDispatcher
} = require("./dispachermanager");
const { const {
hmsToSeconds hmsToSeconds
} = require("./util"); } = require("./util");
@ -20,7 +17,7 @@ var isSummendByPlay = false;
// random Color of the Jellyfin Logo Gradient // random Color of the Jellyfin Logo Gradient
function getRandomDiscordColor () { function getRandomDiscordColor () {
let random = Math.random(); const random = Math.random();
function randomNumber (b, a) { function randomNumber (b, a) {
return Math.floor(random * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b); return Math.floor(random * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b);
} }
@ -186,7 +183,7 @@ function handleChannelMessage (message) {
} }
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "skip")) { } else if (message.content.startsWith(CONFIG["discord-prefix"] + "skip")) {
try { try {
playbackmanager.nextTrack() playbackmanager.nextTrack();
} catch (error) { } catch (error) {
const errorMessage = getDiscordEmbedError(error); const errorMessage = getDiscordEmbedError(error);
message.channel.send(errorMessage); message.channel.send(errorMessage);

View File

@ -7,7 +7,6 @@ const {
ticksToSeconds ticksToSeconds
} = require("./util"); } = require("./util");
// this whole thing should be a class but its probably too late now. // this whole thing should be a class but its probably too late now.
var currentPlayingPlaylist; var currentPlayingPlaylist;
@ -52,16 +51,13 @@ function startPlaying(voiceconnection = discordclientmanager.getDiscordClient().
getAudioDispatcher().on("finish", () => { getAudioDispatcher().on("finish", () => {
if (currentPlayingPlaylist.length < playlistIndex) { if (currentPlayingPlaylist.length < playlistIndex) {
console.log("PLAYLIST END")
if (disconnectOnFinish) { if (disconnectOnFinish) {
stop(voiceconnection, currentPlayingPlaylist[playlistIndex - 1]); stop(voiceconnection, currentPlayingPlaylist[playlistIndex - 1]);
} else { } else {
stop(undefined, currentPlayingPlaylist[playlistIndex - 1]); stop(undefined, currentPlayingPlaylist[playlistIndex - 1]);
} }
} else { } else {
startPlaying(voiceconnection, itemIDPlaylist, currentPlayingPlaylistIndex+1, 0) startPlaying(voiceconnection, itemIDPlaylist, currentPlayingPlaylistIndex + 1, 0);
} }
}); });
} }
@ -88,19 +84,18 @@ function nextTrack(){
} else if (currentPlayingPlaylistIndex + 1 >= currentPlayingPlaylist.length) { } else if (currentPlayingPlaylistIndex + 1 >= currentPlayingPlaylist.length) {
throw Error("This is the Last song"); throw Error("This is the Last song");
} }
startPlaying(undefined, undefined, currentPlayingPlaylistIndex + 1, 0, _disconnectOnFinish) startPlaying(undefined, undefined, currentPlayingPlaylistIndex + 1, 0, _disconnectOnFinish);
} }
function previousTrack () { function previousTrack () {
if (ticksToSeconds(getPostitionTicks()) < 10) { if (ticksToSeconds(getPostitionTicks()) < 10) {
console.log(currentPlayingPlaylistIndex , currentPlayingPlaylist.length);
if (!(currentPlayingPlaylist)) { if (!(currentPlayingPlaylist)) {
throw Error("There is currently nothing playing"); throw Error("There is currently nothing playing");
} else if (currentPlayingPlaylistIndex - 1 < 0) { } else if (currentPlayingPlaylistIndex - 1 < 0) {
startPlaying(undefined, undefined, currentPlayingPlaylistIndex, 0, _disconnectOnFinish) startPlaying(undefined, undefined, currentPlayingPlaylistIndex, 0, _disconnectOnFinish);
throw Error("This is the First song"); throw Error("This is the First song");
} }
startPlaying(undefined, undefined, currentPlayingPlaylistIndex - 1, 0, _disconnectOnFinish) startPlaying(undefined, undefined, currentPlayingPlaylistIndex - 1, 0, _disconnectOnFinish);
} }
} }
@ -108,8 +103,6 @@ function previousTrack(){
* @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from * @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from
*/ */
function stop (disconnectVoiceConnection, itemId = getItemId()) { function stop (disconnectVoiceConnection, itemId = getItemId()) {
console.log("im getting called");
console
isPaused = true; isPaused = true;
if (disconnectVoiceConnection) { if (disconnectVoiceConnection) {
disconnectVoiceConnection.disconnect(); disconnectVoiceConnection.disconnect();
@ -151,7 +144,6 @@ function playPause() {
function getPostitionTicks () { function getPostitionTicks () {
// this is very sketchy but i dont know how else to do it // this is very sketchy but i dont know how else to do it
console.log((_seek + getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000);
return (_seek + getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000; return (_seek + getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000;
} }

View File

@ -12,7 +12,6 @@ function openSocket () {
} }
); );
jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => { jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => {
console.log(data);
if (data.MessageType === "Play") { if (data.MessageType === "Play") {
if (data.Data.PlayCommand === "PlayNow") { if (data.Data.PlayCommand === "PlayNow") {
playbackmanager.startPlaying(undefined, data.Data.ItemIds, data.Data.StartIndex || 0, 0, false); playbackmanager.startPlaying(undefined, data.Data.ItemIds, data.Data.StartIndex || 0, 0, false);
@ -24,7 +23,7 @@ function openSocket () {
playbackmanager.stop(); playbackmanager.stop();
} else if (data.Data.Command === "Seek") { } else if (data.Data.Command === "Seek") {
// because the server sends seek an privious track at same time so i have to do timing // because the server sends seek an privious track at same time so i have to do timing
setTimeout(async()=>{playbackmanager.seek(data.Data.SeekPositionTicks);},20) setTimeout(async () => { playbackmanager.seek(data.Data.SeekPositionTicks); }, 20);
} else if (data.Data.Command === "NextTrack") { } else if (data.Data.Command === "NextTrack") {
try { try {
playbackmanager.nextTrack(); playbackmanager.nextTrack();
@ -33,7 +32,6 @@ function openSocket () {
} }
} else if (data.Data.Command === "PreviousTrack") { } else if (data.Data.Command === "PreviousTrack") {
try { try {
console.log(ticksToSeconds(playbackmanager.getPostitionTicks())<10,ticksToSeconds(playbackmanager.getPostitionTicks()),` (${playbackmanager.getPostitionTicks()})`," < ",10)
if (ticksToSeconds(playbackmanager.getPostitionTicks()) < 10) { if (ticksToSeconds(playbackmanager.getPostitionTicks()) < 10) {
playbackmanager.previousTrack(); playbackmanager.previousTrack();
} }