From 7e0b2cd3f36fd1bd0ef8fc0191f5887792c6d3a6 Mon Sep 17 00:00:00 2001 From: eta Date: Mon, 13 Jul 2020 13:20:15 +0100 Subject: feat(tvldb): parse CTCP ACTIONs properly, allow use of aliases in ??! syntax Change-Id: I3cc0e88a94ea0edc470ff9e0da203f1193d40f9f Reviewed-on: https://cl.tvl.fyi/c/depot/+/1128 Tested-by: BuildkiteCI Reviewed-by: lukegb Reviewed-by: glittershark --- fun/tvldb/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'fun') diff --git a/fun/tvldb/src/main.rs b/fun/tvldb/src/main.rs index 5d2e670337f6..f95b27656d1a 100644 --- a/fun/tvldb/src/main.rs +++ b/fun/tvldb/src/main.rs @@ -146,8 +146,16 @@ impl App { .last_msgs .entry(chan.to_string()) .or_insert(HashMap::new()); - let val = if let Some(last) = chan_lastmsgs.get(&kwd.keyword.name.to_ascii_lowercase()) { - format!("<{}> {}", &kwd.keyword.name, last) + // Use `nick` here, so things like "grfn: see glittershark" work. + let val = if let Some(last) = chan_lastmsgs.get(&nick.to_ascii_lowercase()) { + if last.starts_with("\x01ACTION ") { + // Yes, this is inefficient, but it's better than writing some hacky CTCP parsing code + // I guess (also, characters are hard, so just blindly slicing seems like a bad idea) + format!("* {} {}", nick, last.replace("\x01ACTION ", "").replace("\x01", "")) + } + else { + format!("<{}> {}", nick, last) + } } else { Err(format_err!("I dunno what {} said...", kwd.keyword.name))? }; -- cgit 1.4.1