From 5334ed895f464edc9c5974939d0df942cb4ecfee Mon Sep 17 00:00:00 2001 From: 0/0 Date: Wed, 9 Aug 2023 15:33:10 +0000 Subject: [PATCH] Add support for setting custom activity status (#2503) This allows custom statuses to be used. See: https://github.com/discord/discord-api-docs/pull/6345 --- src/gateway/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 5be4c7b0205..d2ed1022b92 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -78,6 +78,8 @@ pub struct ActivityData { /// The type of the activity #[serde(rename = "type")] pub kind: ActivityType, + /// The state of the activity, if the type is [`ActivityType::Custom`] + pub state: Option, /// The url of the activity, if the type is [`ActivityType::Streaming`] pub url: Option, } @@ -89,6 +91,7 @@ impl ActivityData { Self { name: name.into(), kind: ActivityType::Playing, + state: None, url: None, } } @@ -103,6 +106,7 @@ impl ActivityData { Ok(Self { name: name.into(), kind: ActivityType::Streaming, + state: None, url: Some(url.into_url()?), }) } @@ -113,6 +117,7 @@ impl ActivityData { Self { name: name.into(), kind: ActivityType::Listening, + state: None, url: None, } } @@ -123,6 +128,7 @@ impl ActivityData { Self { name: name.into(), kind: ActivityType::Watching, + state: None, url: None, } } @@ -133,6 +139,20 @@ impl ActivityData { Self { name: name.into(), kind: ActivityType::Competing, + state: None, + url: None, + } + } + + /// Creates an activity that appears as ``. + #[must_use] + pub fn custom(state: impl Into) -> Self { + Self { + // discord seems to require a name for custom activities + // even though it's not displayed + name: "~".to_string(), + kind: ActivityType::Custom, + state: Some(state.into()), url: None, } } @@ -143,6 +163,7 @@ impl From for ActivityData { Self { name: activity.name, kind: activity.kind, + state: activity.state, url: activity.url, } }