diff --git a/src/bot.rs b/src/bot.rs index b83f821..a80dc85 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -45,6 +45,8 @@ impl EventHandler for Handler { let guild_id = if let Some(id) = msg.guild_id { id.to_string() } else { + let private_channel = discord_structure::Channel::new(author_name.clone(), msg.channel_id.to_string(), "dm".to_string()); + sender.send(postman::Packet::Channel(private_channel)).expect("failed to send packet"); "dm".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()); diff --git a/src/discord_structure.rs b/src/discord_structure.rs index b161961..6224222 100644 --- a/src/discord_structure.rs +++ b/src/discord_structure.rs @@ -15,6 +15,21 @@ impl Guild { channels: vec![], } } + + pub fn add_channel(&mut self, channel: Channel) { + let mut already_exist = false; + + for existing_channel in self.channels.clone() { + if existing_channel.id != channel.id { + continue + } + already_exist = true; + } + + if !already_exist { + self.channels.insert(0, channel.clone()) + } + } } #[derive(PartialEq, Clone)] diff --git a/src/main.rs b/src/main.rs index bc8f3c6..a4fa8ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,8 +86,7 @@ impl eframe::App for Jiji { if self.guilds[i].id != channel.guild_id { continue } - self.guilds[i].channels.push(channel.clone()); - println!("gui : channel added to '{}'", self.guilds[i].name); + self.guilds[i].add_channel(channel.clone()); } } postman::Packet::Message(message) => {