diff --git a/bot/handlers.go b/bot/handlers.go index e8d9a27..8bf516c 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -84,10 +84,12 @@ func (b *Bot) isCmd(message string) (bool, string) { iscmd := false lowerMessage := strings.ToLower(message) + rex := fmt.Sprintf(`^%s\S\s.+`, botnick) + if strings.HasPrefix(lowerMessage, cmdc) && len(cmdc) > 0 { iscmd = true message = message[len(cmdc):] - } else if strings.HasPrefix(lowerMessage, botnick) && lowerMessage[len(botnick)] != ' ' { + } else if match, _ := regexp.MatchString(rex, lowerMessage); match { iscmd = true message = message[len(botnick):] diff --git a/plugins/counter.go b/plugins/counter.go index 966b6e9..a1b7810 100644 --- a/plugins/counter.go +++ b/plugins/counter.go @@ -4,6 +4,7 @@ import ( "fmt" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" + "log" "strings" ) @@ -31,8 +32,8 @@ func NewCounterPlugin(bot *bot.Bot) *CounterPlugin { } // Message responds to the bot hook on recieving messages. -// This function returns true if the plugin responds in a meaningful way to the -// users message. Otherwise, the function returns false and the bot continues +// This function returns true if the plugin responds in a meaningful way to the +// users message. Otherwise, the function returns false and the bot continues // execution of other plugins. func (p *CounterPlugin) Message(message bot.Message) bool { // This bot does not reply to anything @@ -40,6 +41,8 @@ func (p *CounterPlugin) Message(message bot.Message) bool { channel := message.Channel parts := strings.Split(message.Body, " ") + log.Println("++Message:", nick, channel, parts) + if len(parts) == 0 { return false } @@ -128,6 +131,8 @@ func (p *CounterPlugin) Message(message bot.Message) bool { itemName = nameParts[1] } + log.Println("++:", subject, itemName) + if strings.HasSuffix(parts[0], "++") { // ++ those fuckers item := p.update(subject, itemName, 1) @@ -165,8 +170,8 @@ func (p *CounterPlugin) update(subject, itemName string, delta int) Item { return item } -// LoadData imports any configuration data into the plugin. This is not -// strictly necessary other than the fact that the Plugin interface demands it +// LoadData imports any configuration data into the plugin. This is not +// strictly necessary other than the fact that the Plugin interface demands it // exist. This may be deprecated at a later date. func (p *CounterPlugin) LoadData() { // This bot has no data to load