Merge pull request #3 from victormignot/discord-connection
Init basic connection to Discord
This commit is contained in:
commit
3b49b951d6
2
.env.example
Normal file
2
.env.example
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Discord Token
|
||||||
|
DISCORD_TOKEN="Enter your Discord secret token"
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
1855
Cargo.lock
generated
1855
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,3 +6,6 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serenity = { version="0.11", default-features = false, features = ["client", "gateway", "rustls_backend", "model" ] }
|
||||||
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
mongodb = "2.3.0"
|
||||||
|
|
|
@ -30,6 +30,12 @@
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
rustfmt
|
rustfmt
|
||||||
];
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
set -a
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
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