Skip to content

Commit

Permalink
fix(serializers): use the correct names for the aliases (#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Nov 11, 2024
1 parent 52c2ac9 commit d8a3941
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/serializers/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { isNullish, type Awaitable } from '@sapphire/utilities';
import type { Channel } from 'discord.js';

@ApplyOptions<Serializer.Options>({
aliases: ['guildTextChannel', 'guildVoiceChannel', 'guildCategoryChannel']
aliases: ['guildTextChannel', 'guildVoiceChannel', 'guildCategoryChannel'] satisfies SerializerType[]
})
export class UserSerializer extends Serializer<string> {
public async parse(args: Serializer.Args, { entry }: Serializer.UpdateContext) {
const result = await args.pickResult(entry.type as 'guildTextChannel' | 'guildVoiceChannel' | 'guildCategoryChannel');
const result = await args.pickResult(entry.type as SerializerType);
return result.match({
ok: (value) => this.ok(value.id),
err: (error) => this.errorFromArgument(args, error)
Expand All @@ -18,7 +18,7 @@ export class UserSerializer extends Serializer<string> {

public isValid(value: string, context: Serializer.UpdateContext): Awaitable<boolean> {
const channel = context.guild.channels.cache.get(value);
return !isNullish(channel) && this.isValidChannel(channel, context.entry.type);
return !isNullish(channel) && this.isValidChannel(channel, context.entry.type as SerializerType);
}

/**
Expand All @@ -30,18 +30,20 @@ export class UserSerializer extends Serializer<string> {
return context.guild.channels.cache.get(value)?.name ?? value;
}

private isValidChannel(channel: Channel, type: string): boolean {
private isValidChannel(channel: Channel, type: SerializerType): boolean {
if (!isGuildBasedChannelByGuildKey(channel)) return false;

switch (type) {
case 'textChannel':
case 'guildTextChannel':
return isTextChannel(channel) || isNewsChannel(channel);
case 'voiceChannel':
case 'guildVoiceChannel':
return isVoiceChannel(channel);
case 'categoryChannel':
case 'guildCategoryChannel':
return isCategoryChannel(channel);
default:
return false;
}

return false;
}
}

type SerializerType = 'guildTextChannel' | 'guildVoiceChannel' | 'guildCategoryChannel';

0 comments on commit d8a3941

Please sign in to comment.