Fix command parser

This commit is contained in:
c0re100 2025-09-02 18:58:30 +08:00
parent 51f3ce0659
commit 5c5078ec42
No known key found for this signature in database
GPG key ID: 7C3B3004FE745AAF

View file

@ -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