Making the counters aware of the bot itself.

This commit is contained in:
Chris Sexton 2013-05-07 19:30:37 -04:00
parent e8ff495c2f
commit 46fa81cd68
2 changed files with 12 additions and 5 deletions

View File

@ -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):]

View File

@ -4,6 +4,7 @@ import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"strings"
)
@ -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)