diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 96ae92c..231d611 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -23,7 +23,7 @@ jobs: run: cargo fmt --check - name: Lint - run: cargo clippy + run: cargo clippy -- -D warnings - name: Tests run: cargo test diff --git a/src/client.rs b/src/client.rs index 6eece7a..8bf394d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,25 +1,57 @@ use serenity::{prelude::GatewayIntents, Client as DiscordClient}; +/// Yorokobot's client. +/// Used for connecting to the Discord API and your MongoDB database +/// +/// # Example +/// ```rust,no_run +/// # async fn run() { +/// use yorokobot::client::{Client, ClientCredentials}; +/// +/// let token = String::from("Your discord token"); +/// +/// let credentials = ClientCredentials { +/// discord_token: &token, +/// }; +/// +/// let mut client = Client::new(credentials).await; +/// +/// client.connect().await; +/// +/// # } +/// ``` +/// pub struct Client { discord_client: DiscordClient, } -pub struct ClientOptions<'a> { +/// Yorokobot connection credentials +pub struct ClientCredentials<'a> { + /// Token for Discord API pub discord_token: &'a String, } impl<'a> Client { - pub async fn new(options: ClientOptions<'a>) -> Client { - let discord_client = DiscordClient::builder(options.discord_token, GatewayIntents::empty()) - .await - .expect("Could not create Discord Client"); + /// Create a Yorokobot client + pub async fn new(credentials: ClientCredentials<'a>) -> Client { + let discord_client = + DiscordClient::builder(credentials.discord_token, GatewayIntents::empty()) + .await + .expect("Could not create Discord Client"); Client { discord_client } } - pub async fn connect_discord(&mut self) -> () { + /// Start connection to Discord API. + /// Wrap [`serenity::client::Client`] start method. + pub async fn connect_discord(&mut self) { if let Err(error) = self.discord_client.start().await { println!("Could not connect to Discord: {:?}", error); } } + + /// Connect client to the Mongo database then to the Discord API. + pub async fn connect(&mut self) { + self.connect_discord().await; + } } diff --git a/src/lib.rs b/src/lib.rs index b9babe5..c18a41e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,10 @@ +//! Discord bot providing a subscription system to topics. +//! Powered by [`Serenity`] +//! +//! [`Serenity`]: https://github.com/serenity-rs/serenity + +#![deny(missing_docs)] +#![deny(warnings)] + +/// Module containing the Yorokobot client and used structs pub mod client; diff --git a/src/main.rs b/src/main.rs index 50f37f7..e135ec0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,16 @@ use std::env; -use yorokobot::client::{Client, ClientOptions}; +use yorokobot::client::{Client, ClientCredentials}; #[tokio::main] async fn main() { let discord_token = env::var("DISCORD_TOKEN").expect("Cannot fetch Discord token"); - let options = ClientOptions { + let credentials = ClientCredentials { discord_token: &discord_token, }; - let mut client = Client::new(options).await; + let mut client = Client::new(credentials).await; client.connect_discord().await; }