diff --git a/structures/Channel.ts b/structures/Channel.ts new file mode 100644 index 0000000..f7d33f6 --- /dev/null +++ b/structures/Channel.ts @@ -0,0 +1,20 @@ +import type { Model } from "./Base.ts"; +import { Snowflake, Session, DiscordChannel, ChannelTypes } from "../mod.ts"; + +export class Channel implements Model { + constructor(session: Session, data: DiscordChannel) { + this.id = data.id; + this.data = data; + this.session = session; + this.name = this.data.name; + } + readonly data: DiscordChannel; + readonly id: Snowflake; + readonly session: Session; + public readonly name: string | undefined; + + get type() { + return ChannelTypes[this.data.type]; + } + +} \ No newline at end of file diff --git a/structures/GuildChannel.ts b/structures/GuildChannel.ts new file mode 100644 index 0000000..56529e2 --- /dev/null +++ b/structures/GuildChannel.ts @@ -0,0 +1,30 @@ +import { Channel } from "./Channel.ts"; +import { DiscordChannel, Routes, Session } from "../mod.ts"; + +export class GuildChannel extends Channel { + constructor(session: Session, data: DiscordChannel) { + super(session, data); + this.guild_id = data.guild_id; + } + + guild_id?: string; + + get topic() { + return this.data.topic; + } + + get guildId() { + return this.guild_id; + } + + delete(reason?: string) { + return this.session.rest.runMethod( + this.session.rest, + "DELETE", + Routes.CHANNEL(this.id), + { + reason, + }, + ); + } +} diff --git a/structures/TextChannel.ts b/structures/TextChannel.ts new file mode 100644 index 0000000..eff5c15 --- /dev/null +++ b/structures/TextChannel.ts @@ -0,0 +1,27 @@ +import { GuildChannel } from "./GuildChannel.ts"; +import { DiscordChannel, Session } from "../mod.ts"; + +export class TextChannel extends GuildChannel { + constructor(session: Session, data: DiscordChannel) { + super(session, data); + } + + get lastMessageId() { + return this.data.last_message_id; + } + get rateLimitPerUser() { + return this.data.rate_limit_per_user; + } + + get parentId() { + return this.data.parent_id; + } + + get permissionOverwrites() { + return this.data.permission_overwrites; + } + + get nsfw() { + return this.data.nsfw; + } +} diff --git a/util/Routes.ts b/util/Routes.ts index a6adec0..375c4e5 100644 --- a/util/Routes.ts +++ b/util/Routes.ts @@ -26,6 +26,10 @@ export interface GetMessagesOptions { limit?: number; } +export function CHANNEL(channelId: Snowflake) { + return `/channels/${channelId}`; +} + /** used to send messages */ export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) { let url = `/channels/${channelId}/messages?`;