Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Presence): Allow bots to set custom status #1475

Merged
merged 11 commits into from
Jan 22, 2024
13 changes: 6 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"];
bsian03 marked this conversation as resolved.
Show resolved Hide resolved
type FriendSuggestionReasons = { name: string; platform_type: string; type: number }[];
type SelfStatus = Status | "invisible";
type Status = "online" | "idle" | "dnd";
Expand Down Expand Up @@ -1516,7 +1515,7 @@ 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;
type?: T;
url?: string;
Expand Down Expand Up @@ -2661,8 +2660,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 @@ -3703,8 +3702,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
12 changes: 11 additions & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ class Client extends EventEmitter {
* @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 {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
*/
editStatus(status, activities) {
Expand All @@ -2173,6 +2173,16 @@ class Client extends EventEmitter {
activities = [activities];
}
if(activities !== undefined) {
if(activities.length > 0) {
activities = activities.map((a) => {
if(a.hasOwnProperty("type")) {
a.type = a.url ? 1 : 0;
} else if(a.type === 4) {
a.state = a.name;
}
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
return a;
});
}
this.presence.activities = activities;
}

Expand Down
13 changes: 10 additions & 3 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class Shard extends EventEmitter {
* @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 {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
*/
editStatus(status, activities) {
Expand All @@ -234,8 +234,15 @@ 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;
if(activities.length > 0) {
activities = activities.map((a) => {
if(a.hasOwnProperty("type")) {
a.type = a.url ? 1 : 0;
} else if(a.type === 4) {
a.state = a.name;
}
return a;
});
}
this.presence.activities = activities;
}
Expand Down