From a7317a0a3ca2a86ebccd804d15a59b37e8a6f938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Fri, 8 Jul 2022 22:15:03 -0300 Subject: [PATCH] TODO done: targetApplication implemented & Minor changes --- packages/biscuit/structures/Invite.ts | 48 ++++++++------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/packages/biscuit/structures/Invite.ts b/packages/biscuit/structures/Invite.ts index 5e79787..df6cad2 100644 --- a/packages/biscuit/structures/Invite.ts +++ b/packages/biscuit/structures/Invite.ts @@ -8,6 +8,7 @@ import type { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus, + DiscordApplication } from "../../discordeno/mod.ts"; import { TargetTypes } from "../../discordeno/mod.ts"; import { GuildChannel } from "./channels.ts"; @@ -15,6 +16,7 @@ import { Member } from "./Member.ts"; import InviteGuild from "./guilds/InviteGuild.ts"; import User from "./User.ts"; import Guild from "./guilds/Guild.ts"; +import Application from "./Application.ts"; export interface InviteStageInstance { /** The members speaking in the Stage */ @@ -53,29 +55,21 @@ export class Invite { constructor(session: Session, data: DiscordInvite) { this.session = session; - if (data.guild) { - this.guild = new InviteGuild(session, data.guild); - } - - if (data.approximate_member_count) { - this.approximateMemberCount = data.approximate_member_count; - } - - if (data.approximate_presence_count) { - this.approximatePresenceCount = data.approximate_presence_count; - } - + this.guild = data.guild ? new InviteGuild(session, data.guild) : undefined; + this.approximateMemberCount = data.approximate_member_count ? data.approximate_member_count : undefined; + this.approximatePresenceCount = data.approximate_presence_count ? data.approximate_presence_count : undefined; + this.code = data.code; + this.expiresAt = data.expires_at ? Number.parseInt(data.expires_at) : undefined; + this.inviter = data.inviter ? new User(session, data.inviter) : undefined; + this.targetUser = data.target_user ? new User(session, data.target_user) : undefined; + this.targetApplication = data.target_application ? new Application(session, data.target_application as DiscordApplication) : undefined; + this.targetType = data.target_type; + if (data.channel) { const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; this.channel = new GuildChannel(session, data.channel as DiscordChannel, guildId); } - this.code = data.code; - - if (data.expires_at) { - this.expiresAt = Number.parseInt(data.expires_at); - } - if (data.guild_scheduled_event) { this.guildScheduledEvent = { id: data.guild_scheduled_event.id, @@ -105,14 +99,6 @@ export class Invite { }; } - if (data.inviter) { - this.inviter = new User(session, data.inviter); - } - - if (data.target_user) { - this.targetUser = new User(session, data.target_user); - } - if (data.stage_instance) { const guildId = (data.guild && data.guild?.id) ? data.guild.id : ""; this.stageInstance = { @@ -124,13 +110,6 @@ export class Invite { topic: data.stage_instance.topic, }; } - - // TODO: create Application structure - // this.targetApplication = data.target_application - - if (data.target_type) { - this.targetType = data.target_type; - } } readonly session: Session; @@ -145,8 +124,7 @@ export class Invite { channel?: Partial; stageInstance?: InviteStageInstance; guildScheduledEvent?: InviteScheduledEvent; - // TODO: create Application structure - // targetApplication?: Partial + targetApplication?: Partial async delete(): Promise { await Guild.prototype.deleteInvite.call(this.guild, this.code);