Add Discord connection

This commit is contained in:
Victor Mignot 2022-10-17 00:13:26 -04:00
parent 8b873e1fef
commit 42b7d04e32
No known key found for this signature in database
GPG key ID: FFE4EF056FB5E0D0
3 changed files with 41 additions and 2 deletions

25
src/client.rs Normal file
View file

@ -0,0 +1,25 @@
use serenity::{prelude::GatewayIntents, Client as DiscordClient};
pub struct Client {
discord_client: DiscordClient,
}
pub struct ClientOptions<'a> {
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");
Client { discord_client }
}
pub async fn connect_discord(&mut self) -> () {
if let Err(error) = self.discord_client.start().await {
println!("Could not connect to Discord: {:?}", error);
}
}
}

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod client;

View file

@ -1,3 +1,16 @@
fn main() {
println!("Hello, world!");
use std::env;
use yorokobot::client::{Client, ClientOptions};
#[tokio::main]
async fn main() {
let discord_token = env::var("DISCORD_TOKEN").expect("Cannot fetch Discord token");
let options = ClientOptions {
discord_token: &discord_token,
};
let mut client = Client::new(options).await;
client.connect_discord().await;
}