fix(prefix): prevent multiple prefix usage like ++++ping (#1)

This commit is contained in:
Arthur
2026-04-11 15:01:47 +02:00
committed by GitHub
parent 1f774628c2
commit 0fb91e0172
3 changed files with 7 additions and 9 deletions
+3 -4
View File
@@ -28,11 +28,10 @@ fn has_only_photo_attachments(msg: &Message) -> bool {
} }
fn is_piconly_command_message(content: &str, prefix: &str) -> bool { fn is_piconly_command_message(content: &str, prefix: &str) -> bool {
if !content.starts_with(prefix) { let Some(without_prefix) = content.strip_prefix(prefix) else {
return false; return false;
} };
let without_prefix = without_prefix.trim();
let without_prefix = content.trim_start_matches(prefix).trim();
without_prefix without_prefix
.split_whitespace() .split_whitespace()
.next() .next()
+1 -1
View File
@@ -662,7 +662,7 @@ pub fn command_metadata_by_key(key: &str) -> Option<CommandMetadata> {
} }
pub fn resolve_default_alias(alias: &str) -> Option<&'static str> { pub fn resolve_default_alias(alias: &str) -> Option<&'static str> {
let normalized = alias.trim().trim_start_matches('+').to_lowercase(); let normalized = alias.trim().to_lowercase();
all_command_metadata().into_iter().find_map(|meta| { all_command_metadata().into_iter().find_map(|meta| {
if meta if meta
.default_aliases .default_aliases
+3 -4
View File
@@ -110,11 +110,10 @@ pub async fn handle_message(ctx: &Context, msg: &Message) {
return; return;
} }
if !content.starts_with(&prefix_value) { let Some(without_prefix) = content.strip_prefix(&prefix_value) else {
return; return;
} };
let without_prefix = without_prefix.trim();
let without_prefix = content.trim_start_matches(&prefix_value).trim();
if without_prefix.is_empty() { if without_prefix.is_empty() {
return; return;
} }