From 0ece17b6a08f72dd889fe371fdae30dec1dff18a Mon Sep 17 00:00:00 2001 From: Jonathan Bouligny Date: Mon, 8 Jun 2026 14:23:56 -0500 Subject: [PATCH] fix: Trim whitespace in is_admin_command Lets users run commands even with a space before the !admin prefix. --- changelog.d/1804.bugfix | 1 + src/service/admin/mod.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelog.d/1804.bugfix diff --git a/changelog.d/1804.bugfix b/changelog.d/1804.bugfix new file mode 100644 index 000000000..57207e12d --- /dev/null +++ b/changelog.d/1804.bugfix @@ -0,0 +1 @@ +Fixed admin commands being ignored when they had leading whitespace before admin commands. Contributed by @kitvonsnookerz. diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index ae3c14eac..f3711d385 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -549,6 +549,8 @@ pub async fn is_admin_command( 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( // 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( // 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 {