From 81ed707dc18aae3e9fc2388181b1b348d5600054 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 17 Jun 2024 08:41:02 -0400 Subject: [PATCH] Add early returns for performance --- src/bot.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index a05b235..59274bb 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -99,11 +99,11 @@ impl Bot { } fn handle_message(&mut self, message: GenericChatMsg) -> Result<(), String> { - let content = message.content().as_plain().unwrap_or(""); let sender_uid = match &message.chat_type { ChatType::Tell(from, _) | ChatType::Group(from, _) | ChatType::Say(from) => from, _ => return Ok(()), }; + let content = message.content().as_plain().unwrap_or(""); let sender_info = self .client .player_list() @@ -117,12 +117,14 @@ impl Bot { }) .ok_or_else(|| format!("Failed to find info for uid {sender_uid}"))?; - // First, process commands with no arguments + // Process commands with no arguments if content == "inv" { info!("Inviting {}", sender_info.player_alias); self.client.send_invite(*sender_uid, InviteKind::Group); + + return Ok(()); } if content == "kick_all" && self.admin_list.contains(&sender_info.uuid) { @@ -133,6 +135,8 @@ impl Bot { for (uid, _) in group_members { self.client.kick_from_group(uid); } + + return Ok(()); } if content == "cheese" { @@ -150,6 +154,8 @@ impl Bot { _ => self.client.send_command("group".to_string(), vec![content]), } } + + return Ok(()); } if content == "info" { @@ -195,6 +201,7 @@ impl Bot { } } } + match &message.chat_type { ChatType::Tell(_, _) => { self.client.send_command(