fetch working, update not working

This commit is contained in:
WanderingPenwing 2024-07-11 18:03:47 +02:00
parent da571b4259
commit 19fc2626f7
2 changed files with 21 additions and 1 deletions

View file

@ -39,6 +39,21 @@ impl EventHandler for Handler {
println!("bot : successfuly sent reply"); println!("bot : successfuly sent reply");
} }
if let Some(sender) = context.data.read().await.get::<postman::Sender>() {
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) { async fn ready(&self, _context: Context, ready: Ready) {
@ -59,6 +74,7 @@ impl EventHandler for Handler {
get_guilds(&context1).await; get_guilds(&context1).await;
}); });
//comment this to get the listening to messages working
let context2 = Arc::clone(&context); let context2 = Arc::clone(&context);
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
@ -184,6 +200,9 @@ async fn get_guilds(context: &Context) {
let guilds = context.cache.guilds().await; let guilds = context.cache.guilds().await;
if let Some(sender) = context.data.read().await.get::<postman::Sender>() { if let Some(sender) = context.data.read().await.get::<postman::Sender>() {
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 { for guild_id in guilds {
if let Some(guild) = context.cache.guild(guild_id).await { if let Some(guild) = context.cache.guild(guild_id).await {
println!("bot : found guild '{}'", guild.name.clone()); println!("bot : found guild '{}'", guild.name.clone());

View file

@ -114,6 +114,7 @@ impl eframe::App for Jiji {
if unkown_channel { if unkown_channel {
println!("gui : 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() { for i in 0..self.guilds.len() {
if ui.add(egui::SelectableLabel::new(self.selected_guild == Some(i), self.guilds[i].name.clone())).clicked() { if ui.add(egui::SelectableLabel::new(self.selected_guild == Some(i), self.guilds[i].name.clone())).clicked() {
self.selected_guild = Some(i); 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())); let _ = self.sender.send(postman::Packet::FetchChannels(self.guilds[i].id.clone()));
self.selected_channel = None; self.selected_channel = None;