diff --git a/bot/bot.go b/bot/bot.go index 40c661f..e2f958c 100644 --- a/bot/bot.go +++ b/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 diff --git a/config/config.go b/config/config.go index 719a423..21c1129 100644 --- a/config/config.go +++ b/config/config.go @@ -27,7 +27,7 @@ type Config struct { Nick string FullName string Version string - CommandChar string + CommandChar []string RatePerSec float64 LogLength int Admins []string diff --git a/example_config.json b/example_config.json index 0942470..63b28b0 100644 --- a/example_config.json +++ b/example_config.json @@ -16,7 +16,7 @@ }, "Nick": "CatBaseTest", "FullName": "CatBase", - "CommandChar": "!", + "CommandChar": ["!", "ยก"], "RatePerSec": 10.0, "LogLength": 50, "Admins": [""],