From 526d3c9eb93611567717df1ffc50fe47ec01ec42 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Tue, 13 Feb 2024 01:16:02 -0700 Subject: basic serenity client --- src/config.rs | 2 +- src/main.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src') 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") + } + } } -- cgit 1.4.1