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