diff --git a/src/bot.rs b/src/bot.rs index 0f859bb..cafca46 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -83,30 +83,29 @@ impl anyhow::Result<()>> Bot { return (self.sendmsg)(origin.into(), handler.lock().await.execute(msg).await?); } return (self.sendmsg)(origin.into(), "Unknown command.".into()); - } else { - for trigger in &self.triggers { - let captures = trigger.0.captures(content)?; - if let Some(captures) = captures { - let msg = Context { - author, - content: Some(content), - db: &self.db, - history: &self.history, - }; - return (self.sendmsg)( - origin.into(), - trigger.1.lock().await.execute(msg, captures).await?, - ); - } - } - self.history.add_message(author, content).await; } + for trigger in &self.triggers { + let captures = trigger.0.captures(content)?; + if let Some(captures) = captures { + let msg = Context { + author, + content: Some(content), + db: &self.db, + history: &self.history, + }; + return (self.sendmsg)( + origin.into(), + trigger.1.lock().await.execute(msg, captures).await?, + ); + } + } + self.history.add_message(author, content).await; Ok(()) } pub async fn handle_message(&self, origin: &str, author: &str, content: &str) { if let Err(e) = self.handle_message_inner(origin, author, content).await { - let _ = (self.sendmsg)(origin.into(), format!("Error: {}", e)); + let _err = (self.sendmsg)(origin.into(), format!("Error: {}", e)); } } } diff --git a/src/history.rs b/src/history.rs index beaa562..d520d27 100644 --- a/src/history.rs +++ b/src/history.rs @@ -16,7 +16,7 @@ impl MessageHistory { pub async fn last_msg(&self, user: &str) -> Option { let map = self.map.read().await; - map.get(user).and_then(|d| d.get(0)).map(|s| s.to_string()) + map.get(user).and_then(|d| d.get(0)).map(ToString::to_string) } pub async fn last_msgs(&self, user: &str, count: usize) -> Option> { diff --git a/src/main.rs b/src/main.rs index 8b5b558..1f19995 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::module_name_repetitions)] + use fancy_regex::Regex; use std::env; use std::fs::File; @@ -8,7 +10,7 @@ use std::thread; use crate::bot::Bot; use crate::commands::eval::Eval; use crate::commands::help::Help; -use crate::commands::leek::Owo; +use crate::commands::leek::{Leet, Mock, Owo}; use crate::commands::quotes::{Grab, Quot}; use crate::commands::sed::Sed; use crate::commands::spotify::Spotify; @@ -99,6 +101,8 @@ async fn main() -> anyhow::Result<()> { bot.add_command("help".into(), Help); bot.add_command("waifu".into(), Waifu::default()); bot.add_command("owo".into(), Owo); + bot.add_command("leet".into(), Leet); + bot.add_command("mock".into(), Mock); bot.add_command("ev".into(), Eval::default()); bot.add_command("grab".into(), Grab); bot.add_command("quot".into(), Quot); @@ -109,9 +113,9 @@ async fn main() -> anyhow::Result<()> { if let Some(spotcfg) = cfg.spotify { let creds = Credentials::new(&spotcfg.client_id, &spotcfg.client_secret); let spotify = Spotify::new(creds).await?; - bot.add_trigger(Regex::new(r"(?:https?|spotify):(?://open\.spotify\.com/)?(track|artist|album|playlist)[/:]([a-zA-Z0-9]*)")?, spotify); + bot.add_trigger(Regex::new(r"(?:https?|spotify):(?://open\.spotify\.com/)?(track|artist|album|playlist)[/:]([a-zA-Z\d]*)")?, spotify); } else { - tracing::warn!("Spotify module is disabled, because the config is missing") + tracing::warn!("Spotify module is disabled, because the config is missing"); } bot.add_trigger(Regex::new(r"https?://[^\s/$.?#].\S*")?, Title::new()?); #[cfg(feature = "debug")] @@ -164,9 +168,9 @@ async fn message_loop anyhow::Result<()>>( if origin.is_channel_name() { if let Some(author) = message.prefix.as_ref().and_then(|p| match p { Prefix::Nickname(name, _, _) => Some(&name[..]), - _ => None, + Prefix::ServerName(_) => None, }) { - bot.handle_message(origin, author, &content).await + bot.handle_message(origin, author, &content).await; } else { tracing::warn!("Couldn't get the author for a message"); }