mirror of https://github.com/velour/catbase.git
Merge pull request #34 from velour/morecmds
Add multiple command character support.
This commit is contained in:
commit
d72cb89692
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
|
// Checks if message is a command and returns its curtailed version
|
||||||
func IsCmd(c *config.Config, message string) (bool, string) {
|
func IsCmd(c *config.Config, message string) (bool, string) {
|
||||||
cmdc := c.CommandChar
|
cmdcs := c.CommandChar
|
||||||
botnick := strings.ToLower(c.Nick)
|
botnick := strings.ToLower(c.Nick)
|
||||||
iscmd := false
|
iscmd := false
|
||||||
lowerMessage := strings.ToLower(message)
|
lowerMessage := strings.ToLower(message)
|
||||||
|
|
||||||
if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 {
|
if strings.HasPrefix(lowerMessage, botnick) &&
|
||||||
iscmd = true
|
|
||||||
message = message[len(cmdc):]
|
|
||||||
// } else if match, _ := regexp.MatchString(rex, lowerMessage); match {
|
|
||||||
} else if strings.HasPrefix(lowerMessage, botnick) &&
|
|
||||||
len(lowerMessage) > len(botnick) &&
|
len(lowerMessage) > len(botnick) &&
|
||||||
(lowerMessage[len(botnick)] == ',' || 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] == ',' {
|
if message[0] == ':' || message[0] == ',' {
|
||||||
message = message[1:]
|
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
|
// trim off any whitespace left on the message
|
||||||
|
|
|
@ -27,7 +27,7 @@ type Config struct {
|
||||||
Nick string
|
Nick string
|
||||||
FullName string
|
FullName string
|
||||||
Version string
|
Version string
|
||||||
CommandChar string
|
CommandChar []string
|
||||||
RatePerSec float64
|
RatePerSec float64
|
||||||
LogLength int
|
LogLength int
|
||||||
Admins []string
|
Admins []string
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
"Nick": "CatBaseTest",
|
"Nick": "CatBaseTest",
|
||||||
"FullName": "CatBase",
|
"FullName": "CatBase",
|
||||||
"CommandChar": "!",
|
"CommandChar": ["!", "¡"],
|
||||||
"RatePerSec": 10.0,
|
"RatePerSec": 10.0,
|
||||||
"LogLength": 50,
|
"LogLength": 50,
|
||||||
"Admins": ["<Admin Nick>"],
|
"Admins": ["<Admin Nick>"],
|
||||||
|
|
Loading…
Reference in New Issue