From b99218bdc3916842a5b3a047431c45af06cfe568 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Fri, 1 Jul 2022 16:18:59 -0500 Subject: [PATCH] refactor: Channel -> BaseChannel --- mod.ts | 2 +- structures/BaseChannel.ts | 49 ++++++++++++++++++++++++++++++++++++++ structures/Channel.ts | 24 ------------------- structures/DMChannel.ts | 4 ++-- structures/GuildChannel.ts | 4 ++-- 5 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 structures/BaseChannel.ts delete mode 100644 structures/Channel.ts diff --git a/mod.ts b/mod.ts index dc393a4..8e72101 100644 --- a/mod.ts +++ b/mod.ts @@ -2,7 +2,7 @@ export * from "./structures/AnonymousGuild.ts"; export * from "./structures/Attachment.ts"; export * from "./structures/Base.ts"; export * from "./structures/BaseGuild.ts"; -export * from "./structures/Channel.ts"; +export * from "./structures/BaseChannel.ts"; export * from "./structures/Component.ts"; export * from "./structures/DMChannel.ts"; export * from "./structures/Embed.ts"; diff --git a/structures/BaseChannel.ts b/structures/BaseChannel.ts new file mode 100644 index 0000000..a0ed80b --- /dev/null +++ b/structures/BaseChannel.ts @@ -0,0 +1,49 @@ +import type { Model } from "./Base.ts"; +import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../session/Session.ts"; +import type { ChannelTypes, DiscordChannel } from "../vendor/external.ts"; +import TextChannel from "./TextChannel.ts"; +import VoiceChannel from "./VoiceChannel.ts"; +import DMChannel from "./DMChannel.ts"; +import NewsChannel from "./NewsChannel.ts"; +import ThreadChannel from "./ThreadChannel.ts"; + +export abstract class BaseChannel implements Model { + constructor(session: Session, data: DiscordChannel) { + this.id = data.id; + this.session = session; + this.name = data.name; + this.type = data.type; + } + readonly id: Snowflake; + readonly session: Session; + + name?: string; + type: ChannelTypes; + + isText(): this is TextChannel { + return this instanceof TextChannel; + } + + isVoice(): this is VoiceChannel { + return this instanceof VoiceChannel; + } + + isDM(): this is DMChannel { + return this instanceof DMChannel; + } + + isNews(): this is NewsChannel { + return this instanceof NewsChannel; + } + + isThread(): this is ThreadChannel { + return this instanceof ThreadChannel; + } + + toString(): string { + return `<#${this.id}>`; + } +} + +export default BaseChannel; diff --git a/structures/Channel.ts b/structures/Channel.ts deleted file mode 100644 index daf18ac..0000000 --- a/structures/Channel.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { Model } from "./Base.ts"; -import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/Session.ts"; -import type { ChannelTypes, DiscordChannel } from "../vendor/external.ts"; - -export abstract class Channel implements Model { - constructor(session: Session, data: DiscordChannel) { - this.id = data.id; - this.session = session; - this.name = data.name; - this.type = data.type; - } - readonly id: Snowflake; - readonly session: Session; - - name?: string; - type: ChannelTypes; - - toString(): string { - return `<#${this.id}>`; - } -} - -export default Channel; diff --git a/structures/DMChannel.ts b/structures/DMChannel.ts index d3407f1..d13bd5d 100644 --- a/structures/DMChannel.ts +++ b/structures/DMChannel.ts @@ -2,11 +2,11 @@ import type { Model } from "./Base.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordChannel } from "../vendor/external.ts"; -import Channel from "./Channel.ts"; +import BaseChannel from "./BaseChannel.ts"; import User from "./User.ts"; import * as Routes from "../util/Routes.ts"; -export class DMChannel extends Channel implements Model { +export class DMChannel extends BaseChannel implements Model { constructor(session: Session, data: DiscordChannel) { super(session, data); diff --git a/structures/GuildChannel.ts b/structures/GuildChannel.ts index 99ea4ff..73dfd3b 100644 --- a/structures/GuildChannel.ts +++ b/structures/GuildChannel.ts @@ -2,11 +2,11 @@ import type { Model } from "./Base.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordChannel, DiscordInviteMetadata } from "../vendor/external.ts"; -import Channel from "./Channel.ts"; +import BaseChannel from "./BaseChannel.ts"; import Invite from "./Invite.ts"; import * as Routes from "../util/Routes.ts"; -export abstract class GuildChannel extends Channel implements Model { +export abstract class GuildChannel extends BaseChannel implements Model { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { super(session, data); this.guildId = guildId;