From 03471870a709cda11bc5027c9e043ce37696bee5 Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Sat, 12 Aug 2023 13:59:39 +0200 Subject: [PATCH] chore: allow setting activity state (#9743) + (#9742) --- src/structures/ClientPresence.js | 10 +++++++++- src/structures/ClientUser.js | 7 ++++--- typings/index.d.ts | 7 ++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/structures/ClientPresence.js b/src/structures/ClientPresence.js index 04ccce6e45531..9b0217debb78c 100644 --- a/src/structures/ClientPresence.js +++ b/src/structures/ClientPresence.js @@ -49,11 +49,18 @@ class ClientPresence extends Presence { if (activities?.length) { for (const [i, activity] of activities.entries()) { if (typeof activity.name !== 'string') throw new TypeError('INVALID_TYPE', `activities[${i}].name`, 'string'); - activity.type ??= 0; + + activity.type ??= ActivityTypes.PLAYING; + + if (activity.type === ActivityType.CUSTOM && !activity.state) { + activity.state = activity.name; + activity.name = 'Custom Status'; + } data.activities.push({ type: typeof activity.type === 'number' ? activity.type : ActivityTypes[activity.type], name: activity.name, + state: activity.state, url: activity.url, }); } @@ -62,6 +69,7 @@ class ClientPresence extends Presence { ...this.activities.map(a => ({ name: a.name, type: ActivityTypes[a.type], + state: activity.state ?? undefined, url: a.url ?? undefined, })), ); diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 61e2522e7defa..4af22b74baadb 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -96,7 +96,8 @@ class ClientUser extends User { /** * Options for setting activities * @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|number} [type] Type of the activity * @property {string} [url] Twitch / YouTube stream URL */ @@ -147,7 +148,7 @@ class ClientUser extends User { /** * Options for setting an activity. * @typedef {Object} ActivityOptions - * @property {string} [name] Name of the activity + * @property {string} name Name of the activity * @property {string} [url] Twitch / YouTube stream URL * @property {ActivityType|number} [type] Type of the activity * @property {number|number[]} [shardId] Shard Id(s) to have the activity set on @@ -155,7 +156,7 @@ class ClientUser extends User { /** * Sets the activity the client user is playing. - * @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity + * @param {string|ActivityOptions} name Activity being played, or options for setting the activity * @param {ActivityOptions} [options] Options for setting the activity * @returns {ClientPresence} * @example diff --git a/typings/index.d.ts b/typings/index.d.ts index 5dc7baf2288c6..52e53a00fb401 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -707,7 +707,7 @@ export class ClientUser extends User { public verified: boolean; public edit(data: ClientUserEditData): Promise; public setActivity(options?: ActivityOptions): ClientPresence; - public setActivity(name: string, options?: ActivityOptions): ClientPresence; + public setActivity(name: string, options?: Omit): ClientPresence; public setAFK(afk?: boolean, shardId?: number | number[]): ClientPresence; public setAvatar(avatar: BufferResolvable | Base64Resolvable | null): Promise; public setPresence(data: PresenceData): ClientPresence; @@ -3794,9 +3794,10 @@ export type ActivityFlagsString = export type ActivitiesOptions = Omit; export interface ActivityOptions { - name?: string; + name: string; + state?: string; url?: string; - type?: ExcludeEnum; + type?: ActivityType; shardId?: number | readonly number[]; }