feat: more structures

This commit is contained in:
socram03 2022-06-23 21:35:00 -04:00
parent 0f68995136
commit ebca648b61
4 changed files with 81 additions and 0 deletions

20
structures/Channel.ts Normal file
View File

@ -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];
}
}

View File

@ -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<DiscordChannel>(
this.session.rest,
"DELETE",
Routes.CHANNEL(this.id),
{
reason,
},
);
}
}

27
structures/TextChannel.ts Normal file
View File

@ -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;
}
}

View File

@ -26,6 +26,10 @@ export interface GetMessagesOptions {
limit?: number; limit?: number;
} }
export function CHANNEL(channelId: Snowflake) {
return `/channels/${channelId}`;
}
/** used to send messages */ /** used to send messages */
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) { export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) {
let url = `/channels/${channelId}/messages?`; let url = `/channels/${channelId}/messages?`;