From eff200ee150e4450c8c7eceb210defe70db4a403 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 16 Jun 2013 21:03:43 -0400 Subject: [PATCH] Fixing multi-channel factoid squirts. --- bot/handlers.go | 9 +++++++-- plugins/factoid.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bot/handlers.go b/bot/handlers.go index 0ae593d..5b026c7 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -125,12 +125,17 @@ func (b *Bot) buildMessage(conn *irc.Client, inMsg irc.Msg) Message { return msg } -func (b *Bot) LastMessage() (Message, error) { +func (b *Bot) LastMessage(channel string) (Message, error) { log := <-b.logOut if len(log) == 0 { return Message{}, errors.New("No messages found.") } - return log[len(log)-1], nil + for i := len(log); i > 0; i-- { + if log[i].Channel == channel { + return log[i], nil + } + } + return Message{}, errors.New("No messages found.") } // Take an input string and mutate it based on $vars in the string diff --git a/plugins/factoid.go b/plugins/factoid.go index ba99689..6830837 100644 --- a/plugins/factoid.go +++ b/plugins/factoid.go @@ -421,7 +421,7 @@ func (p *FactoidPlugin) factTimer(channel string) { for { time.Sleep(time.Duration(5) * time.Second) - lastmsg, err := p.Bot.LastMessage() + lastmsg, err := p.Bot.LastMessage(channel) if err != nil { continue }