Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 70 additions & 16 deletions src/tasks/status_update_mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use super::Task;
use crate::graphql::GraphQLClient;
use anyhow::Context;
use async_trait::async_trait;
use serenity::builder::CreateWebhook;
use serenity::builder::ExecuteWebhook;
use serenity::client::Context as ClientContext;
use serenity::model::id::UserId;
use serenity::model::webhook::Webhook;
use serenity::prelude::CacheHttp;
use std::collections::HashMap;

Expand All @@ -30,8 +34,6 @@ use chrono::{Datelike, Duration, Local, Timelike};
use chrono_tz::Asia::Kolkata;
use mailparse::{MailHeaderMap, ParsedMail};
use poise::serenity_prelude::ChannelId;
use poise::serenity_prelude::CreateEmbed;
use poise::serenity_prelude::CreateMessage;

pub struct EmailDetails {
pub from: String,
Expand Down Expand Up @@ -79,22 +81,77 @@ pub async fn mirror_new_updates(ctx: ClientContext, client: GraphQLClient) -> an
if member.track.is_none() || member.group_id.is_none() {
continue;
}
send_update(
&ctx,
member.name.clone(),
member.track.clone().unwrap(),
member.group_id.unwrap(),
email.body.clone(),
)
.await?;
if let Some(discord_id) = &member.discord_id {
let discord_id: u64 = discord_id.parse()?;

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now silently skips mirroring when member.discord_id is None, which is a behavior change from the previous implementation (updates were still mirrored). Consider adding an else fallback (e.g., send via webhook with a default avatar / bot identity) and/or logging so missing IDs don’t cause updates to disappear.

Copilot uses AI. Check for mistakes.

@hrideshmg hrideshmg Mar 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AadarshM07 this needs to be addressed. The discord IDs are only populated when the member signs into home and fills them in manually, they might forget and its not obvious if they do.

@AadarshM07 AadarshM07 Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hrideshmg Added the fallback , it will use the bot pfp if no discord id is found.

send_update(
&ctx,
member.name.clone(),
discord_id,
member.track.clone().unwrap(),
member.group_id.unwrap(),
email.body.clone(),
)
.await?;
Comment thread
hrideshmg marked this conversation as resolved.
Outdated
}
}
}
Ok(())
}

async fn get_or_create_webhook(
ctx: &ClientContext,
channel_id: ChannelId,
) -> anyhow::Result<Webhook> {
let hooks = channel_id.webhooks(ctx.http()).await?;

Comment thread
hrideshmg marked this conversation as resolved.
if let Some(hook) = hooks
.into_iter()
.find(|h| h.name == Some("amD Updates".to_string()))
{
return Ok(hook);
}

let webhook = channel_id
.create_webhook(ctx.http(), CreateWebhook::new("amD Updates"))
.await?;

Ok(webhook)
}

async fn send_webhook_message(
ctx: &ClientContext,
channel_id: ChannelId,
username: String,
avatar_url: String,
content: String,
) -> anyhow::Result<()> {
let webhook = get_or_create_webhook(ctx, channel_id).await?;

let builder = ExecuteWebhook::new()
.username(username)
.avatar_url(avatar_url)
Comment thread
AadarshM07 marked this conversation as resolved.
.content(content);

webhook.execute(ctx.http(), false, builder).await?;

Comment thread
AadarshM07 marked this conversation as resolved.
Ok(())
}

async fn get_avatar_url(ctx: &ClientContext, discord_id: u64) -> anyhow::Result<String> {
let user = ctx.http.get_user(UserId::new(discord_id)).await?;
Comment thread
hrideshmg marked this conversation as resolved.

let avatar = user
.avatar_url()
.unwrap_or_else(|| user.default_avatar_url());

Ok(avatar)
}

async fn send_update(
ctx: &ClientContext,
name: String,
discord_id: u64,
track: String,
group: i32,
content: String,
Expand All @@ -111,14 +168,11 @@ async fn send_update(
_ => STATUS_UPDATE_CHANNEL_ID,
};

let embed = CreateEmbed::new()
.title(format!("Status Update: {}", name))
.description(content);
let channel = ChannelId::new(channel_id);

let msg = CreateMessage::new().embed(embed);
let avatar_url = get_avatar_url(ctx, discord_id).await?;

let channel = ChannelId::new(channel_id);
channel.send_message(ctx.http(), msg).await?;
send_webhook_message(ctx, channel, name, avatar_url, content).await?;

Ok(())
}
Expand Down
Loading