From 5c5078ec427b2444302480aa3526ea4c30332970 Mon Sep 17 00:00:00 2001 From: c0re100 Date: Tue, 2 Sep 2025 18:58:30 +0800 Subject: [PATCH] Fix command parser --- client/extra.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/client/extra.go b/client/extra.go index c786893..9b32fc9 100644 --- a/client/extra.go +++ b/client/extra.go @@ -23,22 +23,18 @@ func IsCommand(text string) bool { func CheckCommand(text string, entities []*TextEntity) string { if IsCommand(text) { - var cmd string + cmd := text // e.g. ["/hello 123", "/hell o 123"] // Result: "/hello", "/hell" - if i := strings.Index(text, " "); i != -1 { - cmd = text[:i] + if i := strings.Index(cmd, " "); i != -1 { + cmd = cmd[:i] } // e.g.: ["/hello@world_bot", "/hello@", "/hello@123"] // Result: "/hello" - if i := strings.Index(text, "@"); i != -1 { - cmd = text[:i] - } - - if cmd == "" { - return text + if i := strings.Index(cmd, "@"); i != -1 { + cmd = cmd[:i] } return cmd