better dm

This commit is contained in:
WanderingPenwing 2024-07-11 22:10:14 +02:00
parent 6f5bfdfd82
commit faf95577da
3 changed files with 18 additions and 2 deletions

View file

@ -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());

View file

@ -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)]

View file

@ -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) => {