Formatted project
This commit is contained in:
parent
c5529c384f
commit
c9a0979c51
3 changed files with 19 additions and 18 deletions
32
src/lib.rs
32
src/lib.rs
|
|
@ -1,35 +1,35 @@
|
||||||
//! # Rust Discord Activity
|
//! # Rust Discord Activity
|
||||||
//! _A lightweight Rust library to control Discord Rich Presence_
|
//! _A lightweight Rust library to control Discord Rich Presence_
|
||||||
//!
|
//!
|
||||||
//! ## Installation
|
//! ## Installation
|
||||||
//! Rust Discord Activity is available directly on [crates.io](https://crates.io/crates/rust-discord-activity):
|
//! Rust Discord Activity is available directly on [crates.io](https://crates.io/crates/rust-discord-activity):
|
||||||
//! `cargo add rust-discord-activity`
|
//! `cargo add rust-discord-activity`
|
||||||
//!
|
//!
|
||||||
//! ## How to use
|
//! ## How to use
|
||||||
//! 1. Instantiate a new DiscordClient
|
//! 1. Instantiate a new DiscordClient
|
||||||
//! 2. Create your Activity and set desired data using provided structs
|
//! 2. Create your Activity and set desired data using provided structs
|
||||||
//! 3. Create a new Payload with your Activity
|
//! 3. Create a new Payload with your Activity
|
||||||
//! 4. Send your Payload through the DiscordClient
|
//! 4. Send your Payload through the DiscordClient
|
||||||
//!
|
//!
|
||||||
//! Et voilà !
|
//! Et voilà !
|
||||||
//!
|
//!
|
||||||
//! ## Example
|
//! ## Example
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! let mut client = DiscordClient::new("<application_id>");
|
//! let mut client = DiscordClient::new("<application_id>");
|
||||||
//!
|
//!
|
||||||
//! let limg = Some(String::from("https://placehold.co/600x400/png"));
|
//! let limg = Some(String::from("https://placehold.co/600x400/png"));
|
||||||
//! let simg = Some(String::from("https://placehold.co/200x100/png"));
|
//! let simg = Some(String::from("https://placehold.co/200x100/png"));
|
||||||
//! let asset = Asset::new(limg, None, simg, None);
|
//! let asset = Asset::new(limg, None, simg, None);
|
||||||
//! let now_in_millis = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis();
|
//! let now_in_millis = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis();
|
||||||
//! let timestamp = Timestamp::new(Some(now_in_millis - 10000), None);
|
//! let timestamp = Timestamp::new(Some(now_in_millis - 10000), None);
|
||||||
//!
|
//!
|
||||||
//! let party = Party::new(None, Some((2, 4)));
|
//! let party = Party::new(None, Some((2, 4)));
|
||||||
//! let mut button_vec = vec![];
|
//! let mut button_vec = vec![];
|
||||||
//! button_vec.push(Button::new("First Button".into(), "https://google.com".into()));
|
//! button_vec.push(Button::new("First Button".into(), "https://google.com".into()));
|
||||||
//! button_vec.push(Button::new("Second Button".into(), "https://yahoo.com".into()));
|
//! button_vec.push(Button::new("Second Button".into(), "https://yahoo.com".into()));
|
||||||
//!
|
//!
|
||||||
//! let mut activity = Activity::new();
|
//! let mut activity = Activity::new();
|
||||||
//!
|
//!
|
||||||
//! activity
|
//! activity
|
||||||
//! .set_state(Some("This is State".into()))
|
//! .set_state(Some("This is State".into()))
|
||||||
//! .set_activity_type(Some(ActivityType::LISTENING))
|
//! .set_activity_type(Some(ActivityType::LISTENING))
|
||||||
|
|
@ -39,20 +39,20 @@
|
||||||
//! .set_party(Some(party))
|
//! .set_party(Some(party))
|
||||||
//! .set_instance(Some(true))
|
//! .set_instance(Some(true))
|
||||||
//! .set_buttons(Some(button_vec));
|
//! .set_buttons(Some(button_vec));
|
||||||
//!
|
//!
|
||||||
//! let payload = Payload::new(EventName::Activity, EventData::Activity(activity));
|
//! let payload = Payload::new(EventName::Activity, EventData::Activity(activity));
|
||||||
//!
|
//!
|
||||||
//! let _ = client.send_payload(payload);
|
//! let _ = client.send_payload(payload);
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! And voilà! This sets-up a new Activity for the current Discord user:
|
//! And voilà! This sets-up a new Activity for the current Discord user:
|
||||||
//!
|
//!
|
||||||
//! <img alt="Discord Rich Presence" src="https://imgur.com/gf9pOen.png" width="300"/>
|
//! <img alt="Discord Rich Presence" src="https://imgur.com/gf9pOen.png" width="300"/>
|
||||||
//!
|
//!
|
||||||
//! ## Limitations
|
//! ## Limitations
|
||||||
//! For the moment, the library only works with MacOS and local Discord application.
|
//! For the moment, the library only works with MacOS and local Discord application.
|
||||||
//!
|
//!
|
||||||
//! ## Next Steps
|
//! ## Next Steps
|
||||||
//! - Write proper documentation for this library
|
//! - Write proper documentation for this library
|
||||||
//! - Write unit tests
|
//! - Write unit tests
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ pub struct Activity {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
instance: Option<bool>,
|
instance: Option<bool>,
|
||||||
|
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
flags: Option<i8>,
|
flags: Option<i8>,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ pub enum Error {
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
let msg = match self {
|
let msg = match self {
|
||||||
Error::DiscordNotFound => Cow::Borrowed("Could not connect to client. Is Discord running ?"),
|
Error::DiscordNotFound => {
|
||||||
|
Cow::Borrowed("Could not connect to client. Is Discord running ?")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
f.write_str(&msg)
|
f.write_str(&msg)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue