diff --git a/bot/handlers.go b/bot/handlers.go index fc75ac8..0cec534 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -120,6 +120,7 @@ func (b *Bot) buildMessage(conn *irc.Conn, line *irc.Line) Message { if len(line.Args) > 1 { message = line.Args[1] } + iscmd := false filteredMessage := message if !isaction { @@ -244,7 +245,7 @@ func (b *Bot) Help(channel string, parts []string) { b.SendMessage(channel, msg) } -func (b *Bot) UserJoined(conn *irc.Conn, line *irc.Line) { +func (b *Bot) ActionRecieved(conn *irc.Conn, line *irc.Line) { msg := b.buildMessage(conn, line) for _, name := range b.PluginOrdering { p := b.Plugins[name] diff --git a/main.go b/main.go index ba1a2e1..0282d0f 100644 --- a/main.go +++ b/main.go @@ -53,12 +53,24 @@ func main() { // catches anything left, will always return true b.AddHandler("factoid", plugins.NewFactoidPlugin(b)) - c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) { - b.MsgRecieved(conn, line) + c.AddHandler("NICK", func(conn *irc.Conn, line *irc.Line) { + b.ActionRecieved(conn, line) + }) + + c.AddHandler("NAMES", func(conn *irc.Conn, line *irc.Line) { + b.ActionRecieved(conn, line) + }) + + c.AddHandler("MODE", func(conn *irc.Conn, line *irc.Line) { + b.ActionRecieved(conn, line) + }) + + c.AddHandler("PART", func(conn *irc.Conn, line *irc.Line) { + b.ActionRecieved(conn, line) }) c.AddHandler("JOIN", func(conn *irc.Conn, line *irc.Line) { - b.UserJoined(conn, line) + b.ActionRecieved(conn, line) }) c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) { diff --git a/plugins/downtime.go b/plugins/downtime.go index e4517a4..ad162cf 100644 --- a/plugins/downtime.go +++ b/plugins/downtime.go @@ -6,6 +6,7 @@ import ( "fmt" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" + "log" "strings" "time" ) @@ -70,14 +71,20 @@ func (p *DowntimePlugin) record(user string) { Nick: user, LastSeen: time.Now(), }) + log.Println("Inserted downtime for:", user) } else { // 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) } } +func (p *DowntimePlugin) remove(user string) { + p.Coll.RemoveAll(bson.M{"nick": user}) + log.Println("Removed downtime for:", user) +} + // LoadData imports any configuration data into the plugin. This is not strictly necessary other // than the fact that the Plugin interface demands it exist. This may be deprecated at a later // date. @@ -92,9 +99,17 @@ func (p *DowntimePlugin) Help(channel string, parts []string) { // Empty event handler because this plugin does not do anything on event recv func (p *DowntimePlugin) Event(kind string, message bot.Message) bool { - if kind == "JOIN" && message.User.Name != p.Bot.Config.Nick { + log.Println(kind, "\t", message) + if kind != "PART" && message.User.Name != p.Bot.Config.Nick { // user joined, let's nail them for it - p.record(strings.ToLower(message.User.Name)) + if kind == "NICK" { + p.record(strings.ToLower(message.Channel)) + p.remove(strings.ToLower(message.User.Name)) + } else { + p.record(strings.ToLower(message.User.Name)) + } + } else if kind == "PART" { + p.remove(strings.ToLower(message.User.Name)) } return false }