From 373c46471d4c8709f08f4197e277f94389b06c6f Mon Sep 17 00:00:00 2001 From: socram03 Date: Sat, 25 Jun 2022 19:38:34 -0400 Subject: [PATCH] feat: some changes --- mod.ts | 1 + structures/Channel.ts | 4 ++-- structures/Emoji.ts | 18 ++++++++++++++++++ structures/Guild.ts | 4 ++-- structures/GuildChannel.ts | 2 +- structures/GuildEmoji.ts | 15 +++++++++++++++ structures/Role.ts | 13 ++++++------- structures/TextChannel.ts | 4 ++-- structures/VoiceChannel.ts | 4 ++-- 9 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 structures/Emoji.ts create mode 100644 structures/GuildEmoji.ts diff --git a/mod.ts b/mod.ts index 2663b56..7304f31 100644 --- a/mod.ts +++ b/mod.ts @@ -15,3 +15,4 @@ export * from "./structures/TextChannel.ts"; export * from "./structures/VoiceChannel.ts"; export * from "./structures/ThreadChannel.ts"; export * from "./structures/NewsChannel.ts"; +export * from "./structures/Emoji.ts"; diff --git a/structures/Channel.ts b/structures/Channel.ts index 40e3bd7..f2fae2e 100644 --- a/structures/Channel.ts +++ b/structures/Channel.ts @@ -8,8 +8,8 @@ export abstract class Channel implements Model { this.name = data.name; this.type = data.type; } - id: Snowflake; - session: Session; + readonly id: Snowflake; + readonly session: Session; name?: string; type: ChannelTypes; diff --git a/structures/Emoji.ts b/structures/Emoji.ts new file mode 100644 index 0000000..78df164 --- /dev/null +++ b/structures/Emoji.ts @@ -0,0 +1,18 @@ +import { Session, DiscordEmoji, Snowflake } from "../mod.ts"; + +export class Emoji { + constructor(session: Session, data: DiscordEmoji) { + this.id = data.id; + this.name = data.name; + this.animated = !!data.animated; + this.available = !!data.available; + this.requireColons = !!data.require_colons; + this.session = session; + } + readonly id?: Snowflake; + readonly session: Session; + name?: string; + animated: boolean; + available: boolean; + requireColons: boolean; +} \ No newline at end of file diff --git a/structures/Guild.ts b/structures/Guild.ts index b447e58..f18eb86 100644 --- a/structures/Guild.ts +++ b/structures/Guild.ts @@ -39,7 +39,7 @@ export class Guild extends BaseGuild implements Model { this.defaultMessageNotificationLevel = data.default_message_notifications; this.explicitContentFilterLevel = data.explicit_content_filter; this.members = data.members?.map((member) => new Member(session, { ...member, user: member.user! })) ?? []; - this.roles = data.roles.map((role) => new Role(session, this, role)); + this.roles = data.roles.map((role) => new Role(session, this.id, role)); } splashHash?: bigint; @@ -78,7 +78,7 @@ export class Guild extends BaseGuild implements Model { }, ); - return new Role(this.session, this, role); + return new Role(this.session, this.id, role); } async deleteRole(roleId: Snowflake): Promise { diff --git a/structures/GuildChannel.ts b/structures/GuildChannel.ts index c0a986f..8ca5873 100644 --- a/structures/GuildChannel.ts +++ b/structures/GuildChannel.ts @@ -2,7 +2,7 @@ import { Channel } from "./Channel.ts"; import { Guild } from "./Guild.ts"; import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts"; -export class GuildChannel extends Channel { +export abstract class GuildChannel extends Channel { constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) { super(session, data); this.guildId = guildId; diff --git a/structures/GuildEmoji.ts b/structures/GuildEmoji.ts new file mode 100644 index 0000000..f0056b8 --- /dev/null +++ b/structures/GuildEmoji.ts @@ -0,0 +1,15 @@ +import { Snowflake, Session, Emoji, DiscordEmoji, User } from "../mod.ts"; + +export class GuildEmoji extends Emoji { + constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) { + super(session, data); + this.guildId = guildId; + this.roles = data.roles; + this.user = data.user ? new User(this.session, data.user) : undefined; + this.managed = !!data.managed; + } + guildId: Snowflake; + roles?: Snowflake[]; + user?: User; + managed?: boolean; +} \ No newline at end of file diff --git a/structures/Role.ts b/structures/Role.ts index 2bb3cb1..9b71a56 100644 --- a/structures/Role.ts +++ b/structures/Role.ts @@ -1,15 +1,14 @@ import type { Model } from "./Base.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordRole } from "../vendor/external.ts"; -import { Snowflake } from "../util/Snowflake.ts"; +import { Snowflake, Routes } from "../mod.ts"; import { iconHashToBigInt } from "../util/hash.ts"; -import { Guild } from "./Guild.ts"; export class Role implements Model { - constructor(session: Session, guild: Guild, data: DiscordRole) { + constructor(session: Session, guildId: Snowflake, data: DiscordRole) { this.session = session; this.id = data.id; - this.guild = guild; + this.guildId = guildId; this.hoist = data.hoist; this.iconHash = data.icon ? iconHashToBigInt(data.icon) : undefined; this.color = data.color; @@ -21,7 +20,7 @@ export class Role implements Model { session: Session; id: Snowflake; - guild: Guild; + guildId: Snowflake; hoist: boolean; iconHash?: bigint; color: number; @@ -43,12 +42,12 @@ export class Role implements Model { } async delete() { - await this.guild.deleteRole(this.id); + await this.session.rest.runMethod(this.session.rest, "DELETE", Routes.GUILD_ROLE(this.guildId, this.id)); } toString() { switch (this.id) { - case this.guild.id: + case this.guildId: return "@everyone"; default: return `<@&${this.id}>`; diff --git a/structures/TextChannel.ts b/structures/TextChannel.ts index 6c9a729..446bdcc 100644 --- a/structures/TextChannel.ts +++ b/structures/TextChannel.ts @@ -7,7 +7,7 @@ import { GetMessagesOptions } from "../util/Routes.ts"; /** * Represents the options object to create an invitation - * 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 */ export interface DiscordInviteOptions { @@ -20,7 +20,7 @@ export interface DiscordInviteOptions { /** * Represent the options object to create a Thread Channel - * https://discord.com/developers/docs/resources/channel#start-thread-without-message + * @link https://discord.com/developers/docs/resources/channel#start-thread-without-message */ export interface ThreadCreateOptions { diff --git a/structures/VoiceChannel.ts b/structures/VoiceChannel.ts index 065c693..7f285c3 100644 --- a/structures/VoiceChannel.ts +++ b/structures/VoiceChannel.ts @@ -3,8 +3,8 @@ import { Guild } from "./Guild.ts"; import { DiscordChannel, Session, Snowflake, VideoQualityModes } from "../mod.ts"; export class VoiceChannel extends GuildChannel { - constructor(session: Session, data: DiscordChannel, guild: Guild) { - super(session, data, guild); + constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) { + super(session, data, guildId); this.bitRate = data.bitrate; this.userLimit = data.user_limit ?? 0; data.rtc_region ? this.rtcRegion = data.rtc_region : undefined;