mirror of https://github.com/velour/catbase.git
Add multiple command character support.
Now you can use ¡!
This commit is contained in:
parent
7b7c0dc5bb
commit
0badd5f2ce
16
bot/bot.go
16
bot/bot.go
|
@ -218,16 +218,12 @@ func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Checks if message is a command and returns its curtailed version
|
||||
func IsCmd(c *config.Config, message string) (bool, string) {
|
||||
cmdc := c.CommandChar
|
||||
cmdcs := c.CommandChar
|
||||
botnick := strings.ToLower(c.Nick)
|
||||
iscmd := false
|
||||
lowerMessage := strings.ToLower(message)
|
||||
|
||||
if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 {
|
||||
iscmd = true
|
||||
message = message[len(cmdc):]
|
||||
// } else if match, _ := regexp.MatchString(rex, lowerMessage); match {
|
||||
} else if strings.HasPrefix(lowerMessage, botnick) &&
|
||||
if strings.HasPrefix(lowerMessage, botnick) &&
|
||||
len(lowerMessage) > len(botnick) &&
|
||||
(lowerMessage[len(botnick)] == ',' || lowerMessage[len(botnick)] == ':') {
|
||||
|
||||
|
@ -238,6 +234,14 @@ func IsCmd(c *config.Config, message string) (bool, string) {
|
|||
if message[0] == ':' || message[0] == ',' {
|
||||
message = message[1:]
|
||||
}
|
||||
} else {
|
||||
for _, cmdc := range cmdcs {
|
||||
if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 {
|
||||
iscmd = true
|
||||
message = message[len(cmdc):]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trim off any whitespace left on the message
|
||||
|
|
|
@ -27,7 +27,7 @@ type Config struct {
|
|||
Nick string
|
||||
FullName string
|
||||
Version string
|
||||
CommandChar string
|
||||
CommandChar []string
|
||||
RatePerSec float64
|
||||
LogLength int
|
||||
Admins []string
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
},
|
||||
"Nick": "CatBaseTest",
|
||||
"FullName": "CatBase",
|
||||
"CommandChar": "!",
|
||||
"CommandChar": ["!", "¡"],
|
||||
"RatePerSec": 10.0,
|
||||
"LogLength": 50,
|
||||
"Admins": ["<Admin Nick>"],
|
||||
|
|
Loading…
Reference in New Issue