Fixed error with beers and reporting a particular users' beers

This commit is contained in:
Chris Sexton 2012-08-17 22:53:39 -04:00
parent 9990decfc7
commit 5b3784a9ed
1 changed files with 13 additions and 8 deletions

View File

@ -76,13 +76,7 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
count, err := strconv.Atoi(parts[2]) count, err := strconv.Atoi(parts[2])
if err != nil { if err != nil {
// if it's not a number, maybe it's a nick! // if it's not a number, maybe it's a nick!
if p.doIKnow(parts[2]) { p.Bot.SendMessage(channel, "Sorry, that didn't make any sense.")
p.reportCount(parts[2], channel, false)
} else {
msg := fmt.Sprintf("Sorry, I don't know %s.", parts[2])
p.Bot.SendMessage(channel, msg)
return true
}
} }
if count < 0 { if count < 0 {
@ -103,6 +97,13 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
} else { } else {
p.Bot.SendMessage(channel, "I don't know your math.") p.Bot.SendMessage(channel, "I don't know your math.")
} }
} else if len(parts) == 2 {
if p.doIKnow(parts[1]) {
p.reportCount(parts[1], channel, false)
} else {
msg := fmt.Sprintf("Sorry, I don't know %s.", parts[1])
p.Bot.SendMessage(channel, msg)
}
} else if len(parts) == 1 { } else if len(parts) == 1 {
p.reportCount(nick, channel, true) p.reportCount(nick, channel, true)
} }
@ -159,8 +160,12 @@ func (p *BeersPlugin) reportCount(nick, channel string, himself bool) {
beers := p.getBeers(nick) beers := p.getBeers(nick)
msg := fmt.Sprintf("%s has had %d beers so far.", nick, beers) msg := fmt.Sprintf("%s has had %d beers so far.", nick, beers)
if himself { if himself {
if beers == 0 {
msg = fmt.Sprintf("You really need to get drinkin, %s!", nick)
} else {
msg = fmt.Sprintf("You've had %d beers so far, %s.", beers, nick) msg = fmt.Sprintf("You've had %d beers so far, %s.", beers, nick)
} }
}
p.Bot.SendMessage(channel, msg) p.Bot.SendMessage(channel, msg)
fmt.Println("I should have reported a beer count!") fmt.Println("I should have reported a beer count!")
} }