fix: Trim whitespace in is_admin_command

Lets users run commands even with a space before the !admin prefix.
This commit is contained in:
Jonathan Bouligny
2026-06-11 15:20:34 +00:00
committed by Ellis Git
parent 7d945bbd5d
commit 0ece17b6a0
2 changed files with 8 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
Fixed admin commands being ignored when they had leading whitespace before admin commands. Contributed by @kitvonsnookerz.
+7 -3
View File
@@ -549,6 +549,8 @@ pub async fn is_admin_command<E>(
return None;
}
// Trim leading spaces from commands
let trimmed_body: &str = body.trim_start();
if let Some(room_id) = event.room_id()
&& self.is_admin_room(room_id).await
{
@@ -556,7 +558,9 @@ pub async fn is_admin_command<E>(
// Ignore messages which aren't admin commands
let server_user = &self.services.globals.server_user;
if !(body.starts_with("!admin") || body.starts_with(server_user.as_str())) {
if !(trimmed_body.starts_with("!admin")
|| trimmed_body.starts_with(server_user.as_str()))
{
return None;
}
@@ -572,8 +576,8 @@ pub async fn is_admin_command<E>(
// This is a message outside the admin room
// Is it an escaped admin command? i.e. `\!admin --help`
let is_public_escape =
body.starts_with('\\') && body.trim_start_matches('\\').starts_with("!admin");
let is_public_escape = trimmed_body.starts_with('\\')
&& trimmed_body.trim_start_matches('\\').starts_with("!admin");
// Ignore the message if it's not
if !is_public_escape {