diff --git a/src/commands/player/filters.js b/src/commands/player/filters.js index 3f2b9ab..0db125b 100644 --- a/src/commands/player/filters.js +++ b/src/commands/player/filters.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions, ffmpegFilterOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); @@ -77,6 +78,7 @@ module.exports = { ], components: [filterActionRow, disableFiltersActionRow] }); + logger.debug(`Sent embed for command ${interaction.commandName}, awaiting interaction response.`); const collectorFilter = (i) => i.user.id === interaction.user.id; try { @@ -85,6 +87,8 @@ module.exports = { time: 60000 }); + logger.debug(`Received interaction response for command ${interaction.commandName}.`); + confirmation.deferUpdate(); queue.filters.ffmpeg.setInputArgs([ @@ -124,6 +128,8 @@ module.exports = { // Enable provided filters queue.filters.ffmpeg.toggle(confirmation.values); + logger.debug(`Enabled filters ${confirmation.values.join(', ')} for command ${interaction.commandName}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -149,12 +155,17 @@ module.exports = { ], components: [] }); - } catch (e) { - if (e.code === 'InteractionCollectorError') { + } catch (error) { + if (error.code === 'InteractionCollectorError') { + logger.debug(`Interaction response timed out for command ${interaction.commandName}.`); return; } - throw e; + logger.debug( + error, + `Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.` + ); + throw error; } } }; diff --git a/src/commands/player/leave.js b/src/commands/player/leave.js index 16766b2..b3056ba 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); @@ -18,6 +19,7 @@ module.exports = { const queue = useQueue(interaction.guild.id); if (!queue) { + logger.debug(`User used command ${interaction.commandName} but there was no queue.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -31,6 +33,7 @@ module.exports = { if (!queue.deleted) { queue.delete(); + logger.debug(`User used command ${interaction.commandName} and deleted the queue.`); return await interaction.editReply({ embeds: [ diff --git a/src/commands/player/loop.js b/src/commands/player/loop.js index 0b69e15..163efc3 100644 --- a/src/commands/player/loop.js +++ b/src/commands/player/loop.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions, botOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); @@ -45,6 +46,8 @@ module.exports = { const currentModeUserString = loopModesFormatted.get(currentMode); if (!mode && mode !== 0) { + logger.debug(`User used command ${interaction.commandName} but no mode was provided.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -59,6 +62,10 @@ module.exports = { } if (mode === currentMode) { + logger.debug( + `User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.` + ); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -73,6 +80,8 @@ module.exports = { queue.setRepeatMode(mode); if (!queue.repeatMode === mode) { + logger.debug(`User used command ${interaction.commandName} but failed to change loop mode.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -85,6 +94,8 @@ module.exports = { } if (queue.repeatMode === 0) { + logger.debug(`User used command ${interaction.commandName} and disabled loop mode.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -101,6 +112,8 @@ module.exports = { } if (queue.repeatMode === 3) { + logger.debug(`User used command ${interaction.commandName} and enabled autoplay.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -116,6 +129,8 @@ module.exports = { }); } + logger.debug(`User used command ${interaction.commandName} and enabled loop mode.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/nowplaying.js b/src/commands/player/nowplaying.js index d66539c..40166d9 100644 --- a/src/commands/player/nowplaying.js +++ b/src/commands/player/nowplaying.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions, playerOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); @@ -92,6 +93,8 @@ module.exports = { const loopModeUserString = loopModesFormatted.get(queue.repeatMode); + logger.debug(`User used command ${interaction.commandName}, finished intializing data.`); + const response = await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -140,6 +143,8 @@ module.exports = { components: [nowPlayingActionRow] }); + logger.debug(`User used command ${interaction.commandName}, finished sending response.`); + const collectorFilter = (i) => i.user.id === interaction.user.id; try { const confirmation = await response.awaitMessageComponent({ @@ -150,7 +155,11 @@ module.exports = { confirmation.deferUpdate(); if (confirmation.customId === 'nowplaying-skip') { + logger.debug(`User used command ${interaction.commandName}, received skip confirmation.`); if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) { + logger.debug( + `User used command ${interaction.commandName} and tried skipping but there was no queue.` + ); return await interaction.followUp({ embeds: [ new EmbedBuilder() @@ -164,6 +173,9 @@ module.exports = { } if (queue.currentTrack !== currentTrack) { + logger.debug( + `User used command ${interaction.commandName} and tried skipping but the track was already removed.` + ); return await interaction.followUp({ embeds: [ new EmbedBuilder() @@ -185,6 +197,7 @@ module.exports = { const repeatModeUserString = loopModesFormatted.get(queue.repeatMode); + logger.debug(`User used command ${interaction.commandName} and skipped the track.`); return await interaction.followUp({ embeds: [ new EmbedBuilder() @@ -210,12 +223,14 @@ module.exports = { components: [] }); } - } catch (e) { - if (e.code === 'InteractionCollectorError') { + } catch (error) { + if (error.code === 'InteractionCollectorError') { + logger.debug(`User used command ${interaction.commandName} but did not respond to the skip prompt.`); return; } - throw e; + logger.debug(error, `User used command ${interaction.commandName} but there was an unhandled error.`); + throw error; } } }; diff --git a/src/commands/player/pause.js b/src/commands/player/pause.js index 5620aa5..16214fa 100644 --- a/src/commands/player/pause.js +++ b/src/commands/player/pause.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); @@ -31,6 +32,7 @@ module.exports = { // change paused state to opposite of current state queue.node.setPaused(!queue.node.isPaused()); + logger.debug(`User used command ${interaction.commandName} and set paused state to ${queue.node.isPaused()}.`); return await interaction.editReply({ embeds: [ diff --git a/src/commands/player/play.js b/src/commands/player/play.js index 76e2391..3de4b37 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -33,6 +33,8 @@ module.exports = { } if (!searchResult || searchResult.tracks.length === 0) { + logger.debug(`No results found for query: ${query}`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -49,6 +51,8 @@ module.exports = { searchResult.tracks[0].raw.duration === 0 && searchResult.tracks[0].source === 'youtube' ) { + logger.debug(`Unsupported audio source. Query: ${query}. Track is live, 0 duration and from YouTube.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -83,6 +87,8 @@ module.exports = { } } })); + + logger.debug(`player.play() successful. Query: ${query}.`); } catch (error) { if (error.message.includes('Sign in to confirm your age')) { return await interaction.editReply({ @@ -102,6 +108,8 @@ module.exports = { error.message.includes('Failed to fetch resources for ytdl streaming'))) || error.message.includes('Could not extract stream for this track') ) { + logger.debug(error, `Found track but failed to retrieve audio. Query: ${query}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -114,6 +122,8 @@ module.exports = { } if (error.message === 'Cancelled') { + logger.debug(error, `Operation cancelled. Query: ${query}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -125,13 +135,14 @@ module.exports = { }); } - logger.error('Failed to play track with player.play()'); - logger.error(error); + logger.error(error, 'Failed to play track with player.play(), unhandled error.'); } let queue = useQueue(interaction.guild.id); if (!queue) { + logger.warn(`After player.play(), queue is undefined. Query: ${query}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -151,6 +162,8 @@ module.exports = { let durationFormat = track.raw.duration === 0 || track.duration === '0:00' ? '' : `\`${track.duration}\``; if (searchResult.playlist && searchResult.tracks.length > 1) { + logger.debug(`Playlist found and added with player.play(). Query: ${query}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -172,6 +185,8 @@ module.exports = { } if (queue.currentTrack === track && queue.tracks.data.length === 0) { + logger.debug(`Track found and added with player.play(), started playing. Query: ${query}.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -189,6 +204,7 @@ module.exports = { }); } + logger.debug(`Track found and added with player.play(), added to queue. Query: ${query}.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/queue.js b/src/commands/player/queue.js index f7fb7aa..6a77fd7 100644 --- a/src/commands/player/queue.js +++ b/src/commands/player/queue.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions, playerOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); @@ -20,6 +21,7 @@ module.exports = { if (!queue) { if (pageIndex >= 1) { + logger.debug(`User used command ${interaction.commandName} but there was no queue.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -33,6 +35,7 @@ module.exports = { }); } + logger.debug(`User used command ${interaction.commandName} but there was no queue.`); queueString = 'The queue is empty, add some tracks with **`/play`**!'; return await interaction.editReply({ embeds: [ @@ -54,6 +57,8 @@ module.exports = { const totalPages = Math.ceil(queueLength / 10) || 1; if (pageIndex > totalPages - 1) { + logger.debug(`User used command ${interaction.commandName} but page was higher than total pages.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -99,9 +104,10 @@ module.exports = { queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop } Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n` }`; - if (!currentTrack) { + logger.debug(`User used command ${interaction.commandName} but there was no current track.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -133,6 +139,7 @@ module.exports = { bar = '_No duration available._'; } + logger.debug(`User used command ${interaction.commandName} and got queue in reply with current track.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/remove.js b/src/commands/player/remove.js index a17e506..8853fbf 100644 --- a/src/commands/player/remove.js +++ b/src/commands/player/remove.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); @@ -30,6 +31,8 @@ module.exports = { const removeTrackNumber = interaction.options.getNumber('tracknumber'); if (removeTrackNumber > queue.tracks.data.length) { + logger.debug(`User used command ${interaction.commandName} but track number was higher than total tracks.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -46,6 +49,7 @@ module.exports = { let durationFormat = removedTrack.raw.duration === 0 || removedTrack.duration === '0:00' ? '' : `\`${removedTrack.duration}\``; + logger.debug(`User used command ${interaction.commandName} and removed track.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/seek.js b/src/commands/player/seek.js index c749dd9..dc79333 100644 --- a/src/commands/player/seek.js +++ b/src/commands/player/seek.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); @@ -45,6 +46,8 @@ module.exports = { } if (durationArray.length === 0 || durationArray.length > 3) { + logger.debug(`User used command ${interaction.commandName} but entered an invalid duration.`); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -70,6 +73,9 @@ module.exports = { }); if (!validElements) { + logger.debug( + `User used command ${interaction.commandName} but entered an invalid duration after parsing duration.` + ); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -90,6 +96,10 @@ module.exports = { const isValidDuration = regex.test(durationString); if (!isValidDuration) { + logger.debug( + `User used command ${interaction.commandName} but entered an invalid duration after regex checks.` + ); + return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -108,6 +118,7 @@ module.exports = { const durationInMilliseconds = durationArray[0] * 3600000 + durationArray[1] * 60000 + durationArray[2] * 1000; if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) { + logger.debug(`User used command ${interaction.commandName} but entered a duration longer than the track.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -120,6 +131,8 @@ module.exports = { } queue.node.seek(durationInMilliseconds); + + logger.debug(`User used command ${interaction.commandName} and seeked to duration.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/skip.js b/src/commands/player/skip.js index f0159bf..42d8af4 100644 --- a/src/commands/player/skip.js +++ b/src/commands/player/skip.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); @@ -31,6 +32,9 @@ module.exports = { if (skipToTrack) { if (skipToTrack > queue.tracks.data.length) { + logger.debug( + `User used command ${interaction.commandName} but track number was higher than total tracks.` + ); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -48,6 +52,7 @@ module.exports = { : `\`${skippedTrack.duration}\``; queue.node.skipTo(skipToTrack - 1); + logger.debug(`User used command ${interaction.commandName} and skipped to track.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -65,6 +70,9 @@ module.exports = { } } else { if (queue.tracks.data.length === 0 && !queue.currentTrack) { + logger.debug( + `User used command ${interaction.commandName} but there was no tracks in queue or current track.` + ); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -92,6 +100,7 @@ module.exports = { const loopModeUserString = loopModesFormatted.get(queue.repeatMode); + logger.debug(`User used command ${interaction.commandName} and skipped track.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/commands/player/volume.js b/src/commands/player/volume.js index f8fc56a..c12cf92 100644 --- a/src/commands/player/volume.js +++ b/src/commands/player/volume.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); @@ -32,6 +33,9 @@ module.exports = { if (!volume && volume !== 0) { const currentVolume = queue.node.volume; + logger.debug( + `User used command ${interaction.commandName} but no volume was provided, providing info of current volume.` + ); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -44,6 +48,9 @@ module.exports = { ] }); } else if (volume > 100 || volume < 0) { + logger.debug( + `User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.` + ); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -57,6 +64,7 @@ module.exports = { queue.node.setVolume(volume); if (volume === 0) { + logger.debug(`User used command ${interaction.commandName} and muted volume.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -72,6 +80,7 @@ module.exports = { }); } + logger.debug(`User used command ${interaction.commandName} and changed volume.`); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/utils/validation/queueValidation.js b/src/utils/validation/queueValidation.js index 7f533ea..d5ff4d4 100644 --- a/src/utils/validation/queueValidation.js +++ b/src/utils/validation/queueValidation.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { EmbedBuilder } = require('discord.js'); @@ -12,6 +13,9 @@ exports.queueDoesNotExist = async (interaction, queue) => { .setColor(embedOptions.colors.warning) ] }); + + logger.debug(`User tried to use command ${interaction.commandName} but there was no queue.`); + return true; } @@ -29,6 +33,9 @@ exports.queueNoCurrentTrack = async (interaction, queue) => { .setColor(embedOptions.colors.warning) ] }); + + logger.debug(`User tried to use command ${interaction.commandName} but there was no current track.`); + return true; } diff --git a/src/utils/validation/searchQueryValidation.js b/src/utils/validation/searchQueryValidation.js index 40897b9..3a58b96 100644 --- a/src/utils/validation/searchQueryValidation.js +++ b/src/utils/validation/searchQueryValidation.js @@ -11,6 +11,7 @@ exports.transformQuery = async (query) => { // if country-based, transform to normal Spotify url if (isCountryBased) { + logger.debug(`Transforming country-based Spotify url to normal Spotify url from query ${query}.`); const trackId = query.match(regex)[2]; query = `https://open.spotify.com/track/${trackId}`; } diff --git a/src/utils/validation/voiceChannelValidation.js b/src/utils/validation/voiceChannelValidation.js index d86f894..750e96e 100644 --- a/src/utils/validation/voiceChannelValidation.js +++ b/src/utils/validation/voiceChannelValidation.js @@ -1,3 +1,4 @@ +const logger = require('../../services/logger'); const { embedOptions } = require('../../config'); const { EmbedBuilder } = require('discord.js'); @@ -12,6 +13,8 @@ exports.notInVoiceChannel = async (interaction) => { .setColor(embedOptions.colors.warning) ] }); + + logger.debug(`User tried to use command ${interaction.commandName} but was not in a voice channel.`); return true; }