Skip to content

Commit

Permalink
chore: allow setting activity state (#9743) + (#9742)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaw0r3k authored and vladfrangu committed Nov 5, 2023
1 parent 610bdaa commit f217335
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/structures/ClientPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand All @@ -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,
})),
);
Expand Down
7 changes: 4 additions & 3 deletions src/structures/ClientUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -147,15 +148,15 @@ 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
*/

/**
* 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
Expand Down
7 changes: 4 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export class ClientUser extends User {
public verified: boolean;
public edit(data: ClientUserEditData): Promise<this>;
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 setAvatar(avatar: BufferResolvable | Base64Resolvable | null): Promise<this>;
public setPresence(data: PresenceData): ClientPresence;
Expand Down Expand Up @@ -3795,9 +3795,10 @@ export type ActivityFlagsString =
export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;

export interface ActivityOptions {
name?: string;
name: string;
state?: string;
url?: string;
type?: ExcludeEnum<typeof ActivityTypes, 'CUSTOM'>;
type?: ActivityType;
shardId?: number | readonly number[];
}

Expand Down

0 comments on commit f217335

Please sign in to comment.