UNPKG

detritus-client

Version:

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

58 lines (57 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Presences = void 0; const constants_1 = require("../constants"); const structures_1 = require("../structures"); const basecollection_1 = require("./basecollection"); ; /** * Presences Collection * @category Collections */ class Presences extends basecollection_1.BaseClientCollection { insert(value) { const guildId = value.guild_id || constants_1.LOCAL_GUILD_ID; for (let activity of value.activities) { Object.assign(activity, { guild_id: guildId }); } let presence; if (this.enabled) { if (this.has(value.user.id)) { presence = this.get(value.user.id); if (value.status === constants_1.PresenceStatuses.OFFLINE) { presence._deleteGuildId(guildId); if (presence._shouldDelete) { this.delete(presence.user.id); presence.merge(value); } } else { presence.merge(value); } } else { presence = new structures_1.Presence(this.client, value); if (!presence.isOffline) { this.set(presence.user.id, presence); } } } else { presence = new structures_1.Presence(this.client, value); } return presence; } clearGuildId(guildId) { for (let [userId, presence] of this) { presence._deleteGuildId(guildId); if (presence._shouldDelete) { this.delete(userId); } } } get [Symbol.toStringTag]() { return `Presences (${this.size.toLocaleString()} items)`; } } exports.Presences = Presences;