mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
refactor(PresenceManager): have Presence extend Base and simplify add (#6056)
* refactor(PresenceManager): have Presence extend Base and simplify add * style(Presence): add empty line after super call Co-authored-by: Noel <buechler.noel@outlook.com> Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -19,8 +19,7 @@ class PresenceManager extends CachedManager {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
add(data, cache) {
|
add(data, cache) {
|
||||||
const existing = this.cache.get(data.user.id);
|
return super.add(data, cache, { id: data.user.id });
|
||||||
return existing ? existing.patch(data) : super.add(data, cache, { id: data.user.id });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ClientPresence extends Presence {
|
|||||||
|
|
||||||
set(presence) {
|
set(presence) {
|
||||||
const packet = this._parse(presence);
|
const packet = this._parse(presence);
|
||||||
this.patch(packet);
|
this._patch(packet);
|
||||||
if (typeof presence.shardId === 'undefined') {
|
if (typeof presence.shardId === 'undefined') {
|
||||||
this.client.ws.broadcast({ op: OPCodes.STATUS_UPDATE, d: packet });
|
this.client.ws.broadcast({ op: OPCodes.STATUS_UPDATE, d: packet });
|
||||||
} else if (Array.isArray(presence.shardId)) {
|
} else if (Array.isArray(presence.shardId)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const Base = require('./Base');
|
||||||
const Emoji = require('./Emoji');
|
const Emoji = require('./Emoji');
|
||||||
const ActivityFlags = require('../util/ActivityFlags');
|
const ActivityFlags = require('../util/ActivityFlags');
|
||||||
const { ActivityTypes } = require('../util/Constants');
|
const { ActivityTypes } = require('../util/Constants');
|
||||||
@@ -31,20 +32,16 @@ const Util = require('../util/Util');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a user's presence.
|
* Represents a user's presence.
|
||||||
|
* @extends {Base}
|
||||||
*/
|
*/
|
||||||
class Presence {
|
class Presence extends Base {
|
||||||
/**
|
/**
|
||||||
* @param {Client} client The instantiating client
|
* @param {Client} client The instantiating client
|
||||||
* @param {APIPresence} [data={}] The data for the presence
|
* @param {APIPresence} [data={}] The data for the presence
|
||||||
*/
|
*/
|
||||||
constructor(client, data = {}) {
|
constructor(client, data = {}) {
|
||||||
/**
|
super(client);
|
||||||
* The client that instantiated this
|
|
||||||
* @name Presence#client
|
|
||||||
* @type {Client}
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
Object.defineProperty(this, 'client', { value: client });
|
|
||||||
/**
|
/**
|
||||||
* The presence's user id
|
* The presence's user id
|
||||||
* @type {Snowflake}
|
* @type {Snowflake}
|
||||||
@@ -57,7 +54,7 @@ class Presence {
|
|||||||
*/
|
*/
|
||||||
this.guild = data.guild ?? null;
|
this.guild = data.guild ?? null;
|
||||||
|
|
||||||
this.patch(data);
|
this._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +75,7 @@ class Presence {
|
|||||||
return this.guild.members.resolve(this.userId);
|
return this.guild.members.resolve(this.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
patch(data) {
|
_patch(data) {
|
||||||
/**
|
/**
|
||||||
* The status of this presence
|
* The status of this presence
|
||||||
* @type {PresenceStatus}
|
* @type {PresenceStatus}
|
||||||
|
|||||||
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@@ -1273,10 +1273,9 @@ export class Permissions extends BitField<PermissionString, bigint> {
|
|||||||
public static resolve(permission?: PermissionResolvable): bigint;
|
public static resolve(permission?: PermissionResolvable): bigint;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Presence {
|
export class Presence extends Base {
|
||||||
public constructor(client: Client, data?: unknown);
|
public constructor(client: Client, data?: unknown);
|
||||||
public activities: Activity[];
|
public activities: Activity[];
|
||||||
public readonly client: Client;
|
|
||||||
public clientStatus: ClientPresenceStatusData | null;
|
public clientStatus: ClientPresenceStatusData | null;
|
||||||
public guild: Guild | null;
|
public guild: Guild | null;
|
||||||
public readonly member: GuildMember | null;
|
public readonly member: GuildMember | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user