From c9e6b2e681088687f5a714c3324d4d0731b8393e Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 02:53:45 -0400 Subject: better unrecognized handling, more expressive react/unreact indicators --- src/bot.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 14 deletions(-) (limited to 'src/bot.rs') diff --git a/src/bot.rs b/src/bot.rs index dabb64c..836fb82 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -230,22 +230,53 @@ fn on_err(err: FrameworkError) -> BoxFuture<()> { __non_exhaustive: (), }; - match util::pop_string(msg_content) - .map_err(anyhow::Error::from) - .and_then(|(_rest, s)| s.parse().map_err(anyhow::Error::from)) - { - Ok(u) => { - if let Err(e) = commands::unrecognized(PoiseContext::Prefix(ctx), u).await { - error!("processing audio: {e}"); + let content = msg_content.trim(); + + if content.is_empty() { + if let Err(e) = util::reply(PoiseContext::Prefix(ctx), "what?").await { + error!("responding to empty message: {e}"); + }; + + return; + } + + lazy_static::lazy_static! { + static ref HTTP_REGEX: regex::Regex = regex::Regex::new(r#"^https?://"#).unwrap(); + } + + if HTTP_REGEX.is_match(content) { + match util::pop_string(msg_content) + .map_err(anyhow::Error::from) + .and_then(|(_rest, s)| s.parse().map_err(anyhow::Error::from)) + { + Ok(u) => { + if let Err(e) = + commands::link_unrecognized(PoiseContext::Prefix(ctx), u).await + { + error!("processing audio: {e}"); + "BANIC".to_string() + } else { + return; + } + }, + Err(e) => { + error!("processing unrecognized message: {e}"); "BANIC".to_string() - } else { - return; - } - }, - Err(e) => { - error!("processing unrecognized message: {e}"); + }, + } + } else { + if let Err(e) = commands::meme::invoke::_meme( + PoiseContext::Prefix(ctx), + msg_content, + Default::default(), + ) + .await + { + error!("producing meme for unrecognized: {e}"); "BANIC".to_string() - }, + } else { + return; + } } }, _ => "BANIC".to_string(), -- cgit v1.3.1