Do not respond to or log ignored commands.

This commit is contained in:
projectmoon 2020-11-01 12:20:45 +00:00
parent 29ef21087f
commit 3ccd60c173
2 changed files with 29 additions and 23 deletions

View File

@ -143,10 +143,14 @@ impl DiceBot {
}
}
if results.len() >= 1 {
if results.len() == 1 {
let cmd_result = &results[0];
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
NoticeMessageEventContent::html(cmd_result.plain.clone(), cmd_result.html.clone()),
NoticeMessageEventContent::html(
cmd_result.plain.clone(),
cmd_result.html.clone(),
),
));
let result = self.client.room_send(&room_id, response, None).await;
@ -154,7 +158,7 @@ impl DiceBot {
let message = extract_error_message(e);
error!("Error sending message: {}", message);
};
} else {
} else if results.len() > 1 {
let message = format!("{}: Executed {} commands", sender_username, results.len());
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
NoticeMessageEventContent::html(&message, &message),
@ -169,6 +173,7 @@ impl DiceBot {
info!("[{}] {} executed: {}", room_name, sender_username, msg_body);
}
}
}
/// Check if a message is recent enough to actually process. If the

View File

@ -43,7 +43,8 @@ pub trait Command: Send + Sync {
/// Parse a command string into a dynamic command execution trait
/// object. Returns an error if a command was recognized but not
/// parsed correctly. Returns Ok(None) if no command was recognized.
/// parsed correctly. Returns IgnoredCommand error if no command was
/// recognized.
pub fn parse(s: &str) -> Result<Box<dyn Command>, BotError> {
match parser::parse_command(s) {
Ok(command) => Ok(command),