mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 22:16:13 +00:00
fix: updated logging for validators
This commit is contained in:
1 parent
22109823e1
commit
57fc1e3ee8
23 files changed
+118
-70
No files matched your search
@@ -1,9 +1,17 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
exports.cannotJoinVoiceOrTalk = async (interaction) => {
|
||||
exports.cannotJoinVoiceOrTalk = async ({ interaction, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'permissionValidator.js',
|
||||
module: 'validator',
|
||||
name: 'cannotJoinVoiceOrTalk',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
const channel = interaction.member.voice.channel;
|
||||
|
||||
if (!channel.joinable || !channel.speakable) {
|
||||
@@ -18,7 +26,7 @@ exports.cannotJoinVoiceOrTalk = async (interaction) => {
|
||||
});
|
||||
|
||||
logger.debug(
|
||||
`User tried to use command ${interaction.commandName} but the bot had no permission to join/speak in the voice channel.`
|
||||
`User tried to use command '${interaction.commandName}' but the bot had no permission to join/speak in the voice channel.`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
@@ -26,13 +34,22 @@ exports.cannotJoinVoiceOrTalk = async (interaction) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.cannotSendMessageInChannel = async (interaction) => {
|
||||
exports.cannotSendMessageInChannel = async ({ interaction, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'permissionValidator.js',
|
||||
module: 'validator',
|
||||
name: 'cannotSendMessageInChannel',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
const channel = interaction.channel;
|
||||
|
||||
// only checks if channel is viewable, as bot will have permission to send interaction replies if channel is viewable
|
||||
if (!channel.viewable) {
|
||||
logger.info(
|
||||
`User tried to use command ${interaction.commandName} but the bot had no permission to send reply in text channel.`
|
||||
`User tried to use command '${interaction.commandName}' but the bot had no permission to send reply in text channel.`
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -51,8 +68,10 @@ exports.cannotSendMessageInChannel = async (interaction) => {
|
||||
ephemeral: true
|
||||
});
|
||||
} catch (error) {
|
||||
if(error.message == 'The reply to this interaction has already been sent or deferred.') {
|
||||
logger.warn('Error while sending ephemereal message about insufficient permissions to send message in channel.');
|
||||
if (error.message == 'The reply to this interaction has already been sent or deferred.') {
|
||||
logger.warn(
|
||||
'Error while sending ephemereal message about insufficient permissions to send message in channel.'
|
||||
);
|
||||
logger.debug(error);
|
||||
} else {
|
||||
logger.error(
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
exports.queueDoesNotExist = async (interaction, queue) => {
|
||||
exports.queueDoesNotExist = async ({ interaction, queue, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'queueValidator.js',
|
||||
module: 'validator',
|
||||
name: 'queueDoesNotExist',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
if (!queue) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -15,15 +23,23 @@ exports.queueDoesNotExist = async (interaction, queue) => {
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but there was no queue.`);
|
||||
|
||||
logger.debug(`User tried to use command '${interaction.commandName}' but there was no queue.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.queueNoCurrentTrack = async (interaction, queue) => {
|
||||
exports.queueNoCurrentTrack = async ({ interaction, queue, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'queueValidator.js',
|
||||
module: 'validator',
|
||||
name: 'queueNoCurrentTrack',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
if (!queue.currentTrack) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -35,15 +51,23 @@ exports.queueNoCurrentTrack = async (interaction, queue) => {
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but there was no current track.`);
|
||||
|
||||
logger.debug(`User tried to use command '${interaction.commandName}' but there was no current track.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.queueIsEmpty = async (interaction, queue) => {
|
||||
exports.queueIsEmpty = async ({ interaction, queue, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'queueValidator.js',
|
||||
module: 'validator',
|
||||
name: 'queueIsEmpty',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
if (queue.tracks.data.length === 0) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -55,8 +79,7 @@ exports.queueIsEmpty = async (interaction, queue) => {
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but there was no tracks in the queue.`);
|
||||
|
||||
logger.debug(`User tried to use command '${interaction.commandName}' but there was no tracks in the queue.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
const logger = require('../../services/logger');
|
||||
exports.transformQuery = async ({ query, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'searchQueryValidator.js',
|
||||
module: 'validator',
|
||||
name: 'transformQuery',
|
||||
executionId: executionId
|
||||
});
|
||||
|
||||
exports.transformQuery = async (query) => {
|
||||
if (query.startsWith('https://open.spotify.com/')) {
|
||||
try {
|
||||
// regex to check for country-based Spotify url
|
||||
@@ -11,13 +16,13 @@ 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}.`);
|
||||
logger.debug(`Transforming country-based Spotify url to normal Spotify url from query '${query}'.`);
|
||||
const type = query.match(regex)[2];
|
||||
const trackId = query.match(regex)[3];
|
||||
query = `https://open.spotify.com/${type}/${trackId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
logger.error(error, 'Error while validating or transforming Spotify url.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,16 @@ const embedOptions = config.get('embedOptions');
|
||||
const systemOptions = config.get('systemOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
exports.notValidGuildId = async (interaction) => {
|
||||
exports.notValidGuildId = async ({ interaction, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'systemCommandValidator.js',
|
||||
module: 'validator',
|
||||
name: 'notValidGuildId',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
if (!systemOptions.systemGuildIds.includes(interaction.guildId)) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -14,6 +23,9 @@ exports.notValidGuildId = async (interaction) => {
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
});
|
||||
logger.debug(
|
||||
`User tried to use command ${interaction.commandName} but system command cannot be executed in the specified guild.`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ exports.notInVoiceChannel = async ({ interaction, executionId }) => {
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but was not in a voice channel.`);
|
||||
logger.debug(`User tried to use command '${interaction.commandName}' but was not in a voice channel.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ exports.notInSameVoiceChannel = async ({ interaction, queue, executionId }) => {
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but was not in the same voice channel.`);
|
||||
logger.debug(`User tried to use command '${interaction.commandName}' but was not in the same voice channel.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user