Improve is_admin function and the admin docs

This commit is contained in:
Jeff 2024-07-16 08:18:06 -04:00
parent 5f03f6bac3
commit 677b472d66
2 changed files with 11 additions and 6 deletions

View File

@ -24,7 +24,7 @@ Create a "secrets.toml" file:
username = "bot_username" username = "bot_username"
password = "bot_password" password = "bot_password"
character = "bot_character" 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. Then create a secret to pass the file securely to the container.

View File

@ -807,13 +807,18 @@ impl Bot {
/// Determines if the Uid belongs to an admin. /// Determines if the Uid belongs to an admin.
fn is_user_admin(&self, uid: &Uid) -> Result<bool, String> { fn is_user_admin(&self, uid: &Uid) -> Result<bool, String> {
let sender_name = self.find_player_alias(uid).ok_or("Failed to find name")?;
if self.admins.contains(sender_name) {
Ok(true)
} else {
let sender_uuid = self let sender_uuid = self
.find_uuid(uid) .find_uuid(uid)
.ok_or("Failed to find uuid")? .ok_or("Failed to find uuid")?
.to_string(); .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)) Ok(self.admins.contains(&sender_uuid))
}
} }
/// Moves the character to the configured position and orientation. /// Moves the character to the configured position and orientation.