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 {
|
func CheckCommand(text string, entities []*TextEntity) string {
|
||||||
if IsCommand(text) {
|
if IsCommand(text) {
|
||||||
var cmd string
|
cmd := text
|
||||||
|
|
||||||
// e.g. ["/hello 123", "/hell o 123"]
|
// e.g. ["/hello 123", "/hell o 123"]
|
||||||
// Result: "/hello", "/hell"
|
// Result: "/hello", "/hell"
|
||||||
if i := strings.Index(text, " "); i != -1 {
|
if i := strings.Index(cmd, " "); i != -1 {
|
||||||
cmd = text[:i]
|
cmd = cmd[:i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g.: ["/hello@world_bot", "/hello@", "/hello@123"]
|
// e.g.: ["/hello@world_bot", "/hello@", "/hello@123"]
|
||||||
// Result: "/hello"
|
// Result: "/hello"
|
||||||
if i := strings.Index(text, "@"); i != -1 {
|
if i := strings.Index(cmd, "@"); i != -1 {
|
||||||
cmd = text[:i]
|
cmd = cmd[:i]
|
||||||
}
|
|
||||||
|
|
||||||
if cmd == "" {
|
|
||||||
return text
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue