fix: Add more logging to all commands

This commit is contained in:
Marius Begby committed 2023-07-19 00:44:32 +02:00
1 parent 389e60baad
commit 8ab4cbead2
13 files changed
+106 -7

No files matched your search

+14 -3
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions, ffmpegFilterOptions } = require('../../config'); const { embedOptions, ffmpegFilterOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
@@ -77,6 +78,7 @@ module.exports = {
], ],
components: [filterActionRow, disableFiltersActionRow] components: [filterActionRow, disableFiltersActionRow]
}); });
logger.debug(`Sent embed for command ${interaction.commandName}, awaiting interaction response.`);
const collectorFilter = (i) => i.user.id === interaction.user.id; const collectorFilter = (i) => i.user.id === interaction.user.id;
try { try {
@@ -85,6 +87,8 @@ module.exports = {
time: 60000 time: 60000
}); });
logger.debug(`Received interaction response for command ${interaction.commandName}.`);
confirmation.deferUpdate(); confirmation.deferUpdate();
queue.filters.ffmpeg.setInputArgs([ queue.filters.ffmpeg.setInputArgs([
@@ -124,6 +128,8 @@ module.exports = {
// Enable provided filters // Enable provided filters
queue.filters.ffmpeg.toggle(confirmation.values); queue.filters.ffmpeg.toggle(confirmation.values);
logger.debug(`Enabled filters ${confirmation.values.join(', ')} for command ${interaction.commandName}.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -149,12 +155,17 @@ module.exports = {
], ],
components: [] components: []
}); });
} catch (e) { } catch (error) {
if (e.code === 'InteractionCollectorError') { if (error.code === 'InteractionCollectorError') {
logger.debug(`Interaction response timed out for command ${interaction.commandName}.`);
return; return;
} }
throw e; logger.debug(
error,
`Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
);
throw error;
} }
} }
}; };
+3
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
@@ -18,6 +19,7 @@ module.exports = {
const queue = useQueue(interaction.guild.id); const queue = useQueue(interaction.guild.id);
if (!queue) { if (!queue) {
logger.debug(`User used command ${interaction.commandName} but there was no queue.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -31,6 +33,7 @@ module.exports = {
if (!queue.deleted) { if (!queue.deleted) {
queue.delete(); queue.delete();
logger.debug(`User used command ${interaction.commandName} and deleted the queue.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
+15
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions, botOptions } = require('../../config'); const { embedOptions, botOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
@@ -45,6 +46,8 @@ module.exports = {
const currentModeUserString = loopModesFormatted.get(currentMode); const currentModeUserString = loopModesFormatted.get(currentMode);
if (!mode && mode !== 0) { if (!mode && mode !== 0) {
logger.debug(`User used command ${interaction.commandName} but no mode was provided.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -59,6 +62,10 @@ module.exports = {
} }
if (mode === currentMode) { if (mode === currentMode) {
logger.debug(
`User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -73,6 +80,8 @@ module.exports = {
queue.setRepeatMode(mode); queue.setRepeatMode(mode);
if (!queue.repeatMode === mode) { if (!queue.repeatMode === mode) {
logger.debug(`User used command ${interaction.commandName} but failed to change loop mode.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -85,6 +94,8 @@ module.exports = {
} }
if (queue.repeatMode === 0) { if (queue.repeatMode === 0) {
logger.debug(`User used command ${interaction.commandName} and disabled loop mode.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -101,6 +112,8 @@ module.exports = {
} }
if (queue.repeatMode === 3) { if (queue.repeatMode === 3) {
logger.debug(`User used command ${interaction.commandName} and enabled autoplay.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -116,6 +129,8 @@ module.exports = {
}); });
} }
logger.debug(`User used command ${interaction.commandName} and enabled loop mode.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+18 -3
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions, playerOptions } = require('../../config'); const { embedOptions, playerOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
@@ -92,6 +93,8 @@ module.exports = {
const loopModeUserString = loopModesFormatted.get(queue.repeatMode); const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName}, finished intializing data.`);
const response = await interaction.editReply({ const response = await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -140,6 +143,8 @@ module.exports = {
components: [nowPlayingActionRow] components: [nowPlayingActionRow]
}); });
logger.debug(`User used command ${interaction.commandName}, finished sending response.`);
const collectorFilter = (i) => i.user.id === interaction.user.id; const collectorFilter = (i) => i.user.id === interaction.user.id;
try { try {
const confirmation = await response.awaitMessageComponent({ const confirmation = await response.awaitMessageComponent({
@@ -150,7 +155,11 @@ module.exports = {
confirmation.deferUpdate(); confirmation.deferUpdate();
if (confirmation.customId === 'nowplaying-skip') { if (confirmation.customId === 'nowplaying-skip') {
logger.debug(`User used command ${interaction.commandName}, received skip confirmation.`);
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) { 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({ return await interaction.followUp({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -164,6 +173,9 @@ module.exports = {
} }
if (queue.currentTrack !== currentTrack) { if (queue.currentTrack !== currentTrack) {
logger.debug(
`User used command ${interaction.commandName} and tried skipping but the track was already removed.`
);
return await interaction.followUp({ return await interaction.followUp({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -185,6 +197,7 @@ module.exports = {
const repeatModeUserString = loopModesFormatted.get(queue.repeatMode); const repeatModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName} and skipped the track.`);
return await interaction.followUp({ return await interaction.followUp({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -210,12 +223,14 @@ module.exports = {
components: [] components: []
}); });
} }
} catch (e) { } catch (error) {
if (e.code === 'InteractionCollectorError') { if (error.code === 'InteractionCollectorError') {
logger.debug(`User used command ${interaction.commandName} but did not respond to the skip prompt.`);
return; return;
} }
throw e; logger.debug(error, `User used command ${interaction.commandName} but there was an unhandled error.`);
throw error;
} }
} }
}; };
+2
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
@@ -31,6 +32,7 @@ module.exports = {
// change paused state to opposite of current state // change paused state to opposite of current state
queue.node.setPaused(!queue.node.isPaused()); 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({ return await interaction.editReply({
embeds: [ embeds: [
+8 -1
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions, playerOptions } = require('../../config'); const { embedOptions, playerOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
@@ -20,6 +21,7 @@ module.exports = {
if (!queue) { if (!queue) {
if (pageIndex >= 1) { if (pageIndex >= 1) {
logger.debug(`User used command ${interaction.commandName} but there was no queue.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() 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`**!'; queueString = 'The queue is empty, add some tracks with **`/play`**!';
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@@ -54,6 +57,8 @@ module.exports = {
const totalPages = Math.ceil(queueLength / 10) || 1; const totalPages = Math.ceil(queueLength / 10) || 1;
if (pageIndex > totalPages - 1) { if (pageIndex > totalPages - 1) {
logger.debug(`User used command ${interaction.commandName} but page was higher than total pages.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -99,9 +104,10 @@ module.exports = {
queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n` } Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n`
}`; }`;
if (!currentTrack) { if (!currentTrack) {
logger.debug(`User used command ${interaction.commandName} but there was no current track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -133,6 +139,7 @@ module.exports = {
bar = '_No duration available._'; bar = '_No duration available._';
} }
logger.debug(`User used command ${interaction.commandName} and got queue in reply with current track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+4
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
@@ -30,6 +31,8 @@ module.exports = {
const removeTrackNumber = interaction.options.getNumber('tracknumber'); const removeTrackNumber = interaction.options.getNumber('tracknumber');
if (removeTrackNumber > queue.tracks.data.length) { 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({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -46,6 +49,7 @@ module.exports = {
let durationFormat = let durationFormat =
removedTrack.raw.duration === 0 || removedTrack.duration === '0:00' ? '' : `\`${removedTrack.duration}\``; removedTrack.raw.duration === 0 || removedTrack.duration === '0:00' ? '' : `\`${removedTrack.duration}\``;
logger.debug(`User used command ${interaction.commandName} and removed track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+13
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
@@ -45,6 +46,8 @@ module.exports = {
} }
if (durationArray.length === 0 || durationArray.length > 3) { if (durationArray.length === 0 || durationArray.length > 3) {
logger.debug(`User used command ${interaction.commandName} but entered an invalid duration.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -70,6 +73,9 @@ module.exports = {
}); });
if (!validElements) { if (!validElements) {
logger.debug(
`User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -90,6 +96,10 @@ module.exports = {
const isValidDuration = regex.test(durationString); const isValidDuration = regex.test(durationString);
if (!isValidDuration) { if (!isValidDuration) {
logger.debug(
`User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -108,6 +118,7 @@ module.exports = {
const durationInMilliseconds = durationArray[0] * 3600000 + durationArray[1] * 60000 + durationArray[2] * 1000; const durationInMilliseconds = durationArray[0] * 3600000 + durationArray[1] * 60000 + durationArray[2] * 1000;
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) { if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
logger.debug(`User used command ${interaction.commandName} but entered a duration longer than the track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -120,6 +131,8 @@ module.exports = {
} }
queue.node.seek(durationInMilliseconds); queue.node.seek(durationInMilliseconds);
logger.debug(`User used command ${interaction.commandName} and seeked to duration.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+9
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
@@ -31,6 +32,9 @@ module.exports = {
if (skipToTrack) { if (skipToTrack) {
if (skipToTrack > queue.tracks.data.length) { 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({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -48,6 +52,7 @@ module.exports = {
: `\`${skippedTrack.duration}\``; : `\`${skippedTrack.duration}\``;
queue.node.skipTo(skipToTrack - 1); queue.node.skipTo(skipToTrack - 1);
logger.debug(`User used command ${interaction.commandName} and skipped to track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -65,6 +70,9 @@ module.exports = {
} }
} else { } else {
if (queue.tracks.data.length === 0 && !queue.currentTrack) { 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({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -92,6 +100,7 @@ module.exports = {
const loopModeUserString = loopModesFormatted.get(queue.repeatMode); const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName} and skipped track.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+9
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation'); const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation'); const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
@@ -32,6 +33,9 @@ module.exports = {
if (!volume && volume !== 0) { if (!volume && volume !== 0) {
const currentVolume = queue.node.volume; 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({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -44,6 +48,9 @@ module.exports = {
] ]
}); });
} else if (volume > 100 || volume < 0) { } 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({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -57,6 +64,7 @@ module.exports = {
queue.node.setVolume(volume); queue.node.setVolume(volume);
if (volume === 0) { if (volume === 0) {
logger.debug(`User used command ${interaction.commandName} and muted volume.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
@@ -72,6 +80,7 @@ module.exports = {
}); });
} }
logger.debug(`User used command ${interaction.commandName} and changed volume.`);
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
+7
View File
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { EmbedBuilder } = require('discord.js'); const { EmbedBuilder } = require('discord.js');
@@ -12,6 +13,9 @@ exports.queueDoesNotExist = async (interaction, queue) => {
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
] ]
}); });
logger.debug(`User tried to use command ${interaction.commandName} but there was no queue.`);
return true; return true;
} }
@@ -29,6 +33,9 @@ exports.queueNoCurrentTrack = async (interaction, queue) => {
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
] ]
}); });
logger.debug(`User tried to use command ${interaction.commandName} but there was no current track.`);
return true; return true;
} }
@@ -11,6 +11,7 @@ exports.transformQuery = async (query) => {
// if country-based, transform to normal Spotify url // if country-based, transform to normal Spotify url
if (isCountryBased) { if (isCountryBased) {
logger.debug(`Transforming country-based Spotify url to normal Spotify url from query ${query}.`);
const trackId = query.match(regex)[2]; const trackId = query.match(regex)[2];
query = `https://open.spotify.com/track/${trackId}`; query = `https://open.spotify.com/track/${trackId}`;
} }
@@ -1,3 +1,4 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config'); const { embedOptions } = require('../../config');
const { EmbedBuilder } = require('discord.js'); const { EmbedBuilder } = require('discord.js');
@@ -12,6 +13,8 @@ exports.notInVoiceChannel = async (interaction) => {
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
] ]
}); });
logger.debug(`User tried to use command ${interaction.commandName} but was not in a voice channel.`);
return true; return true;
} }