fix: update voice channel validator logging

This commit is contained in:
Marius Begby committed 2023-08-26 14:21:37 +02:00
1 parent 9d9087d4c3
commit 22109823e1
16 files changed
+95 -70

No files matched your search

+8 -8
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
}
+28 -20
View File
@@ -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\'.'
);
}
})();
+20 -3
View File
@@ -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;