From e251294b5f8c837d013f7c0f1dae51a5160a943e Mon Sep 17 00:00:00 2001 From: projectmoon Date: Thu, 12 Nov 2020 20:22:08 +0000 Subject: [PATCH] Only execute lines with commands. Fixes #45 and #46. --- src/bot.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 8928b2a..3e29162 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -124,12 +124,12 @@ impl DiceBot { let mut results = Vec::with_capacity(msg_body.lines().count()); - for command in msg_body.lines() { - if !command.is_empty() { - let ctx = Context::new(&self.db, &room_id.as_str(), &sender_username, &command); - if let Some(cmd_result) = execute_command(&ctx).await { - results.push(cmd_result); - } + let commands = msg_body.trim().lines().filter(|line| line.starts_with("!")); + + for command in commands { + let ctx = Context::new(&self.db, &room_id.as_str(), &sender_username, &command); + if let Some(cmd_result) = execute_command(&ctx).await { + results.push(cmd_result); } }