Skip to content

Commit

Permalink
Add support for setting custom activity status (serenity-rs#2503)
Browse files Browse the repository at this point in the history
This allows custom statuses to be used. See: discord/discord-api-docs#6345
  • Loading branch information
tazz4843 authored and arqunis committed Oct 24, 2023
1 parent 2f56fbf commit 9ffe3ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The url of the activity, if the type is [`ActivityType::Streaming`]
pub url: Option<Url>,
}
Expand All @@ -89,6 +91,7 @@ impl ActivityData {
Self {
name: name.into(),
kind: ActivityType::Playing,
state: None,
url: None,
}
}
Expand All @@ -103,6 +106,7 @@ impl ActivityData {
Ok(Self {
name: name.into(),
kind: ActivityType::Streaming,
state: None,
url: Some(url.into_url()?),
})
}
Expand All @@ -113,6 +117,7 @@ impl ActivityData {
Self {
name: name.into(),
kind: ActivityType::Listening,
state: None,
url: None,
}
}
Expand All @@ -123,6 +128,7 @@ impl ActivityData {
Self {
name: name.into(),
kind: ActivityType::Watching,
state: None,
url: None,
}
}
Expand All @@ -133,6 +139,20 @@ impl ActivityData {
Self {
name: name.into(),
kind: ActivityType::Competing,
state: None,
url: None,
}
}

/// Creates an activity that appears as `<state>`.
#[must_use]
pub fn custom(state: impl Into<String>) -> 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,
}
}
Expand All @@ -143,6 +163,7 @@ impl From<Activity> for ActivityData {
Self {
name: activity.name,
kind: activity.kind,
state: activity.state,
url: activity.url,
}
}
Expand Down

0 comments on commit 9ffe3ed

Please sign in to comment.