From 19fc2626f72609397c326a6c1c1cda88d2efdc31 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Thu, 11 Jul 2024 18:03:47 +0200 Subject: [PATCH] fetch working, update not working --- src/bot.rs | 19 +++++++++++++++++++ src/main.rs | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bot.rs b/src/bot.rs index 7d81a57..10b12c3 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -39,6 +39,21 @@ impl EventHandler for Handler { println!("bot : successfuly sent reply"); } + if let Some(sender) = context.data.read().await.get::() { + let author_name = msg.author.name.clone(); + let mut guild_id = "dm".to_string(); + + if let Some(channel) = msg.channel(&context.cache).await { + if let Some(guild) = channel.guild() { + guild_id = guild.id.to_string(); + } + } + + let discord_message = discord_structure::Message::new(msg.id.to_string(), msg.channel_id.to_string(), guild_id, author_name, msg.content.clone(), msg.timestamp.to_rfc2822()); + sender.send(postman::Packet::Message(discord_message)).expect("failed to send packet"); + } else { + println!("bot : failed to retrieve sender"); + } } async fn ready(&self, _context: Context, ready: Ready) { @@ -59,6 +74,7 @@ impl EventHandler for Handler { get_guilds(&context1).await; }); + //comment this to get the listening to messages working let context2 = Arc::clone(&context); tokio::spawn(async move { loop { @@ -184,6 +200,9 @@ async fn get_guilds(context: &Context) { let guilds = context.cache.guilds().await; if let Some(sender) = context.data.read().await.get::() { + let personal_messages = discord_structure::Guild::new("dm".to_string(), "dm".to_string()); + sender.send(postman::Packet::Guild(personal_messages)).expect("Failed to send packet"); + for guild_id in guilds { if let Some(guild) = context.cache.guild(guild_id).await { println!("bot : found guild '{}'", guild.name.clone()); diff --git a/src/main.rs b/src/main.rs index c415c90..3312062 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,6 +114,7 @@ impl eframe::App for Jiji { if unkown_channel { println!("gui : unkown channel"); + self.guilds[guild_index].channels.push(discord_structure::Channel::new(message.channel_id.clone(), message.channel_id, message.guild_id)); } } } @@ -192,7 +193,7 @@ impl Jiji { for i in 0..self.guilds.len() { if ui.add(egui::SelectableLabel::new(self.selected_guild == Some(i), self.guilds[i].name.clone())).clicked() { self.selected_guild = Some(i); - if self.guilds[i].channels.len() == 0 { + if self.guilds[i].channels.len() == 0 && self.guilds[i].id != "dm" { let _ = self.sender.send(postman::Packet::FetchChannels(self.guilds[i].id.clone())); self.selected_channel = None;