feat(ClientPresence): allow setting activity state (#9743)

* feat(ClientPresence): allow setting activity state

* fix: add to map

* feat: use name as fallback state
This commit is contained in:
advaith
2023-08-12 04:31:29 -07:00
committed by GitHub
parent 0a9a3ede29
commit 9ed1b59df6
3 changed files with 14 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { GatewayOpcodes } = require('discord-api-types/v10'); const { GatewayOpcodes, ActivityType } = require('discord-api-types/v10');
const { Presence } = require('./Presence'); const { Presence } = require('./Presence');
const { DiscordjsTypeError, ErrorCodes } = require('../errors'); const { DiscordjsTypeError, ErrorCodes } = require('../errors');
@@ -51,11 +51,18 @@ class ClientPresence extends Presence {
if (typeof activity.name !== 'string') { if (typeof activity.name !== 'string') {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, `activities[${i}].name`, 'string'); throw new DiscordjsTypeError(ErrorCodes.InvalidType, `activities[${i}].name`, 'string');
} }
activity.type ??= 0;
activity.type ??= ActivityType.Playing;
if (activity.type === ActivityType.Custom && !activity.state) {
activity.state = activity.name;
activity.name = 'Custom Status';
}
data.activities.push({ data.activities.push({
type: activity.type, type: activity.type,
name: activity.name, name: activity.name,
state: activity.state,
url: activity.url, url: activity.url,
}); });
} }
@@ -63,6 +70,7 @@ class ClientPresence extends Presence {
data.activities.push( data.activities.push(
...this.activities.map(a => ({ ...this.activities.map(a => ({
name: a.name, name: a.name,
state: a.state ?? undefined,
type: a.type, type: a.type,
url: a.url ?? undefined, url: a.url ?? undefined,
})), })),

View File

@@ -99,6 +99,7 @@ class ClientUser extends User {
* Options for setting activities * Options for setting activities
* @typedef {Object} ActivitiesOptions * @typedef {Object} ActivitiesOptions
* @property {string} name Name of the activity * @property {string} name Name of the activity
* @property {string} [state] State of the activity
* @property {ActivityType} [type] Type of the activity * @property {ActivityType} [type] Type of the activity
* @property {string} [url] Twitch / YouTube stream URL * @property {string} [url] Twitch / YouTube stream URL
*/ */
@@ -150,6 +151,7 @@ class ClientUser extends User {
* Options for setting an activity. * Options for setting an activity.
* @typedef {Object} ActivityOptions * @typedef {Object} ActivityOptions
* @property {string} name Name of the activity * @property {string} name Name of the activity
* @property {string} [state] State of the activity
* @property {string} [url] Twitch / YouTube stream URL * @property {string} [url] Twitch / YouTube stream URL
* @property {ActivityType} [type] Type of the activity * @property {ActivityType} [type] Type of the activity
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on * @property {number|number[]} [shardId] Shard Id(s) to have the activity set on

View File

@@ -4323,8 +4323,9 @@ export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;
export interface ActivityOptions { export interface ActivityOptions {
name: string; name: string;
state?: string;
url?: string; url?: string;
type?: Exclude<ActivityType, ActivityType.Custom>; type?: ActivityType;
shardId?: number | readonly number[]; shardId?: number | readonly number[];
} }