diff --git a/bot/bot.go b/bot/bot.go index d484eee..8651a3b 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -61,7 +61,7 @@ func NewBot(config *config.Config, c *irc.Conn) *Bot { return &Bot{ Config: config, Plugins: make(map[string]Handler), - Users: make([]User, 10), + Users: make([]User, 1), Conn: c, DbSession: session, Db: db, diff --git a/bot/handlers.go b/bot/handlers.go index ad60d5d..fe81a48 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -18,7 +18,9 @@ func (b *Bot) checkuser(nick string) *User { var user *User = nil for _, usr := range b.Users { if usr.Name == nick { + fmt.Println("Matched ", nick) user = &usr + break } } if user == nil { @@ -106,10 +108,6 @@ func (b *Bot) MsgRecieved(conn *irc.Conn, line *irc.Line) { } parts := strings.Fields(strings.ToLower(filteredMessage)) - if iscmd { - fmt.Println("Hey, I got a command!") - } - user.MessageLog = append(user.MessageLog, message) if strings.HasPrefix(filteredMessage, "help") && iscmd{ @@ -125,7 +123,7 @@ func (b *Bot) MsgRecieved(conn *irc.Conn, line *irc.Line) { Command: iscmd, Action: isaction, } - fmt.Printf("%#v\n", msg) + fmt.Printf("%#v said %#v\n", user, msg) for _, p := range b.Plugins { if p.Message(msg) { break diff --git a/plugins/beers.go b/plugins/beers.go index bcd97c2..2da0255 100644 --- a/plugins/beers.go +++ b/plugins/beers.go @@ -43,12 +43,12 @@ func (u *userBeers) Save(coll *mgo.Collection) { func getUserBeers(coll *mgo.Collection, nick string) *userBeers { ub := userBeers{New: true} - err := coll.Find(bson.M{"nick": nick}).One(&ub) - if err != nil { - panic(err) - } + coll.Find(bson.M{"nick": nick}).One(&ub) if ub.New == true { ub.New = false + ub.Nick = nick + ub.Beercount = 0 + ub.Momentum = 0 ub.Save(coll) } return &ub @@ -146,6 +146,7 @@ func (p *BeersPlugin) Help(channel string, parts []string) { func (p *BeersPlugin) setBeers(user *bot.User, amount int) { ub := getUserBeers(p.Coll, user.Name) ub.Beercount = amount + ub.Lastdrunk = time.Now() ub.Save(p.Coll) }