From f31e43e3bc13369c929b5406d1a751523fa3d446 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Wed, 23 Jan 2013 10:53:31 -0500 Subject: [PATCH] Accidentally killed ACTION at some point, adding back in --- main.go | 4 ++++ plugins/downtime.go | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 0282d0f..ec1eca4 100644 --- a/main.go +++ b/main.go @@ -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) }) diff --git a/plugins/downtime.go b/plugins/downtime.go index ad162cf..2f8ec77 100644 --- a/plugins/downtime.go +++ b/plugins/downtime.go @@ -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 }