diff --git a/src/bot.rs b/src/bot.rs index 76a027e..88bc957 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -44,7 +44,7 @@ impl EventHandler for Handler { } if let Some(sender) = context.data.read().await.get::() { - let message = postman::Message::new(postman::MessageType::GuildName, guild_names[0].clone()); + let message = postman::Packet::new(postman::PacketKind::GuildName, guild_names[0].clone()); sender.send(message).unwrap(); println!("Message from bot to gui, sent"); } else { @@ -53,7 +53,7 @@ impl EventHandler for Handler { } } -pub async fn start_discord_bot(sender: mpsc::Sender) { +pub async fn start_discord_bot(sender: mpsc::Sender) { println!("Bot connection process started..."); let maybe_client = Client::builder(token::TOKEN) .event_handler(Handler) diff --git a/src/main.rs b/src/main.rs index a5d938f..af5734c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ mod postman; const MAX_FPS: f32 = 30.0; fn main() { - let (tx, rx) = mpsc::channel::(); //tx transmiter + let (tx, rx) = mpsc::channel::(); //tx transmiter let _handle = thread::spawn(move || { println!("Bot thread spawned"); @@ -21,7 +21,7 @@ fn main() { gui(rx); } -fn gui(receiver: mpsc::Receiver) { +fn gui(receiver: mpsc::Receiver) { let icon_data = load_icon().unwrap_or_default(); let options = eframe::NativeOptions { @@ -36,11 +36,11 @@ fn gui(receiver: mpsc::Receiver) { struct Jiji { next_frame: time::Instant, - receiver: mpsc::Receiver, + receiver: mpsc::Receiver, } impl Jiji { - fn new(receiver: mpsc::Receiver) -> Self { + fn new(receiver: mpsc::Receiver) -> Self { Self { next_frame: time::Instant::now(), receiver, @@ -54,6 +54,10 @@ impl eframe::App for Jiji { ((1.0 / MAX_FPS) - self.next_frame.elapsed().as_secs_f32()).max(0.0), )); self.next_frame = time::Instant::now(); + + while let Ok(packet) = self.receiver.try_recv() { + println!("Message from bot to gui received : {}", packet.content); + } self.draw_feed(ctx); } diff --git a/src/postman.rs b/src/postman.rs index d4bcc2e..bffcb14 100644 --- a/src/postman.rs +++ b/src/postman.rs @@ -1,13 +1,13 @@ use std::sync::mpsc; use serenity::prelude::TypeMapKey; -pub struct Message { - kind: MessageType, - content: String, +pub struct Packet { + pub kind: PacketKind, + pub content: String, } -impl Message { - pub fn new(kind : MessageType, content: String) -> Self { +impl Packet { + pub fn new(kind : PacketKind, content: String) -> Self { Self { kind, content, @@ -16,12 +16,12 @@ impl Message { } -pub enum MessageType { +pub enum PacketKind { GuildName, } pub struct Sender; impl TypeMapKey for Sender { - type Value = mpsc::Sender; + type Value = mpsc::Sender; } \ No newline at end of file diff --git a/src/tree.rs b/src/tree.rs new file mode 100644 index 0000000..ead6c31 --- /dev/null +++ b/src/tree.rs @@ -0,0 +1,18 @@ + +struct Guild { + name: String, + id: String, + channels: Vec, +} + +struct Channel { + name: String, + id: String, + messages: Vec, +} + +struct Message { + author: String, + id: String, + content: String, +} \ No newline at end of file