Fixing multi-channel factoid squirts.

This commit is contained in:
Chris Sexton 2013-06-16 21:03:43 -04:00
parent 276cc3e2fe
commit eff200ee15
2 changed files with 8 additions and 3 deletions

View File

@ -125,12 +125,17 @@ func (b *Bot) buildMessage(conn *irc.Client, inMsg irc.Msg) Message {
return msg return msg
} }
func (b *Bot) LastMessage() (Message, error) { func (b *Bot) LastMessage(channel string) (Message, error) {
log := <-b.logOut log := <-b.logOut
if len(log) == 0 { if len(log) == 0 {
return Message{}, errors.New("No messages found.") 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 // Take an input string and mutate it based on $vars in the string

View File

@ -421,7 +421,7 @@ func (p *FactoidPlugin) factTimer(channel string) {
for { for {
time.Sleep(time.Duration(5) * time.Second) time.Sleep(time.Duration(5) * time.Second)
lastmsg, err := p.Bot.LastMessage() lastmsg, err := p.Bot.LastMessage(channel)
if err != nil { if err != nil {
continue continue
} }