mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: update validation in interactions
This commit is contained in:
1 parent
37546405e2
commit
5bc0239cdf
17 files changed
+151
-206
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import { MessageComponentInteraction } from 'discord.js';
|
import { MessageComponentInteraction } from 'discord.js';
|
||||||
import loggerModule from '../services/logger';
|
import loggerModule from '../services/logger';
|
||||||
|
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||||
|
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'interactionComponentHandler.js',
|
source: 'interactionComponentHandler.js',
|
||||||
@@ -16,6 +17,10 @@ export const handleComponent = async (interaction: MessageComponentInteraction,
|
|||||||
|
|
||||||
logger.debug(`Parsed componentId: ${componentId}`);
|
logger.debug(`Parsed componentId: ${componentId}`);
|
||||||
|
|
||||||
|
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const componentModule = await import(`../interactions/components/${componentId}.js`);
|
const componentModule = await import(`../interactions/components/${componentId}.js`);
|
||||||
const { default: component } = componentModule;
|
const { default: component } = componentModule;
|
||||||
|
|
||||||
|
|||||||
@@ -39,22 +39,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import loggerModule from '../../../services/logger';
|
|||||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
import { EmbedOptions } from '../../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
|
|
||||||
@@ -27,30 +28,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (!queue) {
|
const validators = [
|
||||||
logger.debug('There is already no queue.');
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
for (const validator of validators) {
|
||||||
return await interaction.editReply({
|
if (await validator()) {
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.warning)
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!queue.deleted) {
|
if (!queue.deleted) {
|
||||||
queue.delete();
|
queue.delete();
|
||||||
|
|||||||
@@ -41,18 +41,18 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const loopModesFormatted = new Map([
|
const loopModesFormatted = new Map([
|
||||||
|
|||||||
@@ -47,21 +47,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
let geniusSearchQuery = '';
|
let geniusSearchQuery = '';
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
geniusSearchQuery = queue.currentTrack!.title.slice(0, 50);
|
geniusSearchQuery = queue.currentTrack!.title.slice(0, 50);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|||||||
@@ -37,22 +37,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceStringsFormatted = new Map([
|
const sourceStringsFormatted = new Map([
|
||||||
|
|||||||
@@ -28,22 +28,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentTrack = queue.currentTrack!;
|
const currentTrack = queue.currentTrack!;
|
||||||
|
|||||||
@@ -43,20 +43,22 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await cannotJoinVoiceOrTalk({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
let queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) {
|
if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => cannotJoinVoiceOrTalk({ interaction, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const player = useMainPlayer()!;
|
const player = useMainPlayer()!;
|
||||||
const query = interaction.options.getString('query')!;
|
const query = interaction.options.getString('query')!;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import loggerModule from '../../../services/logger';
|
|||||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
|
import { EmbedOptions, PlayerOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||||
@@ -29,57 +30,23 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
||||||
let queueString = '';
|
let queueString = '';
|
||||||
|
|
||||||
if (!queue) {
|
|
||||||
if (pageIndex >= 1) {
|
|
||||||
logger.debug(`There is no queue and user tried to access page ${pageIndex + 1}.`);
|
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
|
||||||
return await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.warning} Oops!**\nPage **\`${
|
|
||||||
pageIndex + 1
|
|
||||||
}\`** is not a valid page number.\n\nThe queue is currently empty, first add some tracks with **\`/play\`**!`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.warning)
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug('There is no queue, displaying empty queue.');
|
|
||||||
queueString = 'The queue is empty, add some tracks with **`/play`**!';
|
|
||||||
|
|
||||||
logger.debug('Responding with info embed.');
|
|
||||||
return await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setAuthor({
|
|
||||||
name: interaction.guild!.name,
|
|
||||||
iconURL: interaction.guild!.iconURL() || ''
|
|
||||||
})
|
|
||||||
.setDescription(`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`)
|
|
||||||
.setColor(embedOptions.colors.info)
|
|
||||||
.setFooter({
|
|
||||||
text: 'Page 1 of 1 (0 tracks)'
|
|
||||||
})
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const queueLength = queue.tracks.data.length;
|
const queueLength = queue.tracks.data.length;
|
||||||
const totalPages = Math.ceil(queueLength / 10) || 1;
|
const totalPages = Math.ceil(queueLength / 10) || 1;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { NodeResolvable, useQueue } from 'discord-player';
|
import { GuildQueue, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../../services/logger';
|
import loggerModule from '../../../services/logger';
|
||||||
@@ -35,18 +35,18 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
return Promise.resolve();
|
|
||||||
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const queue: NodeResolvable = useQueue(interaction.guild!.id)!;
|
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeTrackNumber = interaction.options.getNumber('tracknumber')!;
|
const removeTrackNumber = interaction.options.getNumber('tracknumber')!;
|
||||||
|
|||||||
@@ -34,22 +34,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const durationInput = interaction.options.getString('duration');
|
const durationInput = interaction.options.getString('duration');
|
||||||
|
|||||||
@@ -28,22 +28,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueIsEmpty({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueIsEmpty({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.tracks.shuffle();
|
queue.tracks.shuffle();
|
||||||
|
|||||||
@@ -31,22 +31,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||||
|
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await queueNoCurrentTrack({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const skipToTrack = interaction.options.getNumber('tracknumber');
|
const skipToTrack = interaction.options.getNumber('tracknumber');
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import loggerModule from '../../../services/logger';
|
|||||||
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
|
||||||
import { EmbedOptions } from '../../../types/configTypes';
|
import { EmbedOptions } from '../../../types/configTypes';
|
||||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
|
|
||||||
@@ -27,30 +28,19 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (!queue) {
|
const validators = [
|
||||||
logger.debug('There is no queue.');
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
for (const validator of validators) {
|
||||||
return await interaction.editReply({
|
if (await validator()) {
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
`**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!`
|
|
||||||
)
|
|
||||||
.setColor(embedOptions.colors.warning)
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!queue.deleted) {
|
if (!queue.deleted) {
|
||||||
queue.setRepeatMode(0);
|
queue.setRepeatMode(0);
|
||||||
|
|||||||
@@ -35,18 +35,18 @@ const command: CustomSlashCommandInteraction = {
|
|||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (await notInVoiceChannel({ interaction, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
if (await queueDoesNotExist({ interaction, queue, executionId })) {
|
const validators = [
|
||||||
|
() => notInVoiceChannel({ interaction, executionId }),
|
||||||
|
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||||
|
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const validator of validators) {
|
||||||
|
if (await validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const volume = interaction.options.getNumber('percentage');
|
const volume = interaction.options.getNumber('percentage');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { GuildQueue, Player } from 'discord-player';
|
import { GuildQueue, Player } from 'discord-player';
|
||||||
import { ChatInputCommandInteraction } from 'discord.js';
|
import { ChatInputCommandInteraction, MessageComponentInteraction } from 'discord.js';
|
||||||
|
|
||||||
import { ExtendedClient } from './clientTypes';
|
import { ExtendedClient } from './clientTypes';
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ export interface CannotJoinVoiceOrTalkParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CannotSendMessageInChannelParams {
|
export interface CannotSendMessageInChannelParams {
|
||||||
interaction: ChatInputCommandInteraction;
|
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
||||||
executionId: string;
|
executionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, GuildMember, TextChannel, VoiceChannel } from 'discord.js';
|
import {
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
EmbedBuilder,
|
||||||
|
GuildMember,
|
||||||
|
InteractionType,
|
||||||
|
MessageComponentInteraction,
|
||||||
|
TextChannel,
|
||||||
|
VoiceChannel
|
||||||
|
} from 'discord.js';
|
||||||
|
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
@@ -50,10 +58,13 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: C
|
|||||||
|
|
||||||
const channel = interaction.channel;
|
const channel = interaction.channel;
|
||||||
|
|
||||||
|
const interactionIdentifier =
|
||||||
|
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
|
||||||
|
|
||||||
// only checks if channel is viewable, as bot will have permission to send interaction replies if channel is viewable
|
// only checks if channel is viewable, as bot will have permission to send interaction replies if channel is viewable
|
||||||
if (channel instanceof TextChannel && !channel.viewable) {
|
if (channel instanceof TextChannel && !channel.viewable) {
|
||||||
logger.info(
|
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 interaction '${interactionIdentifier}' but the bot has permission to send reply in text channel.`
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user