Skip to content

Commit

Permalink
feat(Presence): Document custom status (#1475)
Browse files Browse the repository at this point in the history
Co-authored-by: bsian03 <chharry321@gmail.com>
  • Loading branch information
conorwastakenwastaken and bsian03 authored Jan 22, 2024
1 parent 3b0dd35 commit 9b18e0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ declare namespace Eris {

// Presence/Relationship
type ActivityFlags = Constants["ActivityFlags"][keyof Constants["ActivityFlags"]];
type ActivityType = BotActivityType | Constants["ActivityTypes"]["CUSTOM"];
type BotActivityType = Constants["ActivityTypes"][Exclude<keyof Constants["ActivityTypes"], "CUSTOM">];
type ActivityType = Constants["ActivityTypes"][keyof Constants["ActivityTypes"]];
type FriendSuggestionReasons = { name: string; platform_type: string; type: number }[];
type SelfStatus = Status | "invisible";
type Status = "online" | "idle" | "dnd";
Expand Down Expand Up @@ -1519,8 +1518,9 @@ declare namespace Eris {
// the stuff attached to this object apparently varies even more than documented, so...
[key: string]: unknown;
}
interface ActivityPartial<T extends ActivityType = BotActivityType> {
interface ActivityPartial<T extends ActivityType> {
name: string;
state?: string;
type?: T;
url?: string;
}
Expand Down Expand Up @@ -2665,8 +2665,8 @@ declare namespace Eris {
): Promise<Connection>;
editSelfSettings(data: UserSettings): Promise<UserSettings>;
editStageInstance(channelID: string, options: StageInstanceOptions): Promise<StageInstance>;
editStatus(status: SelfStatus, activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editStatus(activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editStatus(status: SelfStatus, activities?: ActivityPartial<ActivityType>[] | ActivityPartial<ActivityType>): void;
editStatus(activities?: ActivityPartial<ActivityType>[] | ActivityPartial<ActivityType>): void;
editUserNote(userID: string, note: string): Promise<void>;
editWebhook(
webhookID: string,
Expand Down Expand Up @@ -3708,8 +3708,8 @@ declare namespace Eris {
createGuild(_guild: Guild): Guild;
disconnect(options?: { reconnect?: boolean | "auto" }, error?: Error): void;
editAFK(afk: boolean): void;
editStatus(status: SelfStatus, activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editStatus(activities?: ActivityPartial<BotActivityType>[] | ActivityPartial<BotActivityType>): void;
editStatus(status: SelfStatus, activities?: ActivityPartial<ActivityType>[] | ActivityPartial<ActivityType>): void;
editStatus(activities?: ActivityPartial<ActivityType>[] | ActivityPartial<ActivityType>): void;
// @ts-ignore: Method override
emit(event: string, ...args: any[]): void;
emit<K extends keyof ShardEvents>(event: K, ...args: ShardEvents[K]): boolean;
Expand Down
5 changes: 3 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,9 +2169,10 @@ class Client extends EventEmitter {
* Update the bot's status on all guilds
* @arg {String} [status] Sets the bot's status, either "online", "idle", "dnd", or "invisible"
* @arg {Array | Object} [activities] Sets the bot's activities. A single activity object is also accepted for backwards compatibility
* @arg {String} activities[].name The name of the activity
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 5 is competing in
* @arg {String} [activities[].name] The name of the activity. Note: When setting a custom status, use `state` instead
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 4 is custom status, 5 is competing in
* @arg {String} [activities[].url] The URL of the activity
* @arg {String} [activities[].state] The state of the activity. This is the text to be displayed as the bots custom status
*/
editStatus(status, activities) {
if(activities === undefined && typeof status === "object") {
Expand Down
8 changes: 3 additions & 5 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ class Shard extends EventEmitter {
* Updates the bot's status on all guilds the shard is in
* @arg {String} [status] Sets the bot's status, either "online", "idle", "dnd", or "invisible"
* @arg {Array | Object} [activities] Sets the bot's activities. A single activity object is also accepted for backwards compatibility
* @arg {String} activities[].name The name of the activity
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 5 is competing in
* @arg {String} [activities[].name] The name of the activity. Note: When setting a custom status, use `state` instead
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 4 is custom status, 5 is competing in
* @arg {String} [activities[].url] The URL of the activity
* @arg {String} [activities[].state] The state of the activity. This is the text to be displayed as the bots custom status
*/
editStatus(status, activities) {
if(activities === undefined && typeof status === "object") {
Expand All @@ -234,9 +235,6 @@ class Shard extends EventEmitter {
activities = [activities];
}
if(activities !== undefined) {
if(activities.length > 0 && !activities[0].hasOwnProperty("type")) {
activities[0].type = activities[0].url ? 1 : 0;
}
this.presence.activities = activities;
}

Expand Down

0 comments on commit 9b18e0e

Please sign in to comment.