Generate doc
This commit is contained in:
parent
a66546c5b0
commit
bd87344834
|
@ -1,25 +1,54 @@
|
|||
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
|
||||
/// use yorokobot::client::{Client, ClientCredentials};
|
||||
///
|
||||
/// let discord_token = "Your discord token";
|
||||
///
|
||||
/// let credentials = ClientCredentials {
|
||||
/// discord_token,
|
||||
/// };
|
||||
///
|
||||
/// let client = Client::new(credentials);
|
||||
///
|
||||
/// 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 }
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue