mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
feat: refactored handling of validators
This commit is contained in:
1 parent
e67d0004b0
commit
8c05499f08
31 files changed
+316
-338
No files matched your search
@@ -18,8 +18,8 @@ import { Logger } from 'pino';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||
|
||||
@@ -34,19 +34,19 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription('Audio filtering type to use.')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'FFmpeg', value: 'ffmpeg' },
|
||||
{ name: 'Biquad', value: 'biquad' },
|
||||
{ name: 'Equalizer', value: 'equalizer' },
|
||||
{ name: 'Disable', value: 'disable' }
|
||||
{ name: 'FFmpeg', value: 'FFmpeg' },
|
||||
{ name: 'Biquad', value: 'Biquad' },
|
||||
{ name: 'Equalizer', value: 'Equalizer' },
|
||||
{ name: 'Disable', value: 'Disable' }
|
||||
)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => notInVoiceChannel(args),
|
||||
(args) => notInSameVoiceChannel(args),
|
||||
(args) => queueDoesNotExist(args),
|
||||
(args) => queueNoCurrentTrack(args)
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -56,11 +56,9 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
await this.runValidators({ interaction, queue, executionId }).catch(() => {
|
||||
return;
|
||||
});
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const filterProvider: string = interaction.options.getString('type') || 'ffmpeg';
|
||||
const filterProvider: string = interaction.options.getString('type') || 'FFmpeg';
|
||||
|
||||
switch (filterProvider) {
|
||||
case 'ffmpeg':
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class LeaveCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -11,6 +11,12 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
||||
.setName('leave')
|
||||
.setDescription('Clear the queue and remove bot from voice channel.');
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -19,39 +25,18 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
logger.info('Validators passed, clearing queue.');
|
||||
|
||||
if (!queue.deleted) {
|
||||
queue.delete();
|
||||
logger.debug('Deleted the queue.');
|
||||
}
|
||||
|
||||
let authorName: string;
|
||||
|
||||
if (interaction.member instanceof GuildMember) {
|
||||
authorName = interaction.member.nickname || interaction.user.username;
|
||||
} else {
|
||||
authorName = interaction.user.username;
|
||||
}
|
||||
logger.debug('Deleting queue.');
|
||||
await this.deleteQueue(queue);
|
||||
|
||||
logger.debug('Responding with success embed.');
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: authorName,
|
||||
iconURL: interaction.user.avatarURL() || this.embedOptions.info.fallbackIconUrl
|
||||
})
|
||||
.setAuthor(await this.getEmbedAuthor(interaction))
|
||||
.setDescription(
|
||||
`**${this.embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
|
||||
)
|
||||
@@ -59,6 +44,12 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
protected async deleteQueue(queue: GuildQueue): Promise<void> {
|
||||
if (!queue.deleted) {
|
||||
queue.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new LeaveCommand();
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder, SlashCommandStringOption } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class LoopCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -23,6 +23,12 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -31,17 +37,7 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
// TODO: create type for loop modes formatted
|
||||
const loopModesFormatted: Map<number, string> = new Map([
|
||||
|
||||
@@ -3,8 +3,8 @@ import { GuildQueue, Player, QueryType, useMainPlayer, useQueue } from 'discord-
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class LyricsCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -21,29 +21,26 @@ class LyricsCommand extends BaseSlashCommandInteraction {
|
||||
.setAutocomplete(true)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
const query: string = interaction.options.getString('query')!;
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const query: string = interaction.options.getString('query')!;
|
||||
let geniusSearchQuery: string = '';
|
||||
|
||||
if (!query) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
geniusSearchQuery = queue.currentTrack!.title.slice(0, 50);
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import {
|
||||
import { PlayerOptions } from '../../../types/configTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||
|
||||
@@ -24,6 +24,13 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
.setName('nowplaying')
|
||||
.setDescription('Show information about the current track.');
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -32,19 +39,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
// TODO: define TS type for validators
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const sourceStringsFormatted: Map<string, string> = new Map([
|
||||
['youtube', 'YouTube'],
|
||||
|
||||
@@ -3,13 +3,20 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class PauseCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
const data = new SlashCommandBuilder().setName('pause').setDescription('Toggle pause for the current track.');
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -18,18 +25,7 @@ class PauseCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const currentTrack: Track = queue.currentTrack!;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandInteraction, CustomError } from '../../../classes/interactions';
|
||||
import { PlayerOptions } from '../../../types/configTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { cannotJoinVoiceOrTalk } from '../../../utils/validation/permissionValidator';
|
||||
import { checkVoicePermissionJoinAndTalk } from '../../../utils/validation/permissionValidator';
|
||||
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||
|
||||
@@ -25,26 +25,21 @@ class PlayCommand extends BaseSlashCommandInteraction {
|
||||
.setAutocomplete(true)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [(args) => checkInVoiceChannel(args)];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
await this.runValidators({ interaction, executionId });
|
||||
|
||||
let queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
if (queue && (await notInSameVoiceChannel({ interaction, queue, executionId }))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => cannotJoinVoiceOrTalk({ interaction, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
if (queue) {
|
||||
await this.runValidators({ interaction, queue, executionId }, [checkSameVoiceChannel]);
|
||||
} else {
|
||||
await this.runValidators({ interaction, executionId }, [checkVoicePermissionJoinAndTalk]);
|
||||
}
|
||||
|
||||
const player = useMainPlayer()!;
|
||||
|
||||
@@ -4,8 +4,8 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { PlayerOptions } from '../../../types/configTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||
|
||||
@@ -18,6 +18,12 @@ class QueueCommand extends BaseSlashCommandInteraction {
|
||||
option.setName('page').setDescription('Page number to display for the queue').setMinValue(1)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -26,17 +32,7 @@ class QueueCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const pageIndex: number = (interaction.options.getNumber('page') || 1) - 1;
|
||||
let queueString: string = '';
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, Track, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class RemoveCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -18,6 +18,12 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
||||
.setRequired(true)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -26,17 +32,7 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class SeekCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -14,6 +14,13 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
||||
option.setName('duration').setDescription('Duration in format 00:00:00 (HH:mm:ss).').setRequired(true)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -22,18 +29,7 @@ class SeekCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const durationInput: string = interaction.options.getString('duration')!;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueIsEmpty } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueEmpty } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class ShuffleCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -11,6 +11,13 @@ class ShuffleCommand extends BaseSlashCommandInteraction {
|
||||
.setName('shuffle')
|
||||
.setDescription('Randomly shuffle all tracks in the queue.');
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueEmpty(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -19,18 +26,7 @@ class ShuffleCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
queue.tracks.shuffle();
|
||||
logger.debug('Shuffled queue tracks.');
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, Track, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class SkipCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -14,6 +14,13 @@ class SkipCommand extends BaseSlashCommandInteraction {
|
||||
option.setName('tracknumber').setDescription('The position in queue to skip to.').setMinValue(1)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -22,18 +29,7 @@ class SkipCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const skipToTrack: number = interaction.options.getNumber('tracknumber')!;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class StopCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -11,6 +11,12 @@ class StopCommand extends BaseSlashCommandInteraction {
|
||||
.setName('stop')
|
||||
.setDescription('Clear the queue and stop playing audio.');
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -19,17 +25,7 @@ class StopCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
if (!queue.deleted) {
|
||||
queue.setRepeatMode(0);
|
||||
|
||||
@@ -2,8 +2,8 @@ import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class VolumeCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -18,6 +18,12 @@ class VolumeCommand extends BaseSlashCommandInteraction {
|
||||
.setMaxValue(100)
|
||||
);
|
||||
super(data);
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
@@ -26,17 +32,7 @@ class VolumeCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
const volume: number = interaction.options.getNumber('percentage')!;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
class GuildsCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -10,15 +10,15 @@ class GuildsCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription('Show the top 25 guilds by member count.');
|
||||
const isSystemCommand: boolean = true;
|
||||
super(data, isSystemCommand);
|
||||
|
||||
this.validators = [(args) => checkValidGuildId(args)];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
if (await notValidGuildId({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await this.runValidators({ interaction, executionId });
|
||||
|
||||
let shardGuilds: Guild[] = [];
|
||||
let totalGuildCount: number = 0;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ApplicationCommandOption, ApplicationCommandOptionData, EmbedBuilder, S
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
class ReloadCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -11,15 +11,15 @@ class ReloadCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription('Reload slash command, autocomplete and component interactions across shards.');
|
||||
const isSystemCommand: boolean = true;
|
||||
super(data, isSystemCommand);
|
||||
|
||||
this.validators = [(args) => checkValidGuildId(args)];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
if (await notValidGuildId({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await this.runValidators({ interaction, executionId });
|
||||
|
||||
try {
|
||||
logger.debug('Reloading interaction module across all shards.');
|
||||
|
||||
@@ -2,7 +2,7 @@ import { EmbedBuilder, EmbedField, SlashCommandBuilder } from 'discord.js';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
class ShardsCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -29,15 +29,15 @@ class ShardsCommand extends BaseSlashCommandInteraction {
|
||||
);
|
||||
const isSystemCommand: boolean = true;
|
||||
super(data, isSystemCommand);
|
||||
|
||||
this.validators = [(args) => checkValidGuildId(args)];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
if (await notValidGuildId({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await this.runValidators({ interaction, executionId });
|
||||
|
||||
let shardInfoList: ShardInfo[] = [];
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { dependencies, version } from '../../../../package.json';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
|
||||
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
|
||||
|
||||
class SystemStatusCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -14,15 +14,15 @@ class SystemStatusCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription('Show operational status of the bot with additional technical information.');
|
||||
const isSystemCommand: boolean = true;
|
||||
super(data, isSystemCommand);
|
||||
|
||||
this.validators = [(args) => checkValidGuildId(args)];
|
||||
}
|
||||
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction, client } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
|
||||
if (await notValidGuildId({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await this.runValidators({ interaction, executionId });
|
||||
|
||||
// from normal /status command
|
||||
const uptimeString: string = await getUptimeFormatted({ executionId });
|
||||
|
||||
@@ -2,12 +2,18 @@ import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember } from 'discord.js';
|
||||
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
||||
import { BaseComponentInteraction } from '../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class FiltersDisableButtonComponent extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
super('filters-disable-button');
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseComponentParams): BaseComponentReturnType {
|
||||
@@ -16,17 +22,7 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
// Reset filters before enabling provided filters
|
||||
if (queue.filters.ffmpeg.filters.length > 0) {
|
||||
|
||||
@@ -4,13 +4,19 @@ import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.
|
||||
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes';
|
||||
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
||||
import { BaseComponentInteraction } from '../../classes/interactions';
|
||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists } from '../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||
|
||||
class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
super('filters-select-menu');
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseComponentParams): BaseComponentReturnType {
|
||||
@@ -22,17 +28,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
const selectMenuInteraction: StringSelectMenuInteraction = interaction as StringSelectMenuInteraction;
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
const validators = [
|
||||
() => notInVoiceChannel({ interaction, executionId }),
|
||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
||||
() => queueDoesNotExist({ interaction, queue, executionId })
|
||||
];
|
||||
|
||||
for (const validator of validators) {
|
||||
if (await validator()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
queue.filters.ffmpeg.setInputArgs([
|
||||
'-threads',
|
||||
|
||||
@@ -2,12 +2,19 @@ import { GuildQueue, Track, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember } from 'discord.js';
|
||||
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
||||
import { BaseComponentInteraction } from '../../classes/interactions';
|
||||
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { checkQueueExists, checkQueueCurrentTrack } from '../../utils/validation/queueValidator';
|
||||
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
|
||||
class NowplayingSkipButton extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
super('nowplaying-skip-button');
|
||||
|
||||
this.validators = [
|
||||
(args) => checkInVoiceChannel(args),
|
||||
(args) => checkSameVoiceChannel(args),
|
||||
(args) => checkQueueExists(args),
|
||||
(args) => checkQueueCurrentTrack(args)
|
||||
];
|
||||
}
|
||||
|
||||
async execute(params: BaseComponentParams): BaseComponentReturnType {
|
||||
@@ -16,18 +23,7 @@ class NowplayingSkipButton extends BaseComponentInteraction {
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
await this.runValidators({ interaction, queue, executionId });
|
||||
|
||||
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
||||
logger.debug('Tried skipping track but there was no queue.');
|
||||
|
||||
Reference in new issue
Block a user