Fix minor parsing issues
This commit is contained in:
parent
329f6d6dae
commit
2a0e805719
|
@ -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<SF: Fn(String, String) -> anyhow::Result<()>> Bot<SF> {
|
|||
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 {
|
||||
|
|
|
@ -7,7 +7,10 @@ pub struct LastMsg;
|
|||
impl Command for LastMsg {
|
||||
async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result<String> {
|
||||
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
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue