fix: AFK
This commit is contained in:
@@ -24,15 +24,7 @@ class ClientPresence extends Presence {
|
||||
const packet = this._parse(presence);
|
||||
this._patch(packet);
|
||||
packet.activities = this.activities.map(a => a.toJSON());
|
||||
if (typeof presence.shardId === 'undefined') {
|
||||
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 });
|
||||
}
|
||||
this.client.ws.broadcast({ op: Opcodes.STATUS_UPDATE, d: packet });
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -45,8 +37,8 @@ class ClientPresence extends Presence {
|
||||
_parse({ status, since, afk, activities }) {
|
||||
const data = {
|
||||
activities: [],
|
||||
afk: typeof afk === 'boolean' ? afk : false,
|
||||
since: typeof since === 'number' && !Number.isNaN(since) ? since : 0,
|
||||
afk: typeof afk === 'boolean' ? afk : this.afk,
|
||||
since: typeof since === 'number' && !Number.isNaN(since) ? this.since : 0,
|
||||
status: status ?? this.status,
|
||||
};
|
||||
if (activities?.length) {
|
||||
|
||||
@@ -130,6 +130,18 @@ class Presence extends Base {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class Options extends null {
|
||||
restTimeOffset: 500,
|
||||
restSweepInterval: 60,
|
||||
failIfNotExists: true,
|
||||
presence: { status: 'online', since: 0, activities: [], afk: false },
|
||||
presence: { status: 'online', since: 0, activities: [], afk: true },
|
||||
sweepers: {},
|
||||
ws: {
|
||||
capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities
|
||||
|
||||
Reference in New Issue
Block a user