From 677b472d6653c7f225c6b2dcbb30bd827f26cfe4 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 16 Jul 2024 08:18:06 -0400 Subject: [PATCH] Improve is_admin function and the admin docs --- README.md | 2 +- src/bot.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index db84d8e..3f2f71a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Create a "secrets.toml" file: username = "bot_username" password = "bot_password" character = "bot_character" -admins = ["my_username"] +admins = ["my_username"] # You may add usernames or UUIDs to this list. The only advantage of using UUIDs is that it will persist accross changes to your username or player alias. ``` Then create a secret to pass the file securely to the container. diff --git a/src/bot.rs b/src/bot.rs index e739641..1befbdd 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -807,13 +807,18 @@ impl Bot { /// Determines if the Uid belongs to an admin. fn is_user_admin(&self, uid: &Uid) -> Result { - let sender_uuid = self - .find_uuid(uid) - .ok_or("Failed to find uuid")? - .to_string(); let sender_name = self.find_player_alias(uid).ok_or("Failed to find name")?; - Ok(self.admins.contains(sender_name) || self.admins.contains(&sender_uuid)) + if self.admins.contains(sender_name) { + Ok(true) + } else { + let sender_uuid = self + .find_uuid(uid) + .ok_or("Failed to find uuid")? + .to_string(); + + Ok(self.admins.contains(&sender_uuid)) + } } /// Moves the character to the configured position and orientation.