Added random affirmations for beer drinking

This commit is contained in:
Chris Sexton 2012-08-24 21:52:15 -04:00
parent a71e743e79
commit c8bc3a6034
1 changed files with 12 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"math/rand"
) )
// This is a skeleton plugin to serve as an example and quick copy/paste for new plugins. // This is a skeleton plugin to serve as an example and quick copy/paste for new plugins.
@ -86,13 +87,13 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
} }
if parts[1] == "+=" { if parts[1] == "+=" {
p.setBeers(user, p.getBeers(nick)+count) p.setBeers(user, p.getBeers(nick)+count)
p.reportCount(nick, channel, true) p.randomReply(channel)
} else if parts[1] == "=" { } else if parts[1] == "=" {
if count == 0 { if count == 0 {
p.puke(user, channel) p.puke(user, channel)
} else { } else {
p.setBeers(user, count) p.setBeers(user, count)
p.reportCount(nick, channel, true) p.randomReply(channel)
} }
} else { } else {
p.Bot.SendMessage(channel, "I don't know your math.") p.Bot.SendMessage(channel, "I don't know your math.")
@ -112,7 +113,7 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
return true return true
} else if parts[0] == "beers++" { } else if parts[0] == "beers++" {
p.addBeers(user) p.addBeers(user)
p.reportCount(nick, channel, true) p.randomReply(channel)
return true return true
} else if parts[0] == "puke" { } else if parts[0] == "puke" {
p.puke(user, channel) p.puke(user, channel)
@ -121,7 +122,7 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
if message.Command && parts[0] == "imbibe" { if message.Command && parts[0] == "imbibe" {
p.addBeers(user) p.addBeers(user)
p.reportCount(nick, channel, true) p.randomReply(channel)
return true return true
} }
@ -133,6 +134,7 @@ func (p *BeersPlugin) Message(message bot.Message) bool {
// date. // date.
func (p *BeersPlugin) LoadData() { func (p *BeersPlugin) LoadData() {
p.Coll = p.Bot.Db.C("beers") p.Coll = p.Bot.Db.C("beers")
rand.Seed(time.Now().Unix())
} }
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
@ -187,3 +189,9 @@ func (p *BeersPlugin) doIKnow(nick string) bool {
} }
return count > 0 return count > 0
} }
// Sends random affirmation to the channel. This could be better (with a datastore for sayings)
func (p *BeersPlugin) randomReply(channel string) {
replies := []string{"ZIGGY! ZAGGY!", "HIC!", "Stay thirsty, my friend!"}
p.Bot.SendMessage(channel, replies[rand.Intn(len(replies))])
}