Skip to content

Commit

Permalink
feat(presence): allow more types and default to custom
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Oct 25, 2023
1 parent e03222a commit 65032e8
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/commands/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ use crate::Context;

#[derive(poise::ChoiceParameter)]
pub enum PresenceChoice {
Custom,
Playing,
Watching,
Custom,
Listening,
Competing,
}

impl PresenceChoice {
fn make_activity(&self, content: &str) -> serenity::ActivityData {
match self {
Self::Custom => serenity::ActivityData::custom(content),
Self::Playing => serenity::ActivityData::playing(content),
Self::Watching => serenity::ActivityData::watching(content),
Self::Listening => serenity::ActivityData::listening(content),
Self::Competing => serenity::ActivityData::competing(content),
}
}
}

impl Default for PresenceChoice {
fn default() -> Self {
Self::Custom
}
}

impl std::fmt::Display for PresenceChoice {
Expand All @@ -16,22 +36,16 @@ impl std::fmt::Display for PresenceChoice {
f,
"{}",
match self {
PresenceChoice::Playing => "Playing".to_owned(),
PresenceChoice::Watching => "Watching".to_owned(),
PresenceChoice::Custom => "Custom".to_owned(),
Self::Custom => "Custom".to_owned(),
Self::Playing => "Playing".to_owned(),
Self::Watching => "Watching".to_owned(),
Self::Listening => "Listening".to_owned(),
Self::Competing => "Competing".to_owned(),
}
)
}
}

fn make_activity(content: &str, presence_type: &PresenceChoice) -> serenity::ActivityData {
match presence_type {
PresenceChoice::Playing => serenity::ActivityData::playing(content),
PresenceChoice::Watching => serenity::ActivityData::watching(content),
PresenceChoice::Custom => serenity::ActivityData::custom(content),
}
}

/// Modify the Discord presence shown by the bot
#[poise::command(
slash_command,
Expand All @@ -45,10 +59,12 @@ pub async fn presence(

#[rename = "type"]
#[description = "Type of presence"]
type_: PresenceChoice,
type_: Option<PresenceChoice>,
) -> Result<()> {
let type_ = type_.unwrap_or_default();

ctx.serenity_context().set_presence(
Some(make_activity(&content, &type_)),
Some(type_.make_activity(&content)),
serenity::OnlineStatus::Online,
);

Expand Down

0 comments on commit 65032e8

Please sign in to comment.