PresenceManager.js
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const CachedManager = require('./CachedManager');
const { Presence } = require('../structures/Presence');
/**
* Manages API methods for Presences and holds their cache.
* @extends {CachedManager}
*/
class PresenceManager extends CachedManager {
constructor(client, iterable) {
super(client, Presence, iterable);
}
/**
* The cache of Presences
* @type {Collection<Snowflake, Presence>}
* @name PresenceManager#cache
*/
_add(data, cache) {
return super._add(data, cache, { id: data.user.id });
}
/**
* Data that can be resolved to a Presence object. This can be:
* * A Presence
* * A UserResolvable
* * A Snowflake
* @typedef {Presence|UserResolvable|Snowflake} PresenceResolvable
*/
/**
* Resolves a {@link PresenceResolvable} to a {@link Presence} object.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Presence}
*/
resolve(presence) {
const presenceResolvable = super.resolve(presence);
if (presenceResolvable) return presenceResolvable;
const UserResolvable = this.client.users.resolveId(presence);
return super.resolve(UserResolvable);
}
/**
* Resolves a {@link PresenceResolvable} to a {@link Presence} id.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Snowflake}
*/
resolveId(presence) {
const presenceResolvable = super.resolveId(presence);
if (presenceResolvable) return presenceResolvable;
const userResolvable = this.client.users.resolveId(presence);
return this.cache.has(userResolvable) ? userResolvable : null;
}
}
module.exports = PresenceManager;