diff --git a/src/bot.rs b/src/bot.rs index 6a14e02..0f859bb 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use tokio::sync::Mutex; fn dissect<'a>(prefix: &str, str: &'a str) -> Option<(&'a str, Option<&'a str>)> { - let str = str.trim().strip_prefix(prefix)?; + let str = str.strip_prefix(prefix)?; if let Some(o) = str.find(' ') { Some((&str[..o], Some(&str[o + 1..]))) } else { @@ -71,6 +71,7 @@ impl anyhow::Result<()>> Bot { author: &str, content: &str, ) -> anyhow::Result<()> { + let content = content.trim(); if let Some((command, remainder)) = dissect(&self.prefix, content) { if let Some(handler) = self.commands.get(command) { let msg = Context { diff --git a/src/commands/debug.rs b/src/commands/debug.rs index 6525b24..4ac3437 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -7,7 +7,10 @@ pub struct LastMsg; impl Command for LastMsg { async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result { let nick = msg.content.unwrap_or(msg.author); - let lastmsg = msg.history.read().await; - Ok(format!("{}: {:?}", nick, lastmsg.get(nick))) + Ok(format!( + "{}: {:?}", + nick, + msg.history.last_msgs(nick, usize::MAX).await + )) } } diff --git a/src/commands/quotes.rs b/src/commands/quotes.rs index ad637f9..05e36d9 100644 --- a/src/commands/quotes.rs +++ b/src/commands/quotes.rs @@ -26,19 +26,16 @@ impl Command for Grab { if author == msg.author { return Ok("You can't grab yourself.".into()); } - let message = msg - .history - .last_msgs(author, count) - .await - .map(|v| v.join(" | ")); - if let Some(message) = message { + let messages = msg.history.last_msgs(author, count).await; + if let Some(messages) = messages { + let message = messages.join(" | "); msg.db .add_quote(Quote { author: author.into(), quote: message, }) .await?; - Ok("Quote added ({} messages).".into()) + Ok(format!("Quote added ({} messages).", messages.len())) } else { Ok("No previous messages to grab.".into()) }