Better command detection
This commit is contained in:
parent
b94b92c2d2
commit
8269e40ff3
2 changed files with 16 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
config.json
|
||||
clessy-broker
|
||||
clessy-mods
|
13
mods/main.go
13
mods/main.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
|
||||
"../tg"
|
||||
)
|
||||
|
@ -10,8 +11,20 @@ func dispatch(broker *tg.Broker, update tg.APIMessage) {
|
|||
metafora(broker, update)
|
||||
}
|
||||
|
||||
func isCommand(update tg.APIMessage, cmdname string) bool {
|
||||
if update.Text == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
text := *(update.Text)
|
||||
return strings.HasPrefix(text, "/"+cmdname+"@"+*botname) || (strings.HasPrefix(text, "/"+cmdname) && !strings.Contains(text, "@"))
|
||||
}
|
||||
|
||||
var botname *string
|
||||
|
||||
func main() {
|
||||
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
|
||||
botname = flag.String("botname", "maudbot", "Bot name for /targetet@commands")
|
||||
flag.Parse()
|
||||
|
||||
err := tg.CreateBrokerClient(*brokerAddr, dispatch)
|
||||
|
|
Reference in a new issue