chore: allow setting activity state (#9743) + (#9742)

This commit is contained in:
Jaw0r3k
2023-08-12 13:59:39 +02:00
committed by Vlad Frangu
parent 610bdaa0f1
commit f217335a9d
3 changed files with 17 additions and 7 deletions

View File

@@ -49,11 +49,18 @@ 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 (typeof activity.name !== 'string') throw new TypeError('INVALID_TYPE', `activities[${i}].name`, 'string'); 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({ data.activities.push({
type: typeof activity.type === 'number' ? activity.type : ActivityTypes[activity.type], type: typeof activity.type === 'number' ? activity.type : ActivityTypes[activity.type],
name: activity.name, name: activity.name,
state: activity.state,
url: activity.url, url: activity.url,
}); });
} }
@@ -62,6 +69,7 @@ class ClientPresence extends Presence {
...this.activities.map(a => ({ ...this.activities.map(a => ({
name: a.name, name: a.name,
type: ActivityTypes[a.type], type: ActivityTypes[a.type],
state: activity.state ?? undefined,
url: a.url ?? undefined, url: a.url ?? undefined,
})), })),
); );

View File

@@ -96,7 +96,8 @@ 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|number} [type] Type of the activity * @property {ActivityType|number} [type] Type of the activity
* @property {string} [url] Twitch / YouTube stream URL * @property {string} [url] Twitch / YouTube stream URL
*/ */
@@ -147,7 +148,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} [url] Twitch / YouTube stream URL * @property {string} [url] Twitch / YouTube stream URL
* @property {ActivityType|number} [type] Type of the activity * @property {ActivityType|number} [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
@@ -155,7 +156,7 @@ class ClientUser extends User {
/** /**
* Sets the activity the client user is playing. * 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 * @param {ActivityOptions} [options] Options for setting the activity
* @returns {ClientPresence} * @returns {ClientPresence}
* @example * @example

7
typings/index.d.ts vendored
View File

@@ -708,7 +708,7 @@ export class ClientUser extends User {
public verified: boolean; public verified: boolean;
public edit(data: ClientUserEditData): Promise<this>; public edit(data: ClientUserEditData): Promise<this>;
public setActivity(options?: ActivityOptions): ClientPresence; public setActivity(options?: ActivityOptions): ClientPresence;
public setActivity(name: string, options?: ActivityOptions): ClientPresence; public setActivity(name: string, options?: Omit<ActivityOptions, 'name'>): ClientPresence;
public setAFK(afk?: boolean, shardId?: number | number[]): ClientPresence; public setAFK(afk?: boolean, shardId?: number | number[]): ClientPresence;
public setAvatar(avatar: BufferResolvable | Base64Resolvable | null): Promise<this>; public setAvatar(avatar: BufferResolvable | Base64Resolvable | null): Promise<this>;
public setPresence(data: PresenceData): ClientPresence; public setPresence(data: PresenceData): ClientPresence;
@@ -3795,9 +3795,10 @@ export type ActivityFlagsString =
export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>; export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;
export interface ActivityOptions { export interface ActivityOptions {
name?: string; name: string;
state?: string;
url?: string; url?: string;
type?: ExcludeEnum<typeof ActivityTypes, 'CUSTOM'>; type?: ActivityType;
shardId?: number | readonly number[]; shardId?: number | readonly number[];
} }