Merge pull request #5 from victormignot/fix-lint-pipeline-warning

Add missing_doc deny options
This commit is contained in:
Victor Mignot 2022-10-17 18:04:22 +00:00 committed by GitHub
commit d29eb3ef5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 10 deletions

View file

@ -23,7 +23,7 @@ jobs:
run: cargo fmt --check
- name: Lint
run: cargo clippy
run: cargo clippy -- -D warnings
- name: Tests
run: cargo test

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;
}