From 998fd7cb737d703001701b2a6e95b18aa1b53118 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Thu, 23 Jun 2022 19:11:46 -0500 Subject: [PATCH] wip: guild struct --- structures/Guild.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 structures/Guild.ts diff --git a/structures/Guild.ts b/structures/Guild.ts new file mode 100644 index 0000000..803a69d --- /dev/null +++ b/structures/Guild.ts @@ -0,0 +1,41 @@ +import type { Model } from "./Base.ts"; +import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../session/Session.ts"; +import type { DiscordGuild, DiscordMember, MakeRequired } from "../vendor/external.ts"; +import { DefaultMessageNotificationLevels, ExplicitContentFilterLevels, VerificationLevels } from "../vendor/external.ts"; +import { iconHashToBigInt, iconBigintToHash as _iconBigintToHash } from "../util/hash.ts"; +import { Member } from "./Member.ts"; + +export class Guild implements Model { + constructor(session: Session, data: DiscordGuild) { + this.session = session; + this.id = data.id; + + this.name = data.name; + this.iconHash = data.icon ? iconHashToBigInt(data.icon) : undefined; + this.splashHash = data.splash ? iconHashToBigInt(data.splash) : undefined; + this.discoverySplashHash = data.discovery_splash ? iconHashToBigInt(data.discovery_splash) : undefined; + this.ownerId = data.owner_id; + this.widgetEnabled = !!data.widget_enabled; + this.widgetChannelId = data.widget_channel_id ? data.widget_channel_id : undefined; + this.vefificationLevel = data.verification_level; + this.defaultMessageNotificationLevel = data.default_message_notifications; + this.explicitContentFilterLevel = data.explicit_content_filter; + this.members = data.members?.map((member) => new Member(session, member as MakeRequired)) ?? []; + } + + readonly session: Session; + readonly id: Snowflake; + + name: string; + iconHash?: bigint; + splashHash?: bigint; + discoverySplashHash?: bigint; + ownerId: Snowflake; + widgetEnabled: boolean; + widgetChannelId?: Snowflake; + vefificationLevel: VerificationLevels; + defaultMessageNotificationLevel: DefaultMessageNotificationLevels; + explicitContentFilterLevel: ExplicitContentFilterLevels; + members: Member[]; +}