Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
feat: Renamed validator files and added permission validator
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Jul 23, 2023
1 parent f04937e commit b68b7da
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/commands/player/filters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions, ffmpegFilterOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const {
SlashCommandBuilder,
EmbedBuilder,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/leave.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/loop.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions, botOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/nowplaying.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions, playerOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/pause.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
9 changes: 7 additions & 2 deletions src/commands/player/play.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const logger = require('../../services/logger');
const { embedOptions, playerOptions, botOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { transformQuery } = require('../../utils/validation/searchQueryValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { cannotJoinVoiceOrTalk } = require('../../utils/validation/permissionValidator');
const { transformQuery } = require('../../utils/validation/searchQueryValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useMainPlayer, useQueue } = require('discord-player');

Expand All @@ -16,6 +17,10 @@ module.exports = {
return;
}

if (await cannotJoinVoiceOrTalk(interaction)) {
return;
}

const player = useMainPlayer();
const query = interaction.options.getString('query');

Expand Down
2 changes: 1 addition & 1 deletion src/commands/player/queue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const logger = require('../../services/logger');
const { embedOptions, playerOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/seek.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/skip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
4 changes: 2 additions & 2 deletions src/commands/player/volume.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
const { queueDoesNotExist } = require('../../utils/validation/queueValidation');
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');

Expand Down
2 changes: 1 addition & 1 deletion src/commands/system/guilds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notValidGuildId } = require('../../utils/validation/systemCommandValidation');
const { notValidGuildId } = require('../../utils/validation/systemCommandValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/system/status.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { notValidGuildId } = require('../../utils/validation/systemCommandValidation');
const { notValidGuildId } = require('../../utils/validation/systemCommandValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const osu = require('node-os-utils');
const { version, dependencies } = require('../../../package.json');
Expand Down
24 changes: 24 additions & 0 deletions src/utils/validation/permissionValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const logger = require('../../services/logger');
const { embedOptions } = require('../../config');
const { EmbedBuilder } = require('discord.js');

exports.cannotJoinVoiceOrTalk = async (interaction) => {
const channel = interaction.member.voice.channel;

if (!channel.joinable || !channel.speakable) {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\nI do not have permission to play audio in the voice channel you are in.\n\nPlease make sure I have the **Connect** and **Speak** permissions in this voice channel.`
)
.setColor(embedOptions.colors.warning)
]
});

logger.debug(`User tried to use command ${interaction.commandName} but was not in a voice channel.`);
return true;
}

return false;
};

0 comments on commit b68b7da

Please sign in to comment.