mirror of
https://github.com/c0re100/gotdlib.git
synced 2026-02-21 20:20:17 +01:00
Fix command parser
This commit is contained in:
parent
51f3ce0659
commit
5c5078ec42
1 changed files with 5 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue