Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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