Do not respond to or log ignored commands.
This commit is contained in:
parent
29ef21087f
commit
3ccd60c173
49
src/bot.rs
49
src/bot.rs
|
@ -143,31 +143,36 @@ impl DiceBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if results.len() == 1 {
|
if results.len() >= 1 {
|
||||||
let cmd_result = &results[0];
|
if results.len() == 1 {
|
||||||
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
|
let cmd_result = &results[0];
|
||||||
NoticeMessageEventContent::html(cmd_result.plain.clone(), cmd_result.html.clone()),
|
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
|
||||||
));
|
NoticeMessageEventContent::html(
|
||||||
|
cmd_result.plain.clone(),
|
||||||
|
cmd_result.html.clone(),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
let result = self.client.room_send(&room_id, response, None).await;
|
let result = self.client.room_send(&room_id, response, None).await;
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
let message = extract_error_message(e);
|
let message = extract_error_message(e);
|
||||||
error!("Error sending message: {}", message);
|
error!("Error sending message: {}", message);
|
||||||
};
|
};
|
||||||
} else {
|
} else if results.len() > 1 {
|
||||||
let message = format!("{}: Executed {} commands", sender_username, results.len());
|
let message = format!("{}: Executed {} commands", sender_username, results.len());
|
||||||
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
|
let response = AnyMessageEventContent::RoomMessage(MessageEventContent::Notice(
|
||||||
NoticeMessageEventContent::html(&message, &message),
|
NoticeMessageEventContent::html(&message, &message),
|
||||||
));
|
));
|
||||||
|
|
||||||
let result = self.client.room_send(&room_id, response, None).await;
|
let result = self.client.room_send(&room_id, response, None).await;
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
let message = extract_error_message(e);
|
let message = extract_error_message(e);
|
||||||
error!("Error sending message: {}", message);
|
error!("Error sending message: {}", message);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("[{}] {} executed: {}", room_name, sender_username, msg_body);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("[{}] {} executed: {}", room_name, sender_username, msg_body);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,8 @@ pub trait Command: Send + Sync {
|
||||||
|
|
||||||
/// Parse a command string into a dynamic command execution trait
|
/// Parse a command string into a dynamic command execution trait
|
||||||
/// object. Returns an error if a command was recognized but not
|
/// 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> {
|
pub fn parse(s: &str) -> Result<Box<dyn Command>, BotError> {
|
||||||
match parser::parse_command(s) {
|
match parser::parse_command(s) {
|
||||||
Ok(command) => Ok(command),
|
Ok(command) => Ok(command),
|
||||||
|
|
Loading…
Reference in New Issue