pub struct ActivityBuilder { /* private fields */ }Expand description
A builder for a Rich Presence activity.
To build an Activity out of it, use ActivityBuilder::build.
Implementations§
Source§impl ActivityBuilder
impl ActivityBuilder
Sourcepub fn name(self, text: impl Into<String>) -> Self
pub fn name(self, text: impl Into<String>) -> Self
Name of the activity.
Examples found in repository?
4async fn main() -> Result<(), PresenceError> {
5 let mut runner = PresenceRunner::new("1463450870480900160");
6
7 let activity = Activity::new()
8 .name("cool app name")
9 .details("Something?")
10 .state("Probably~")
11 .build();
12
13 let client = runner.run(true).await?;
14 client.set_activity(activity).await?;
15
16 // indefinitely block here
17 runner.wait().await?;
18
19 Ok(())
20}Sourcepub fn activity_type(self, type: ActivityType) -> Self
pub fn activity_type(self, type: ActivityType) -> Self
The type of activity you want to create.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn details(self, text: impl Into<String>) -> Self
pub fn details(self, text: impl Into<String>) -> Self
Top text for your activity.
Examples found in repository?
4async fn main() -> Result<(), PresenceError> {
5 let mut runner = PresenceRunner::new("1463450870480900160");
6
7 let activity = Activity::new()
8 .name("cool app name")
9 .details("Something?")
10 .state("Probably~")
11 .build();
12
13 let client = runner.run(true).await?;
14 client.set_activity(activity).await?;
15
16 // indefinitely block here
17 runner.wait().await?;
18
19 Ok(())
20}More examples
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}13async fn main() -> Result<(), PresenceError> {
14 // simple atomic counter
15 let count = Arc::new(AtomicU8::new(0));
16
17 let mut runner = PresenceRunner::new("1463450870480900160")
18 .on_ready(|data| println!("Connected to user: {}", data.user.username))
19 .on_activity_send(move |_| {
20
21 // increments the counter with every send_activity()
22 let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24 println!("Activity {val} sent successfully.")
25
26 })
27 .show_errors() // enables verbose error logging
28 ;
29
30 // create activities for later use
31 let activity_1 = Activity::new()
32 .details("this runs")
33 .state("for ten seconds")
34 .build();
35
36 let activity_2 = Activity::new()
37 .details("believe it")
38 .state("or not")
39 .build();
40
41 let closing_activity = Activity::new()
42 .details("closing presence in...")
43 .duration(Duration::from_secs(5))
44 .small_image("status")
45 .build();
46
47 // first run
48 let client = runner.run(true).await?;
49
50 client.set_activity(activity_1).await?;
51 sleep(Duration::from_secs(5)).await;
52 client.set_activity(activity_2).await?;
53 sleep(Duration::from_secs(5)).await;
54 client.set_activity(closing_activity).await?;
55 sleep(Duration::from_secs(5)).await;
56
57 client.close().await?;
58
59 println!("Stopped.");
60
61 Ok(())
62}Sourcepub fn details_url(self, url: impl Into<String>) -> Self
pub fn details_url(self, url: impl Into<String>) -> Self
URL for the top text of your activity.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn state(self, text: impl Into<String>) -> Self
pub fn state(self, text: impl Into<String>) -> Self
Bottom text for your activity.
Examples found in repository?
4async fn main() -> Result<(), PresenceError> {
5 let mut runner = PresenceRunner::new("1463450870480900160");
6
7 let activity = Activity::new()
8 .name("cool app name")
9 .details("Something?")
10 .state("Probably~")
11 .build();
12
13 let client = runner.run(true).await?;
14 client.set_activity(activity).await?;
15
16 // indefinitely block here
17 runner.wait().await?;
18
19 Ok(())
20}More examples
13async fn main() -> Result<(), PresenceError> {
14 // simple atomic counter
15 let count = Arc::new(AtomicU8::new(0));
16
17 let mut runner = PresenceRunner::new("1463450870480900160")
18 .on_ready(|data| println!("Connected to user: {}", data.user.username))
19 .on_activity_send(move |_| {
20
21 // increments the counter with every send_activity()
22 let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24 println!("Activity {val} sent successfully.")
25
26 })
27 .show_errors() // enables verbose error logging
28 ;
29
30 // create activities for later use
31 let activity_1 = Activity::new()
32 .details("this runs")
33 .state("for ten seconds")
34 .build();
35
36 let activity_2 = Activity::new()
37 .details("believe it")
38 .state("or not")
39 .build();
40
41 let closing_activity = Activity::new()
42 .details("closing presence in...")
43 .duration(Duration::from_secs(5))
44 .small_image("status")
45 .build();
46
47 // first run
48 let client = runner.run(true).await?;
49
50 client.set_activity(activity_1).await?;
51 sleep(Duration::from_secs(5)).await;
52 client.set_activity(activity_2).await?;
53 sleep(Duration::from_secs(5)).await;
54 client.set_activity(closing_activity).await?;
55 sleep(Duration::from_secs(5)).await;
56
57 client.close().await?;
58
59 println!("Stopped.");
60
61 Ok(())
62}Sourcepub fn state_url(self, url: impl Into<String>) -> Self
pub fn state_url(self, url: impl Into<String>) -> Self
URL for the bottom text of your activity.
Sourcepub fn set_as_instance(self) -> Self
pub fn set_as_instance(self) -> Self
Sets the activity to be an instance.
Sourcepub fn status_display_type(self, type: StatusDisplayType) -> Self
pub fn status_display_type(self, type: StatusDisplayType) -> Self
The status display type for the activity.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn duration(self, duration: Duration) -> Self
pub fn duration(self, duration: Duration) -> Self
Countdown duration for your activity.
Examples found in repository?
13async fn main() -> Result<(), PresenceError> {
14 // simple atomic counter
15 let count = Arc::new(AtomicU8::new(0));
16
17 let mut runner = PresenceRunner::new("1463450870480900160")
18 .on_ready(|data| println!("Connected to user: {}", data.user.username))
19 .on_activity_send(move |_| {
20
21 // increments the counter with every send_activity()
22 let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24 println!("Activity {val} sent successfully.")
25
26 })
27 .show_errors() // enables verbose error logging
28 ;
29
30 // create activities for later use
31 let activity_1 = Activity::new()
32 .details("this runs")
33 .state("for ten seconds")
34 .build();
35
36 let activity_2 = Activity::new()
37 .details("believe it")
38 .state("or not")
39 .build();
40
41 let closing_activity = Activity::new()
42 .details("closing presence in...")
43 .duration(Duration::from_secs(5))
44 .small_image("status")
45 .build();
46
47 // first run
48 let client = runner.run(true).await?;
49
50 client.set_activity(activity_1).await?;
51 sleep(Duration::from_secs(5)).await;
52 client.set_activity(activity_2).await?;
53 sleep(Duration::from_secs(5)).await;
54 client.set_activity(closing_activity).await?;
55 sleep(Duration::from_secs(5)).await;
56
57 client.close().await?;
58
59 println!("Stopped.");
60
61 Ok(())
62}Adds a button to the activity.
NOTE: The Discord desktop client may behave in such a way that the buttons may only be visible from anyone but the connected user’s side. This is a wonky feature and must be used with care.
Sourcepub fn large_image(self, key: impl Into<String>) -> Self
pub fn large_image(self, key: impl Into<String>) -> Self
Large image for your activity (e.g., game icon).
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn large_text(self, text: impl Into<String>) -> Self
pub fn large_text(self, text: impl Into<String>) -> Self
Text for the large image of your activity.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn large_url(self, url: impl Into<String>) -> Self
pub fn large_url(self, url: impl Into<String>) -> Self
URL for the large image of your activity.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn small_image(self, key: impl Into<String>) -> Self
pub fn small_image(self, key: impl Into<String>) -> Self
Small image for your activity (e.g., game icon).
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}More examples
13async fn main() -> Result<(), PresenceError> {
14 // simple atomic counter
15 let count = Arc::new(AtomicU8::new(0));
16
17 let mut runner = PresenceRunner::new("1463450870480900160")
18 .on_ready(|data| println!("Connected to user: {}", data.user.username))
19 .on_activity_send(move |_| {
20
21 // increments the counter with every send_activity()
22 let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24 println!("Activity {val} sent successfully.")
25
26 })
27 .show_errors() // enables verbose error logging
28 ;
29
30 // create activities for later use
31 let activity_1 = Activity::new()
32 .details("this runs")
33 .state("for ten seconds")
34 .build();
35
36 let activity_2 = Activity::new()
37 .details("believe it")
38 .state("or not")
39 .build();
40
41 let closing_activity = Activity::new()
42 .details("closing presence in...")
43 .duration(Duration::from_secs(5))
44 .small_image("status")
45 .build();
46
47 // first run
48 let client = runner.run(true).await?;
49
50 client.set_activity(activity_1).await?;
51 sleep(Duration::from_secs(5)).await;
52 client.set_activity(activity_2).await?;
53 sleep(Duration::from_secs(5)).await;
54 client.set_activity(closing_activity).await?;
55 sleep(Duration::from_secs(5)).await;
56
57 client.close().await?;
58
59 println!("Stopped.");
60
61 Ok(())
62}Sourcepub fn small_text(self, text: impl Into<String>) -> Self
pub fn small_text(self, text: impl Into<String>) -> Self
Text for the small image of your activity.
Examples found in repository?
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}Sourcepub fn small_url(self, url: impl Into<String>) -> Self
pub fn small_url(self, url: impl Into<String>) -> Self
URL for the small image of your activity.
Sourcepub fn build(self) -> Activity
pub fn build(self) -> Activity
Parses the state of this builder into a usable Activity for you to pass through super::PresenceClient::set_activity.
Examples found in repository?
4async fn main() -> Result<(), PresenceError> {
5 let mut runner = PresenceRunner::new("1463450870480900160");
6
7 let activity = Activity::new()
8 .name("cool app name")
9 .details("Something?")
10 .state("Probably~")
11 .build();
12
13 let client = runner.run(true).await?;
14 client.set_activity(activity).await?;
15
16 // indefinitely block here
17 runner.wait().await?;
18
19 Ok(())
20}More examples
8async fn main() -> Result<(), PresenceError> {
9 let mut runner = PresenceRunner::new("1463450870480900160")
10 .on_ready(|data| println!("Connected to user: {}", data.user.username))
11 .on_activity_send(|data| {
12 println!("Activity sent to app: {} (running on {})\nMetadata: {}", data.name, data.platform, data.metadata)
13 })
14 .on_disconnect(|f| println!("Disconnected: {f:?}"))
15 .show_errors() // enables verbose error logging
16 ;
17
18 let client = runner.run(true).await?;
19
20 // the activity can include any combination of builder function calls
21 let activity = Activity::new()
22 .activity_type(ActivityType::Playing)
23 .details("epic game")
24 .details_url("https://github.com/hitblast")
25 .status_display_type(StatusDisplayType::Details)
26 .large_image("game_icon")
27 .large_text("Playing a game")
28 .large_url("https://hitblast.github.io/")
29 .small_image("status")
30 .small_text("Online")
31 .build();
32
33 client.set_activity(activity).await?;
34
35 // indefinitely block here
36 runner.wait().await?;
37
38 Ok(())
39}13async fn main() -> Result<(), PresenceError> {
14 // simple atomic counter
15 let count = Arc::new(AtomicU8::new(0));
16
17 let mut runner = PresenceRunner::new("1463450870480900160")
18 .on_ready(|data| println!("Connected to user: {}", data.user.username))
19 .on_activity_send(move |_| {
20
21 // increments the counter with every send_activity()
22 let val = count.fetch_add(1, Ordering::Relaxed) + 1;
23
24 println!("Activity {val} sent successfully.")
25
26 })
27 .show_errors() // enables verbose error logging
28 ;
29
30 // create activities for later use
31 let activity_1 = Activity::new()
32 .details("this runs")
33 .state("for ten seconds")
34 .build();
35
36 let activity_2 = Activity::new()
37 .details("believe it")
38 .state("or not")
39 .build();
40
41 let closing_activity = Activity::new()
42 .details("closing presence in...")
43 .duration(Duration::from_secs(5))
44 .small_image("status")
45 .build();
46
47 // first run
48 let client = runner.run(true).await?;
49
50 client.set_activity(activity_1).await?;
51 sleep(Duration::from_secs(5)).await;
52 client.set_activity(activity_2).await?;
53 sleep(Duration::from_secs(5)).await;
54 client.set_activity(closing_activity).await?;
55 sleep(Duration::from_secs(5)).await;
56
57 client.close().await?;
58
59 println!("Stopped.");
60
61 Ok(())
62}