fix: missing all other status
This commit is contained in:
parent
be786d3876
commit
cf11132275
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { Presence } = require('./Presence');
|
||||
const { CustomStatus } = require('./RichPresence');
|
||||
const { TypeError } = require('../errors');
|
||||
const { Opcodes, ActivityTypes } = require('../util/Constants');
|
||||
|
||||
@ -21,7 +20,8 @@ class ClientPresence extends Presence {
|
||||
*/
|
||||
set(presence) {
|
||||
const packet = this._parse(presence);
|
||||
this._patch(packet);
|
||||
// Parse with custom class
|
||||
this._patch(packet, true);
|
||||
if (typeof presence.shardId === 'undefined') {
|
||||
this.client.ws.broadcast({ op: Opcodes.STATUS_UPDATE, d: packet });
|
||||
} else if (Array.isArray(presence.shardId)) {
|
||||
@ -31,6 +31,8 @@ class ClientPresence extends Presence {
|
||||
} else {
|
||||
this.client.ws.shards.get(presence.shardId).send({ op: Opcodes.STATUS_UPDATE, d: packet });
|
||||
}
|
||||
// Parse with default class
|
||||
// this._patch(packet, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -49,7 +51,7 @@ class ClientPresence extends Presence {
|
||||
};
|
||||
if (activities?.length) {
|
||||
for (const [i, activity] of activities.entries()) {
|
||||
if (!(activity instanceof CustomStatus) && typeof activity.name !== 'string') {
|
||||
if (![ActivityTypes.CUSTOM, 'CUSTOM'].includes(activity.type) && typeof activity.name !== 'string') {
|
||||
throw new TypeError('INVALID_TYPE', `activities[${i}].name`, 'string');
|
||||
}
|
||||
activity.type ??= 0;
|
||||
@ -63,9 +65,7 @@ class ClientPresence extends Presence {
|
||||
data.activities.push(
|
||||
...this.activities.map(a =>
|
||||
Object.assign(a, {
|
||||
name: a.name,
|
||||
type: ActivityTypes[a.type],
|
||||
url: a.url ?? undefined,
|
||||
type: typeof a.type === 'number' ? a.type : ActivityTypes[a.type],
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const Base = require('./Base');
|
||||
const { Emoji } = require('./Emoji');
|
||||
const { CustomStatus, SpotifyRPC, RichPresence } = require('./RichPresence');
|
||||
const ActivityFlags = require('../util/ActivityFlags');
|
||||
const { ActivityTypes } = require('../util/Constants');
|
||||
const Util = require('../util/Util');
|
||||
@ -76,7 +77,7 @@ class Presence extends Base {
|
||||
return this.guild.members.resolve(this.userId);
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
_patch(data, fromClient) {
|
||||
if ('status' in data) {
|
||||
/**
|
||||
* The status of this presence
|
||||
@ -92,7 +93,19 @@ class Presence extends Base {
|
||||
* The activities of this presence
|
||||
* @type {Activity[]}
|
||||
*/
|
||||
this.activities = data.activities.map(activity => new Activity(this, activity));
|
||||
this.activities = data.activities.map(activity => {
|
||||
if (fromClient === true) {
|
||||
if ([ActivityTypes.CUSTOM, 'CUSTOM'].includes(activity.type)) {
|
||||
return new CustomStatus(activity, this);
|
||||
} else if (activity.id == 'spotify:1') {
|
||||
return new SpotifyRPC(this.client, activity, this);
|
||||
} else {
|
||||
return new RichPresence(this.client, activity, this);
|
||||
}
|
||||
} else {
|
||||
return new Activity(this, activity);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.activities ??= [];
|
||||
}
|
||||
|
@ -19,8 +19,10 @@ class CustomStatus {
|
||||
|
||||
/**
|
||||
* @param {CustomStatus|CustomStatusOptions} [data={}] CustomStatus to clone or raw data
|
||||
* @param {Presence} [presence] The presence this activity is part of
|
||||
*/
|
||||
constructor(data = {}) {
|
||||
constructor(data = {}, presence) {
|
||||
Object.defineProperty(this, 'presence', { value: presence });
|
||||
this.name = 'Custom Status';
|
||||
/**
|
||||
* The emoji to be displayed
|
||||
@ -96,9 +98,11 @@ class RichPresence {
|
||||
* @param {Client} [client] Discord client
|
||||
* @param {RichPresence} [data={}] RichPresence to clone or raw data
|
||||
* @param {boolean} [IPC=false] Whether to use IPC (RPC for Discord Apps)
|
||||
* @param {Presence} [presence] The presence this activity is part of
|
||||
*/
|
||||
constructor(client = {}, data = {}, IPC = false) {
|
||||
constructor(client = {}, data = {}, IPC = false, presence) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
Object.defineProperty(this, 'presence', { value: presence });
|
||||
/**
|
||||
* The activity's name
|
||||
* @type {string}
|
||||
@ -552,10 +556,11 @@ class SpotifyRPC extends RichPresence {
|
||||
* Create a new RichPresence (Spotify style)
|
||||
* @param {Client} client Discord Client
|
||||
* @param {SpotifyRPC} options Options for the Spotify RPC
|
||||
* @param {Presence} presence Presence
|
||||
*/
|
||||
constructor(client, options = {}) {
|
||||
constructor(client, options = {}, presence) {
|
||||
if (!client) throw new Error('Client must be set');
|
||||
super(client, options);
|
||||
super(client, options, false, presence);
|
||||
this.setup(options);
|
||||
}
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user