AFK: links instead of message text, and a drawn ping reply
A ping's text holds a mention, which breaks Discord's link formatting, so welcome back now uses a fixed Jump to message link. The picture lists who pinged and when, and the reply to a ping is the new away card. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
4115094fd9
commit
568902b3ed
3 changed files with 16 additions and 8 deletions
|
|
@ -226,7 +226,7 @@ mod tests {
|
|||
let art = RgbaImage::from_fn(300, 300, |x, y| Rgba([(x / 2) as u8 + 60, 90, (y / 2) as u8 + 80, 255]));
|
||||
dump("ban.png", &moderation(&Moderation { action: "Member banned", accent: 0xC8324A, name: "spamcat", id: 123456789012345678, avatar: Some(art.clone()), moderator: "Mira", reason: Some("Posting scam links in every channel after a warning."), extra: vec![("Messages deleted".into(), "1 day".into()), ("DM".into(), "Sent".into())] }));
|
||||
dump("away.png", &away("Mira", Some(&art), "Gone to get food, back in twenty minutes", "In this server", "Send any message to come back"));
|
||||
dump("back.png", &welcome_back("Mira", Some(&art), "2 hours", &["Rowan: did you see this".into(), "spamcat: hey".into(), "nightowl: are you coming tonight".into()]));
|
||||
dump("back.png", &welcome_back("Mira", Some(&art), "2 hours", &["Rowan, 2 hours ago".into(), "spamcat, 40 minutes ago".into()]));
|
||||
dump("deleted.png", &deleted("Rowan", Some(&art), "I definitely did not say that, and you can't prove it", "5 minutes ago"));
|
||||
dump("edited.png", &edited("Rowan", Some(&art), "see you at 8", "see you at 9, sorry", "2 minutes ago"));
|
||||
dump("reaction.png", &reaction("Rowan", Some(&art), "😂", None, "just now"));
|
||||
|
|
|
|||
|
|
@ -168,9 +168,16 @@ pub async fn on_message(state: Arc<State>, m: Message) {
|
|||
}
|
||||
let name = state.cache.user(member.id).map(|u| u.global_name.clone().unwrap_or_else(|| u.name.clone())).unwrap_or_else(|| member.name.clone());
|
||||
let name = guild.and_then(|g| state.cache.member(g, member.id).and_then(|x| x.nick().map(str::to_string))).unwrap_or(name);
|
||||
let text = format!("💤 **{}** is AFK {}: {} (<t:{}:R>)", escape(&name), if k.starts_with("global:") { "everywhere" } else { "here" },
|
||||
escape(entry["reason"].as_str().unwrap_or("AFK")), entry["since"].as_i64().unwrap_or(0));
|
||||
if let Ok(sent) = state.http.create_message(m.channel_id).content(&text).reply(m.id).allowed_mentions(Some(&no_pings)).await {
|
||||
let since = entry["since"].as_i64().unwrap_or(0);
|
||||
let place = if k.starts_with("global:") { "Away everywhere" } else { "Away in this server" };
|
||||
let reason = entry["reason"].as_str().unwrap_or("AFK");
|
||||
let avatar_url = crate::commands::media::avatar(&state, member.id, 128).await;
|
||||
let avatar = crate::commands::media::fetch_picture(&state, &avatar_url).await;
|
||||
let picture = art::away(&name, avatar.as_ref(), reason, place, &format!("Away for {}", fmt_duration(((unix() - since).max(1)) as u64)));
|
||||
let card = Card::new(Some(0x4A4AB8)).gallery(&[&format!("attachment://{}", art::FILE)]).build();
|
||||
let files = [twilight_model::http::attachment::Attachment::from_bytes(art::FILE.to_string(), picture, 1)];
|
||||
let sent = state.http.create_message(m.channel_id).flags(MessageFlags::IS_COMPONENTS_V2).components(&[card]).attachments(&files).reply(m.id).allowed_mentions(Some(&no_pings)).await;
|
||||
if let Ok(sent) = sent {
|
||||
if let Ok(sent) = sent.model().await {
|
||||
delete_later(&state, sent.channel_id, sent.id, 20);
|
||||
}
|
||||
|
|
@ -190,10 +197,11 @@ async fn welcome_back(state: &Arc<State>, m: &Message, guild: Option<Id<GuildMar
|
|||
let mut lines = vec![format!("-# <@{}>", m.author.id)];
|
||||
let mut chips = vec![];
|
||||
for p in pings.iter().rev().take(8).rev() {
|
||||
let text = p["text"].as_str().filter(|t| !t.is_empty()).unwrap_or("message");
|
||||
lines.push(format!("-# <@{}> <t:{}:R> — [{}]({})", p["by"].as_u64().unwrap_or(0), p["at"].as_i64().unwrap_or(0), escape(text), p["url"].as_str().unwrap_or("")));
|
||||
// a fixed label: the ping's own text holds a mention, and Discord can't render one inside a link
|
||||
lines.push(format!("<@{}> <t:{}:R> · [Jump to message](<{}>)", p["by"].as_u64().unwrap_or(0), p["at"].as_i64().unwrap_or(0), p["url"].as_str().unwrap_or("")));
|
||||
let by = p["by"].as_u64().and_then(Id::new_checked).and_then(|u: Id<twilight_model::id::marker::UserMarker>| state.cache.user(u).map(|x| x.global_name.clone().unwrap_or_else(|| x.name.clone()))).unwrap_or_else(|| "Someone".to_string());
|
||||
chips.push(format!("{by}: {}", crate::cardart::plain_in(state, text)));
|
||||
let ago = (unix() - p["at"].as_i64().unwrap_or(0)).max(0) as u64;
|
||||
chips.push(format!("{by}, {} ago", fmt_duration(ago.max(1))));
|
||||
}
|
||||
let avatar_url = crate::commands::media::avatar(state, m.author.id, 128).await;
|
||||
let avatar = crate::commands::media::fetch_picture(state, &avatar_url).await;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ fn render(kind: &str, e: &Value, index: usize, total: usize, guild: Option<Id<Gu
|
|||
card = card.text(&format!("📎 {}", others.iter().enumerate().map(|(i, u)| format!("[file {}](<{u}>)", i + 1)).collect::<Vec<_>>().join(" · ")));
|
||||
}
|
||||
} else {
|
||||
details.push(format!("[jump]({jump})"));
|
||||
details.push(format!("[Jump to message](<{jump}>)"));
|
||||
}
|
||||
details.push(format!("{} of {total}, newest first", index + 1));
|
||||
card.footer(&details.join(" · "))
|
||||
|
|
|
|||
Loading…
Reference in a new issue