darkcord
Version:
A NodeJS Package to interact with Discord API
101 lines (100 loc) • 3.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Invite = void 0;
const Guild_1 = require("./Guild");
class Invite {
/**
* The guild this invite is for
*/
guild;
/**
* The expiration date of this invite
*/
expiresAt;
/**
* The user who created the invite
*/
inviter;
/**
* The invite code (unique ID)
*/
code;
/**
* The channel this invite is for
*/
channel;
/**
* The type of target for this voice channel invite
*/
targetType;
/**
* The user whose stream to display for this voice channel stream invite
*/
targetUser;
/**
* Approximate count of total members
*/
approximateMemberCount;
/**
* Approximate count of online members
*/
approximatePresenceCount;
/**
* The guild scheduled event
*/
guildScheduledEvent;
_client;
constructor(data) {
this._client = data.client;
this.guild = null;
this.expiresAt = null;
this.inviter = null;
this.code = data.code;
this.approximateMemberCount = 0;
this.approximatePresenceCount = 0;
this.targetType = data.target_type;
this.targetUser = data.target_user
? data.client.cache.users.add(data.target_user)
: null;
this.guildScheduledEvent = null;
this._update(data);
}
_update(data) {
if (data.guild) {
this.guild = data.guild
? this._client.guilds.cache.get(data.guild.id) ??
new Guild_1.InviteGuild({ ...data.guild, client: this._client })
: null;
}
if ("expires_at" in data) {
this.expiresAt = data.expires_at ? Date.parse(data.expires_at) : null;
}
if ("inviter" in data) {
this.inviter = data.inviter
? this._client.cache.users.add(data.inviter)
: null;
}
if ("channel" in data) {
this.channel =
this._client.channels.cache.get(data.channel.id) ?? data.channel;
}
if ("approximate_member_count" in data) {
this.approximateMemberCount = data.approximate_member_count || 0;
}
if ("approximate_presence_count" in data) {
this.approximatePresenceCount = data.approximate_presence_count || 0;
}
if ("guild_scheduled_event" in data) {
this.guildScheduledEvent =
data.guild_scheduled_event && this.guild
? new Guild_1.ScheduledEvent(data.guild_scheduled_event, this.guild)
: null;
if (this.guildScheduledEvent && this.guild instanceof Guild_1.Guild) {
this.guild.scheduledEvents.set(this.guildScheduledEvent.id, this.guildScheduledEvent);
}
}
this.rawData = Object.assign({}, data, this.rawData);
return this;
}
}
exports.Invite = Invite;