added hasCommandPrefix
This commit is contained in:
19
utils.go
19
utils.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
)
|
)
|
||||||
@ -28,3 +29,21 @@ func getFeedbackExtendedDescription(bc botConfig) *chat1.UserBotExtendedDescript
|
|||||||
MobileBody: "Please note: Your feedback will be public!",
|
MobileBody: "Please note: Your feedback will be public!",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasCommandPrefix determines if the command matches either command or name variant
|
||||||
|
func hasCommandPrefix(s string, baseCommand string, botName string, subCommands string) bool {
|
||||||
|
// if this is actually a command
|
||||||
|
if strings.HasPrefix(s, "!") || strings.HasPrefix(s, "@") {
|
||||||
|
// generate the two possible command variants
|
||||||
|
botCommand := fmt.Sprintf("%s %s", baseCommand, subCommands)
|
||||||
|
nameCommand := fmt.Sprintf("%s %s", botName, subCommands)
|
||||||
|
// then remove the ! or @ from the string
|
||||||
|
s = strings.Replace(s, "!", "", 1)
|
||||||
|
s = strings.Replace(s, "@", "", 1)
|
||||||
|
// then check if either command variant is a match to the subCommands sent
|
||||||
|
if strings.HasPrefix(s, botCommand) || strings.HasPrefix(s, nameCommand) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user