clessy-ng/utils/command.go

36 lines
595 B
Go
Raw Normal View History

2022-03-24 11:47:37 +00:00
package utils
import (
"strings"
"git.fromouter.space/hamcha/tg"
)
func IsCommand(update tg.APIUpdate, botname string, cmdname string) bool {
if update.Message == nil {
2022-03-24 11:47:37 +00:00
return false
}
message := update.Message
2022-03-24 11:47:37 +00:00
if message.Text == nil {
return false
}
text := strings.TrimSpace(*(message.Text))
2022-03-24 11:47:37 +00:00
shortcmd := "/" + cmdname
fullcmd := shortcmd + "@" + botname
// Check short form
if text == shortcmd || strings.HasPrefix(text, shortcmd+" ") {
return true
}
// Check long form
2022-03-27 20:53:50 +00:00
if text == fullcmd || strings.HasPrefix(text, fullcmd+" ") {
2022-03-24 11:47:37 +00:00
return true
}
return false
}