This commit is contained in:
Elysia
2024-07-24 12:06:52 +07:00
parent bbbf40c5ac
commit 7fa4666df0
3 changed files with 16 additions and 12 deletions

View File

@@ -24,15 +24,7 @@ class ClientPresence extends Presence {
const packet = this._parse(presence); const packet = this._parse(presence);
this._patch(packet); this._patch(packet);
packet.activities = this.activities.map(a => a.toJSON()); packet.activities = this.activities.map(a => a.toJSON());
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)) {
for (const shardId of presence.shardId) {
this.client.ws.shards.get(shardId).send({ op: Opcodes.STATUS_UPDATE, d: packet });
}
} else {
this.client.ws.shards.get(presence.shardId).send({ op: Opcodes.STATUS_UPDATE, d: packet });
}
return this; return this;
} }
@@ -45,8 +37,8 @@ class ClientPresence extends Presence {
_parse({ status, since, afk, activities }) { _parse({ status, since, afk, activities }) {
const data = { const data = {
activities: [], activities: [],
afk: typeof afk === 'boolean' ? afk : false, afk: typeof afk === 'boolean' ? afk : this.afk,
since: typeof since === 'number' && !Number.isNaN(since) ? since : 0, since: typeof since === 'number' && !Number.isNaN(since) ? this.since : 0,
status: status ?? this.status, status: status ?? this.status,
}; };
if (activities?.length) { if (activities?.length) {

View File

@@ -130,6 +130,18 @@ class Presence extends Base {
this.lastModified = data.last_modified; this.lastModified = data.last_modified;
} }
if ('afk' in data) {
this.afk = data.afk;
} else {
this.afk ??= false;
}
if ('since' in data) {
this.since = data.since;
} else {
this.since ??= 0;
}
return this; return this;
} }

View File

@@ -171,7 +171,7 @@ class Options extends null {
restTimeOffset: 500, restTimeOffset: 500,
restSweepInterval: 60, restSweepInterval: 60,
failIfNotExists: true, failIfNotExists: true,
presence: { status: 'online', since: 0, activities: [], afk: false }, presence: { status: 'online', since: 0, activities: [], afk: true },
sweepers: {}, sweepers: {},
ws: { ws: {
capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities