diff --git a/src/commands/player/filters.js b/src/commands/player/filters.js index b872db8..ab33cc9 100644 --- a/src/commands/player/filters.js +++ b/src/commands/player/filters.js @@ -22,8 +22,8 @@ module.exports = { .setDescription('Toggle various audio filters during playback.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -33,7 +33,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } @@ -88,7 +88,7 @@ module.exports = { components: [filterActionRow, disableFiltersActionRow] }); logger.debug( - `Sent embed for command ${interaction.commandName}, awaiting interaction response.` + `[Shard ${interaction.guild.shardId}] Sent embed for command ${interaction.commandName}, awaiting interaction response.` ); const collectorFilter = (i) => i.user.id === interaction.user.id; @@ -99,7 +99,7 @@ module.exports = { }); logger.debug( - `Received interaction response for command ${interaction.commandName}.` + `[Shard ${interaction.guild.shardId}] Received interaction response for command ${interaction.commandName}.` ); confirmation.deferUpdate(); @@ -150,7 +150,7 @@ module.exports = { queue.filters.ffmpeg.toggle(confirmation.values); logger.debug( - `Enabled filters ${confirmation.values.join(', ')} for command ${ + `[Shard ${interaction.guild.shardId}] Enabled filters ${confirmation.values.join(', ')} for command ${ interaction.commandName }.` ); @@ -182,14 +182,14 @@ module.exports = { } catch (error) { if (error.code === 'InteractionCollectorError') { logger.debug( - `Interaction response timed out for command ${interaction.commandName}.` + `[Shard ${interaction.guild.shardId}] Interaction response timed out for command ${interaction.commandName}.` ); return; } logger.debug( error, - `Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.` + `[Shard ${interaction.guild.shardId}] 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 979bc5a..079098a 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -13,8 +13,8 @@ module.exports = { .setDescription('Clear the track queue and remove the bot from voice channel.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -35,7 +35,7 @@ module.exports = { }); } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/loop.js b/src/commands/player/loop.js index 5abdc98..d64cb27 100644 --- a/src/commands/player/loop.js +++ b/src/commands/player/loop.js @@ -27,8 +27,8 @@ module.exports = { { name: 'Disabled', value: '0' } ) ), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -38,7 +38,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/lyrics.js b/src/commands/player/lyrics.js index 229ab9b..d9eb83e 100644 --- a/src/commands/player/lyrics.js +++ b/src/commands/player/lyrics.js @@ -86,13 +86,13 @@ module.exports = { ); return interaction.respond(response); }, - execute: async ({ interaction }) => { + execute: async ({ interaction, executionId }) => { const query = interaction.options.getString('query'); const queue = useQueue(interaction.guild.id); let geniusSearchQuery = ''; if (!query) { - if (await notInVoiceChannel(interaction)) { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -100,7 +100,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/nowplaying.js b/src/commands/player/nowplaying.js index 98af16f..94f26a3 100644 --- a/src/commands/player/nowplaying.js +++ b/src/commands/player/nowplaying.js @@ -15,8 +15,8 @@ module.exports = { .setDescription('Show information about the track currently playing.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -26,7 +26,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/pause.js b/src/commands/player/pause.js index aeaf1d8..21fe770 100644 --- a/src/commands/player/pause.js +++ b/src/commands/player/pause.js @@ -14,8 +14,8 @@ module.exports = { .setDescription('Pause or resume the current track.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -25,7 +25,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/play.js b/src/commands/player/play.js index bb84a5a..d6c6361 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -83,7 +83,7 @@ module.exports = { return interaction.respond(response); }, - execute: async ({ interaction, client, executionId }) => { + execute: async ({ interaction, executionId }) => { const logger = require('../../services/logger').child({ source: 'play.js', module: 'slashCommand', @@ -91,7 +91,7 @@ module.exports = { executionId: executionId }); - if (await notInVoiceChannel(interaction, client)) { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -100,7 +100,7 @@ module.exports = { } let queue = useQueue(interaction.guild.id); - if (queue && (await notInSameVoiceChannel(interaction, queue))) { + if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) { return; } diff --git a/src/commands/player/queue.js b/src/commands/player/queue.js index 89205fd..5112aac 100644 --- a/src/commands/player/queue.js +++ b/src/commands/player/queue.js @@ -15,14 +15,14 @@ module.exports = { .setDMPermission(false) .setNSFW(false) .addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } const queue = useQueue(interaction.guild.id); - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/remove.js b/src/commands/player/remove.js index 7b170ad..9e30721 100644 --- a/src/commands/player/remove.js +++ b/src/commands/player/remove.js @@ -21,8 +21,8 @@ module.exports = { .setMinValue(1) .setRequired(true) ), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -32,7 +32,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/seek.js b/src/commands/player/seek.js index b0f03b4..5d29e06 100644 --- a/src/commands/player/seek.js +++ b/src/commands/player/seek.js @@ -20,8 +20,8 @@ module.exports = { .setDescription('Duration in format 00:00:00 (HH:mm:ss) to seek to.') .setRequired(true) ), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -31,7 +31,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/shuffle.js b/src/commands/player/shuffle.js index cf7e537..61be593 100644 --- a/src/commands/player/shuffle.js +++ b/src/commands/player/shuffle.js @@ -14,8 +14,8 @@ module.exports = { .setDescription('Shuffle tracks in the queue randomly.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -25,7 +25,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/skip.js b/src/commands/player/skip.js index dd3e067..a5ccf12 100644 --- a/src/commands/player/skip.js +++ b/src/commands/player/skip.js @@ -17,8 +17,8 @@ module.exports = { .addNumberOption((option) => option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1) ), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -28,7 +28,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/stop.js b/src/commands/player/stop.js index e05edd9..53e23b5 100644 --- a/src/commands/player/stop.js +++ b/src/commands/player/stop.js @@ -13,8 +13,8 @@ module.exports = { .setDescription('Stop playing audio and clear the track queue.') .setDMPermission(false) .setNSFW(false), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -35,7 +35,7 @@ module.exports = { }); } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/commands/player/volume.js b/src/commands/player/volume.js index 7fb7200..3543d5a 100644 --- a/src/commands/player/volume.js +++ b/src/commands/player/volume.js @@ -21,8 +21,8 @@ module.exports = { .setMinValue(0) .setMaxValue(100) ), - execute: async ({ interaction }) => { - if (await notInVoiceChannel(interaction)) { + execute: async ({ interaction, executionId }) => { + if (await notInVoiceChannel({ interaction, executionId })) { return; } @@ -32,7 +32,7 @@ module.exports = { return; } - if (await notInSameVoiceChannel(interaction, queue)) { + if (await notInSameVoiceChannel({ interaction, queue, executionId })) { return; } diff --git a/src/utils/deploySlashCommands.js b/src/utils/deploySlashCommands.js index ea99fe9..0f34a89 100644 --- a/src/utils/deploySlashCommands.js +++ b/src/utils/deploySlashCommands.js @@ -1,11 +1,20 @@ require('dotenv').config(); -const logger = require('../services/logger'); const fs = require('node:fs'); const path = require('node:path'); const { REST, Routes } = require('discord.js'); const config = require('config'); +const { v4: uuidv4 } = require('uuid'); const systemOptions = config.get('systemOptions'); +const executionId = uuidv4(); + +const logger = require('../services/logger').child({ + source: 'deploySlashCommands.js', + module: 'deploy', + name: 'deploySlashCommands', + executionId: executionId +}); + const slashCommands = []; const systemCommands = []; const commandFolders = fs.readdirSync(path.resolve('./src/commands')); @@ -26,46 +35,45 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN) (async () => { if (!process.env.DISCORD_APPLICATION_ID || !process.env.DISCORD_BOT_TOKEN) { - logger.error('Missing required environment variables for deployment.'); - logger.error('Provide valid DISCORD_APPLICATION_ID and DISCORD_BOT_TOKEN in .env file.'); + logger.error( + 'Missing required environment variables for deployment.\nPlease provide valid DISCORD_APPLICATION_ID and DISCORD_BOT_TOKEN in .env file.' + ); } try { - logger.info('DEPLOYING BOT SLASH COMMANDS'); - logger.info( - slashCommands.map((command) => command.name), - 'Bot commands found:' - ); + logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`); - logger.info('Started refreshing application (/) bot commands.'); + logger.info('Started refreshing user slash commands.'); await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), slashCommands); - logger.info('Successfully refreshed application (/) bot commands.'); + logger.info('Successfully refreshed user slash commands.'); } catch (error) { - logger.error(error, 'Failed to refresh application (/) bot commands.'); + logger.error(error, 'Failed to refresh user slash commands.'); } try { - logger.info('DEPLOYING SYSTEM SLASH COMMANDS'); - logger.info( - systemCommands.map((systemCommand) => systemCommand.name), - 'System commands found:' + logger.debug( + `Bot system slash commands found: ${systemCommands + .map((systemCommand) => `/${systemCommand.name}`) + .join(', ')}` ); - logger.info('Started refreshing application (/) system commands.'); + logger.info('Started refreshing system slash commands.'); const systemGuildIds = systemOptions.systemGuildIds; await Promise.all( systemGuildIds.map((systemGuildId) => { - logger.info(`Refreshing system commands for guild id: ${systemGuildId}.`); + logger.debug(`Refreshing system slash command for guild id '${systemGuildId}'.`); refreshCommands( Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, systemGuildId), systemCommands ); }) ); - logger.info('Successfully refreshed application (/) system commands.'); + logger.info('Successfully refreshed system slash commands.'); } catch (error) { - logger.error(error, 'Failed to refresh application (/) system commands.'); - logger.error('Make sure the bot is in the system guilds provided.'); + logger.error( + error, + 'Failed to refresh system slash commands. Make sure the bot is in the system guilds specified in \'systemOptions\'.' + ); } })(); diff --git a/src/utils/validation/voiceChannelValidator.js b/src/utils/validation/voiceChannelValidator.js index df83238..e4d9640 100644 --- a/src/utils/validation/voiceChannelValidator.js +++ b/src/utils/validation/voiceChannelValidator.js @@ -1,9 +1,17 @@ -const logger = require('../../services/logger'); const config = require('config'); const embedOptions = config.get('embedOptions'); const { EmbedBuilder } = require('discord.js'); -exports.notInVoiceChannel = async (interaction) => { +exports.notInVoiceChannel = async ({ interaction, executionId }) => { + const logger = require('../../services/logger').child({ + source: 'voiceChannelValidator.js', + module: 'validator', + name: 'notInVoiceChannel', + executionId: executionId, + shardId: interaction.guild.shardId, + guildId: interaction.guild.id + }); + if (!interaction.member.voice.channel) { await interaction.editReply({ embeds: [ @@ -22,7 +30,16 @@ exports.notInVoiceChannel = async (interaction) => { return false; }; -exports.notInSameVoiceChannel = async (interaction, queue) => { +exports.notInSameVoiceChannel = async ({ interaction, queue, executionId }) => { + const logger = require('../../services/logger').child({ + source: 'voiceChannelValidator.js', + module: 'validator', + name: 'notInSameVoiceChannel', + executionId: executionId, + shardId: interaction.guild.shardId, + guildId: interaction.guild.id + }); + if (!queue || !queue.dispatcher) { // If there is no queue or bot is not in voice channel, then there is no need to check if user is in same voice channel. return false;