UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

74 lines (73 loc) 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Relationship = void 0; const baseset_1 = require("../collections/baseset"); const constants_1 = require("../constants"); const basestructure_1 = require("./basestructure"); const user_1 = require("./user"); const keysRelationship = new baseset_1.BaseSet([ constants_1.DiscordKeys.ID, constants_1.DiscordKeys.TYPE, constants_1.DiscordKeys.USER, ]); /** * Relationship Structure * Used to describe a relationship with a user * (only non-bots) * @category Structure */ class Relationship extends basestructure_1.BaseStructure { constructor(client, data, isClone) { super(client, undefined, isClone); this._keys = keysRelationship; this.id = ''; this.type = constants_1.RelationshipTypes.NONE; this.merge(data); } get isBlocked() { return this.type === constants_1.RelationshipTypes.BLOCKED; } get isFriend() { return this.type === constants_1.RelationshipTypes.FRIEND; } get isImplicit() { return this.type === constants_1.RelationshipTypes.IMPLICIT; } get isNone() { return this.type === constants_1.RelationshipTypes.NONE; } get isPendingIncoming() { return this.type === constants_1.RelationshipTypes.PENDING_INCOMING; } get isPendingOutgoing() { return this.type === constants_1.RelationshipTypes.PENDING_OUTGOING; } mergeValue(key, value) { if (value !== undefined) { switch (key) { case constants_1.DiscordKeys.USER: { let user; if (this.isClone) { user = new user_1.User(this.client, value, this.isClone); } else { if (this.client.users.has(value.id)) { user = this.client.users.get(value.id); user.merge(value); } else { user = new user_1.User(this.client, value); this.client.users.insert(user); } } value = user; } ; break; } return super.mergeValue(key, value); } } } exports.Relationship = Relationship;