mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Presence/Game): multiple activities and custom status (#3747)
* feat(Presence): add activities * feat(Game): add created* and emoji
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { ActivityFlags, Endpoints } = require('../util/Constants');
|
||||
const ReactionEmoji = require('./ReactionEmoji');
|
||||
|
||||
/**
|
||||
* The status of this presence:
|
||||
@@ -30,18 +31,35 @@ class Presence {
|
||||
*/
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
this.update(data);
|
||||
}
|
||||
|
||||
update(data) {
|
||||
/**
|
||||
* The status of this presence:
|
||||
* @type {PresenceStatus}
|
||||
*/
|
||||
this.status = data.status || 'offline';
|
||||
this.status = data.status || this.status || 'offline';
|
||||
|
||||
/**
|
||||
* The game that the user is playing
|
||||
* @type {?Game}
|
||||
* @deprecated
|
||||
*/
|
||||
this.game = data.game ? new Game(data.game, this) : null;
|
||||
|
||||
if (data.activities) {
|
||||
/**
|
||||
* The activities of this presence
|
||||
* @type {Game[]}
|
||||
*/
|
||||
this.activities = data.activities.map(activity => new Game(activity, this));
|
||||
} else if (data.activity || data.game) {
|
||||
this.activities = [new Game(data.activity || data.game, this)];
|
||||
} else {
|
||||
this.activities = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The devices this presence is on
|
||||
* @type {?Object}
|
||||
@@ -52,12 +70,6 @@ class Presence {
|
||||
this.clientStatus = data.client_status || null;
|
||||
}
|
||||
|
||||
update(data) {
|
||||
this.status = data.status || this.status;
|
||||
this.game = data.game ? new Game(data.game, this) : null;
|
||||
this.clientStatus = data.client_status || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this presence is equal to another
|
||||
* @param {Presence} presence The presence to compare with
|
||||
@@ -67,7 +79,8 @@ class Presence {
|
||||
return this === presence || (
|
||||
presence &&
|
||||
this.status === presence.status &&
|
||||
(this.game ? this.game.equals(presence.game) : !presence.game) &&
|
||||
this.activities.length === presence.activities.length &&
|
||||
this.activities.every((activity, index) => activity.equals(presence.activities[index])) &&
|
||||
this.clientStatus.web === presence.clientStatus.web &&
|
||||
this.clientStatus.mobile === presence.clientStatus.mobile &&
|
||||
this.clientStatus.desktop === presence.clientStatus.desktop
|
||||
@@ -147,10 +160,38 @@ class Game {
|
||||
*/
|
||||
this.assets = data.assets ? new RichPresenceAssets(this, data.assets) : null;
|
||||
|
||||
if (data.emoji) {
|
||||
/**
|
||||
* Emoji for a custom activity
|
||||
* <warn>There is no `reaction` property for this emoji.</warn>
|
||||
* @type {?ReactionEmoji}
|
||||
*/
|
||||
this.emoji = new ReactionEmoji({ message: { client: this.presence.client } }, data.emoji);
|
||||
this.emoji.reaction = null;
|
||||
} else {
|
||||
this.emoji = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creation date of the activity
|
||||
* @type {number}
|
||||
*/
|
||||
this.createdTimestamp = new Date(data.created_at).getTime();
|
||||
|
||||
this.syncID = data.sync_id;
|
||||
this._flags = data.flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the activity was created at
|
||||
* @type {Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
get flags() {
|
||||
const flags = [];
|
||||
for (const [name, flag] of Object.entries(ActivityFlags)) {
|
||||
|
||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -439,6 +439,7 @@ declare module 'discord.js' {
|
||||
public applicationID: string;
|
||||
public assets: RichPresenceAssets;
|
||||
public details: string;
|
||||
public emoji: Omit<ReactionEmoji, 'reaction'> | null;
|
||||
public name: string;
|
||||
public readonly streaming: boolean;
|
||||
public party: {
|
||||
@@ -1011,6 +1012,7 @@ declare module 'discord.js' {
|
||||
|
||||
export class Presence {
|
||||
constructor(data: object, client: Client);
|
||||
public activities: Game[];
|
||||
public readonly client: Client;
|
||||
public game: Game;
|
||||
public status: PresenceStatusData;
|
||||
|
||||
Reference in New Issue
Block a user