Add Discord connection
This commit is contained in:
parent
8b873e1fef
commit
42b7d04e32
25
src/client.rs
Normal file
25
src/client.rs
Normal 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
1
src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod client;
|
17
src/main.rs
17
src/main.rs
|
@ -1,3 +1,16 @@
|
||||||
fn main() {
|
use std::env;
|
||||||
println!("Hello, world!");
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue