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

+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;