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"
)
@ -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