Skip to content

Commit

Permalink
✨ Add support for showing party size
Browse files Browse the repository at this point in the history
  • Loading branch information
trickybestia committed Feb 21, 2023
1 parent eb7a0de commit 0e4bf9e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/configs/all-in-one.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def update():
'buttons': [{'label': 'some_button',
'url': 'https://example.com/'
}],
'party': [1, 3], # 'party': [current party size, max party size],
}]

while True:
Expand Down
3 changes: 2 additions & 1 deletion doc/configs/all-in-one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ cat << EOF
"label": "some_button", \
"url": "https://example.com/" \
} \
] \
], \
"party": [1, 3] \
} \
]
EOF
3 changes: 2 additions & 1 deletion doc/configs/hide-presence-when-some-process-is-running.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ while true; do
"label": "some_button", \
"url": "https://example.com/" \
} \
] \
], \
"party": [1, 3] \
} \
]
EOF
Expand Down
4 changes: 4 additions & 0 deletions doc/configs/static.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"label": "some_button",
"url": "https://example.com/"
}
],
"party": [
1,
3
]
}
]
8 changes: 8 additions & 0 deletions doc/update.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
],
"additionalProperties": false
}
},
"party": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "integer"
}
}
},
"required": [
Expand Down
9 changes: 7 additions & 2 deletions src/rich_presence_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::error::Error;

use discord_rich_presence::{
activity::{Activity, Assets, Button, Timestamps},
activity::{Activity, Assets, Button, Party, Timestamps},
DiscordIpc, DiscordIpcClient,
};

Expand All @@ -47,6 +47,7 @@ impl RichPresenceClient {
let mut assets = Assets::new();
let mut activity = Activity::new();
let mut buttons = Vec::new();
let mut party = Party::new();

if let Some(state) = &message.state {
activity = activity.state(state.as_str());
Expand Down Expand Up @@ -77,6 +78,10 @@ impl RichPresenceClient {
timestamps = timestamps.start(end_timestamp);
}

if let Some(party_size) = message.party {
party = party.size(party_size);
}

if !message.buttons.is_empty() {
for button in &message.buttons {
buttons.push(Button::new(button.label.as_str(), button.url.as_str()));
Expand All @@ -85,7 +90,7 @@ impl RichPresenceClient {
activity = activity.buttons(buttons);
}

activity = activity.assets(assets).timestamps(timestamps);
activity = activity.assets(assets).timestamps(timestamps).party(party);

self.client.set_activity(activity)?;

Expand Down
2 changes: 2 additions & 0 deletions src/update_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct UpdateMessageItem {
pub end_timestamp: Option<i64>,
#[serde(default)]
pub buttons: Vec<Button>,
#[serde(default)]
pub party: Option<[i32; 2]>,
}

#[derive(Deserialize)]
Expand Down

0 comments on commit 0e4bf9e

Please sign in to comment.