Check space before @

This commit is contained in:
c0re100 2025-03-12 00:35:34 +08:00
parent 8de0893227
commit 05b67218a9
No known key found for this signature in database
GPG key ID: 7C3B3004FE745AAF

View file

@ -25,18 +25,18 @@ func IsCommand(text string) bool {
func CheckCommand(text string, entities []*TextEntity) string {
if IsCommand(text) {
// e.g.: ["/hello@world_bot", "/hello@", "/hello@123"]
// Result: "/hello"
if i := strings.Index(text, "@"); i != -1 {
return text[:i]
}
// e.g. ["/hello 123", "/hell o 123"]
// Result: "/hello", "/hell"
if i := strings.Index(text, " "); i != -1 {
return text[:i]
}
// e.g.: ["/hello@world_bot", "/hello@", "/hello@123"]
// Result: "/hello"
if i := strings.Index(text, "@"); i != -1 {
return text[:i]
}
return text
}
return ""