mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: Update validators with new types
This commit is contained in:
1 parent
af6bdd4da8
commit
e67d0004b0
7 files changed
+39
-73
No files matched your search
@@ -21,6 +21,7 @@ import {
|
|||||||
BaseSlashCommandParams,
|
BaseSlashCommandParams,
|
||||||
BaseSlashCommandReturnType
|
BaseSlashCommandReturnType
|
||||||
} from '../types/interactionTypes';
|
} from '../types/interactionTypes';
|
||||||
|
import { ValidatorParams } from '../types/utilTypes';
|
||||||
|
|
||||||
abstract class BaseInteraction {
|
abstract class BaseInteraction {
|
||||||
protected getLoggerBase(
|
protected getLoggerBase(
|
||||||
@@ -38,6 +39,16 @@ abstract class BaseInteraction {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected validators: ((args: ValidatorParams) => Promise<boolean>)[] = [];
|
||||||
|
|
||||||
|
protected async runValidators(args: ValidatorParams): Promise<void> {
|
||||||
|
for (const validator of this.validators) {
|
||||||
|
if (await validator(args)) {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract execute(
|
abstract execute(
|
||||||
params: BaseInteractionParams
|
params: BaseInteractionParams
|
||||||
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
|
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
|
||||||
|
|||||||
@@ -40,8 +40,14 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
{ name: 'Disable', value: 'disable' }
|
{ name: 'Disable', value: 'disable' }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
super(data);
|
super(data);
|
||||||
|
|
||||||
|
this.validators = [
|
||||||
|
(args) => notInVoiceChannel(args),
|
||||||
|
(args) => notInSameVoiceChannel(args),
|
||||||
|
(args) => queueDoesNotExist(args),
|
||||||
|
(args) => queueNoCurrentTrack(args)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||||
@@ -50,18 +56,9 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
|
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
|
|
||||||
const validators = [
|
await this.runValidators({ interaction, queue, executionId }).catch(() => {
|
||||||
() => notInVoiceChannel({ interaction, executionId }),
|
return;
|
||||||
() => notInSameVoiceChannel({ interaction, queue, executionId }),
|
});
|
||||||
() => queueDoesNotExist({ interaction, queue, executionId }),
|
|
||||||
() => queueNoCurrentTrack({ interaction, queue, executionId })
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const validator of validators) {
|
|
||||||
if (await validator()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterProvider: string = interaction.options.getString('type') || 'ffmpeg';
|
const filterProvider: string = interaction.options.getString('type') || 'ffmpeg';
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-40
@@ -23,19 +23,9 @@ export type CustomEvent = {
|
|||||||
isPlayerEvent?: boolean;
|
isPlayerEvent?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NotInVoiceChannelParams = {
|
export type ValidatorParams = {
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NotInSameVoiceChannelParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
queue: GuildQueue;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NotValidGuildIdParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
||||||
|
queue?: GuildQueue;
|
||||||
executionId: string;
|
executionId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,34 +34,6 @@ export type TransformQueryParams = {
|
|||||||
executionId: string;
|
executionId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type QueueDoesNotExistParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
queue: GuildQueue;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type QueueNoCurrentTrackParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
queue: GuildQueue;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type QueueIsEmptyParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
queue: GuildQueue;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CannotJoinVoiceOrTalkParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CannotSendMessageInChannelParams = {
|
|
||||||
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
|
|
||||||
executionId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GetUptimeFormattedParams = {
|
export type GetUptimeFormattedParams = {
|
||||||
executionId: string;
|
executionId: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import {
|
|||||||
VoiceBasedChannel,
|
VoiceBasedChannel,
|
||||||
VoiceChannel
|
VoiceChannel
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import { Logger } from 'pino';
|
import { Logger } from 'pino';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
import { CannotJoinVoiceOrTalkParams, CannotSendMessageInChannelParams } from '../../types/utilTypes';
|
import { ValidatorParams } from '../../types/utilTypes';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: CannotJoinVoiceOrTalkParams) => {
|
export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'cannotJoinVoiceOrTalk',
|
name: 'cannotJoinVoiceOrTalk',
|
||||||
@@ -49,7 +48,7 @@ export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: Cannot
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cannotSendMessageInChannel = async ({ interaction, executionId }: CannotSendMessageInChannelParams) => {
|
export const cannotSendMessageInChannel = async ({ interaction, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'cannotSendMessageInChannel',
|
name: 'cannotSendMessageInChannel',
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, InteractionType } from 'discord.js';
|
import { EmbedBuilder, InteractionType } from 'discord.js';
|
||||||
|
import { Logger } from 'pino';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
import { QueueDoesNotExistParams, QueueIsEmptyParams, QueueNoCurrentTrackParams } from '../../types/utilTypes';
|
import { ValidatorParams } from '../../types/utilTypes';
|
||||||
import { Logger } from 'pino';
|
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
export const queueDoesNotExist = async ({ interaction, queue, executionId }: QueueDoesNotExistParams) => {
|
export const queueDoesNotExist = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'queueDoesNotExist',
|
name: 'queueDoesNotExist',
|
||||||
@@ -37,7 +36,7 @@ export const queueDoesNotExist = async ({ interaction, queue, executionId }: Que
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: QueueNoCurrentTrackParams) => {
|
export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'queueNoCurrentTrack',
|
name: 'queueNoCurrentTrack',
|
||||||
@@ -49,7 +48,7 @@ export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: Q
|
|||||||
const interactionIdentifier =
|
const interactionIdentifier =
|
||||||
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
|
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
|
||||||
|
|
||||||
if (!queue.currentTrack) {
|
if (queue && !queue.currentTrack) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
@@ -67,7 +66,7 @@ export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: Q
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const queueIsEmpty = async ({ interaction, queue, executionId }: QueueIsEmptyParams) => {
|
export const queueIsEmpty = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'queueIsEmpty',
|
name: 'queueIsEmpty',
|
||||||
@@ -79,7 +78,7 @@ export const queueIsEmpty = async ({ interaction, queue, executionId }: QueueIsE
|
|||||||
const interactionIdentifier =
|
const interactionIdentifier =
|
||||||
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
|
interaction.type === InteractionType.ApplicationCommand ? interaction.commandName : interaction.customId;
|
||||||
|
|
||||||
if (queue.tracks.data.length === 0) {
|
if (queue && queue.tracks.data.length === 0) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, InteractionType } from 'discord.js';
|
import { EmbedBuilder, InteractionType } from 'discord.js';
|
||||||
|
import { Logger } from 'pino';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions, SystemOptions } from '../../types/configTypes';
|
import { EmbedOptions, SystemOptions } from '../../types/configTypes';
|
||||||
import { NotValidGuildIdParams } from '../../types/utilTypes';
|
import { ValidatorParams } from '../../types/utilTypes';
|
||||||
import { Logger } from 'pino';
|
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
const systemOptions: SystemOptions = config.get('systemOptions');
|
const systemOptions: SystemOptions = config.get('systemOptions');
|
||||||
export const notValidGuildId = async ({ interaction, executionId }: NotValidGuildIdParams) => {
|
export const notValidGuildId = async ({ interaction, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'notValidGuildId',
|
name: 'notValidGuildId',
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { EmbedBuilder, GuildMember, InteractionType } from 'discord.js';
|
import { EmbedBuilder, GuildMember, InteractionType } from 'discord.js';
|
||||||
|
|
||||||
import { Logger } from 'pino';
|
import { Logger } from 'pino';
|
||||||
import loggerModule from '../../services/logger';
|
import loggerModule from '../../services/logger';
|
||||||
import { EmbedOptions } from '../../types/configTypes';
|
import { EmbedOptions } from '../../types/configTypes';
|
||||||
import { NotInSameVoiceChannelParams, NotInVoiceChannelParams } from '../../types/utilTypes';
|
import { ValidatorParams } from '../../types/utilTypes';
|
||||||
|
|
||||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||||
export const notInVoiceChannel = async ({ interaction, executionId }: NotInVoiceChannelParams) => {
|
export const notInVoiceChannel = async ({ interaction, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'validator',
|
module: 'validator',
|
||||||
name: 'notInVoiceChannel',
|
name: 'notInVoiceChannel',
|
||||||
@@ -37,7 +36,7 @@ export const notInVoiceChannel = async ({ interaction, executionId }: NotInVoice
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const notInSameVoiceChannel = async ({ interaction, queue, executionId }: NotInSameVoiceChannelParams) => {
|
export const notInSameVoiceChannel = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||||
const logger: Logger = loggerModule.child({
|
const logger: Logger = loggerModule.child({
|
||||||
module: 'utilValidation',
|
module: 'utilValidation',
|
||||||
name: 'notInSameVoiceChannel',
|
name: 'notInSameVoiceChannel',
|
||||||
|
|||||||
Reference in new issue
Block a user