Add CategoryChannel and update ChannelFactory

This commit is contained in:
Nicolás Serna 2022-07-19 02:51:15 -03:00
parent 73b20bfdcb
commit e81b80d5cf

View File

@ -12,9 +12,11 @@ import {
DiscordInviteMetadata, DiscordInviteMetadata,
DiscordListArchivedThreads, DiscordListArchivedThreads,
DiscordMessage, DiscordMessage,
DiscordOverwrite,
DiscordThreadMember, DiscordThreadMember,
DiscordWebhook, DiscordWebhook,
GatewayOpcodes, GatewayOpcodes,
OverwriteTypes,
TargetTypes, TargetTypes,
VideoQualityModes, VideoQualityModes,
} from '../../discordeno/mod.ts'; } from '../../discordeno/mod.ts';
@ -89,6 +91,27 @@ export abstract class BaseChannel implements Model {
} }
} }
/** CategoryChannel */
export class CategoryChannel extends BaseChannel {
constructor(session: Session, data: DiscordChannel) {
super(session, data);
this.id = data.id;
this.name = data.name ? data.name : '';
this.permissionOverwrites = data.permission_overwrites ? data.permission_overwrites : undefined;
this.nsfw = data.nsfw ? data.nsfw : false;
this.guildId = data.guild_id ? data.guild_id : undefined;
this.type = ChannelTypes.GuildCategory;
this.position = data.position ? data.position : 0;
}
id: Snowflake;
name: string;
permissionOverwrites?: DiscordOverwrite[];
nsfw: boolean;
guildId?: Snowflake;
position: number;
}
/** TextChannel */ /** TextChannel */
/** /**
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params * @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
@ -816,7 +839,8 @@ export type Channel =
| DMChannel | DMChannel
| NewsChannel | NewsChannel
| ThreadChannel | ThreadChannel
| StageChannel; | StageChannel
| CategoryChannel;
export type ChannelInGuild = export type ChannelInGuild =
| GuildTextChannel | GuildTextChannel
@ -868,6 +892,8 @@ export class ChannelFactory {
return new VoiceChannel(session, channel, channel.guild_id!); return new VoiceChannel(session, channel, channel.guild_id!);
case ChannelTypes.GuildStageVoice: case ChannelTypes.GuildStageVoice:
return new StageChannel(session, channel, channel.guild_id!); return new StageChannel(session, channel, channel.guild_id!);
case ChannelTypes.GuildCategory:
return new CategoryChannel(session, channel);
default: default:
if (textBasedChannels.includes(channel.type)) { if (textBasedChannels.includes(channel.type)) {
return new TextChannel(session, channel); return new TextChannel(session, channel);