implement basic debug logging

This commit is contained in:
KGT1 2021-01-18 06:49:32 +01:00
parent fb38c2b37d
commit f75b978dd8
5 changed files with 18 additions and 1 deletions

View File

@ -5,5 +5,6 @@
"jellyfin-password":"",
"discord-prefix":"?",
"jellyfin-app-name":"Jellyfin Discord Music Bot",
"interactive-seek-bar-update-intervall":2000
"interactive-seek-bar-update-intervall":2000,
"log-level":"info"
}

View File

@ -28,6 +28,7 @@
"@discordjs/opus": "^0.3.2",
"discord.js": "^12.3.1",
"jellyfin-apiclient": "1.4.1",
"loglevel": "^1.7.1",
"node-fetch": "^2.6.0",
"nodejs": "0.0.0",
"window": "^4.2.7",

View File

@ -9,6 +9,7 @@ if (process.env.JELLYFIN_USERNAME) { configfile["jellyfin-username"] = process.e
if (process.env.JELLYFIN_PASSWORD) { configfile["jellyfin-password"] = process.env.JELLYFIN_PASSWORD; }
if (process.env.JELLYFIN_APP_NAME) { configfile["jellyfin-app-name"] = process.env.JELLYFIN_APP_NAME; }
if (process.env.MESSAGE_UPDATE_INTERVAL) { configfile["interactive-seek-bar-update-intervall"] = parseInt(process.env.MESSAGE_UPDATE_INTERVAL); }
if (process.env.LOG_LEVEL) { configfile["log-level"] = process.env.LOG_LEVEL; }
fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => {
if (err) return console.error(err);

View File

@ -9,6 +9,9 @@ try {
const {
handleChannelMessage
} = require("./messagehandler");
const log = require("loglevel");
log.setLevel(CONFIG["log-level"]);
jellyfinClientManager.init();
// TODO Error Checking as the apiclients is inefficent

View File

@ -2,6 +2,8 @@
const interactivemsghandler = require("./interactivemsghandler");
const CONFIG = require("../config.json");
const discordclientmanager = require("./discordclientmanager");
const log = require("loglevel");
const {
getAudioDispatcher,
setAudioDispatcher
@ -29,6 +31,7 @@ function streamURLbuilder (itemID, bitrate) {
}
function startPlaying (voiceconnection = discordclientmanager.getDiscordClient().user.client.voice.connections.first(), itemIDPlaylist = currentPlayingPlaylist, playlistIndex = currentPlayingPlaylistIndex, seekTo, disconnectOnFinish = _disconnectOnFinish) {
log.debug("start playing ",playlistIndex, ". of list: ",itemIDPlaylist," in a voiceconnection?: ", voiceconnection=!undefined);
isPaused = false;
currentPlayingPlaylist = itemIDPlaylist;
currentPlayingPlaylistIndex = playlistIndex;
@ -74,6 +77,7 @@ function startPlaying (voiceconnection = discordclientmanager.getDiscordClient()
}
async function spawnPlayMessage (message) {
log.debug("spawned Play Message: ",message);
const itemIdDetails = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), getItemId());
const imageURL = await jellyfinClientManager.getJellyfinClient().getImageUrl(itemIdDetails.AlbumId || getItemId(), { type: "Primary" });
try {
@ -107,6 +111,7 @@ async function updatePlayMessage () {
* @param {Number} toSeek - where to seek in ticks
*/
function seek (toSeek = 0) {
log.debug("seek to: ", toSeek);
if (getAudioDispatcher()) {
startPlaying(undefined, undefined, undefined, ticksToSeconds(toSeek), _disconnectOnFinish);
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
@ -119,10 +124,12 @@ function seek (toSeek = 0) {
* @param {Array} itemID - array of itemIDs to be added
*/
function addTracks (itemID) {
log.debug("added track: ",itemID);
currentPlayingPlaylist = currentPlayingPlaylist.concat(itemID);
}
function nextTrack () {
log.debug("nextTrack");
if (!(currentPlayingPlaylist)) {
throw Error("There is currently nothing playing");
} else if (currentPlayingPlaylistIndex + 1 >= currentPlayingPlaylist.length) {
@ -134,6 +141,7 @@ function nextTrack () {
}
function previousTrack () {
log.debug("previousTrack");
if (ticksToSeconds(getPostitionTicks()) < 10) {
if (!(currentPlayingPlaylist)) {
throw Error("There is currently nothing playing");
@ -151,6 +159,7 @@ function previousTrack () {
* @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from
*/
function stop (disconnectVoiceConnection, itemId = getItemId()) {
log.debug("stop playback and send following payload to the server: ",getStopPayload());
isPaused = true;
if (interactivemsghandler.hasMessage()) {
interactivemsghandler.destroy();
@ -170,12 +179,14 @@ function stop (disconnectVoiceConnection, itemId = getItemId()) {
}
function pause () {
log.debug("pause");
isPaused = true;
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
getAudioDispatcher().pause(true);
}
function resume () {
log.debug("resume");
isPaused = false;
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
getAudioDispatcher().resume();