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 }