diff options
author | Ashelyn Dawn <git@ashen.earth> | 2024-02-13 01:16:02 -0700 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2024-07-02 22:11:53 -0600 |
commit | 526d3c9eb93611567717df1ffc50fe47ec01ec42 (patch) | |
tree | f6790287137f7cf23f6bf128a3e27a8616b17dfe | |
parent | 0d96660fcbdb6ad7f2cef60f74b09018e0386036 (diff) |
basic serenity client
-rw-r--r-- | Cargo.lock | 5 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 35 |
4 files changed, 39 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock index 82f7a1a..f01745e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1058,6 +1058,7 @@ dependencies = [ "serde", "serde_regex", "serenity", + "tokio", "toml", ] @@ -1369,9 +1370,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 1180df8..6bffe30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,5 @@ regex = "1.10.2" serde = { version = "1.0.196", features = [ "derive" ] } serde_regex = "1.1.0" serenity = "0.12.0" +tokio = "1.36.0" toml = "0.8.8" diff --git a/src/config.rs b/src/config.rs index 998acc0..37a967f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -90,6 +90,6 @@ impl Config { } }); - config + return config } } diff --git a/src/main.rs b/src/main.rs index a9f2686..5e34924 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,42 @@ mod config; use config::Config; +use serenity::{all::{GatewayIntents, Message}, client::{Context, EventHandler}, Client}; -fn main() { +#[tokio::main(flavor = "current_thread")] +async fn main() { println!("Hello, world!"); let config_str = include_str!("../config.toml"); let config = Config::load(config_str.to_string()); + + let token = config.systems.get("ashe-test").unwrap().members + .iter().find(|member| member.name == "test").unwrap() + .discord_token.clone(); + + println!("Token: {}", token); + + let mut client = Client::builder(token, GatewayIntents::all()) + .event_handler(MessageHandler).await.unwrap(); + + client.start().await.unwrap() +} + + +struct MessageHandler; + +#[serenity::async_trait] +impl EventHandler for MessageHandler { + async fn message(&self, context: Context, msg: Message) { + if msg.member.unwrap().user.unwrap().bot { // TODO crashes + return + } + + println!("Got message"); + println!("{}", msg.content); + if let Ok(_test) = msg.channel_id.say(&context, "message acknowledged").await { + println!("Reply sent") + } else { + println!("Error encountered") + } + } } |