Accidentally killed ACTION at some point, adding back in

This commit is contained in:
Chris Sexton 2013-01-23 10:53:31 -05:00
parent 2cb0eba9b8
commit f31e43e3bc
2 changed files with 28 additions and 1 deletions

View File

@ -73,6 +73,10 @@ func main() {
b.ActionRecieved(conn, line)
})
c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) {
b.MsgRecieved(conn, line)
})
c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
b.MsgRecieved(conn, line)
})

View File

@ -7,6 +7,7 @@ import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"sort"
"strings"
"time"
)
@ -23,6 +24,20 @@ type idleEntry struct {
LastSeen time.Time
}
type idleEntries []*idleEntry
func (ie idleEntries) Len() int {
return len(ie)
}
func (ie idleEntries) Less(i, j int) bool {
return ie[i].LastSeen.After(ie[j].LastSeen)
}
func (ie idleEntries) Swap(i, j int) {
ie[i], ie[j] = ie[j], ie[i]
}
// NewDowntimePlugin creates a new DowntimePlugin with the Plugin interface
func NewDowntimePlugin(bot *bot.Bot) *DowntimePlugin {
p := DowntimePlugin{
@ -55,6 +70,12 @@ func (p *DowntimePlugin) Message(message bot.Message) bool {
nick, time.Now().Sub(entry.LastSeen)))
}
ret = true
} else if parts[0] == "idle" && len(parts) == 1 {
// Find all idle times, report them.
var entries idleEntries
p.Coll.Find(nil).All(entries)
sort.Sort(entries)
fmt.Printf("%+v\n", entries)
}
p.record(strings.ToLower(message.User.Name))
@ -76,7 +97,6 @@ func (p *DowntimePlugin) record(user string) {
// Update their entry, they were baaaaaad
entry.LastSeen = time.Now()
p.Coll.Upsert(bson.M{"nick": entry.Nick}, entry)
log.Println("Updated downtime for:", user)
}
}
@ -110,6 +130,9 @@ func (p *DowntimePlugin) Event(kind string, message bot.Message) bool {
}
} else if kind == "PART" {
p.remove(strings.ToLower(message.User.Name))
} else {
log.Println("Unknown event: ", message)
p.record(strings.ToLower(message.User.Name))
}
return false
}