Added new mode support for downtime. Some of the additions in main are not needed, and it may be breaking other plugins.

This commit is contained in:
Chris Sexton 2013-01-22 19:22:32 -05:00
parent a27368af7e
commit 2cb0eba9b8
3 changed files with 35 additions and 7 deletions

View File

@ -120,6 +120,7 @@ func (b *Bot) buildMessage(conn *irc.Conn, line *irc.Line) Message {
if len(line.Args) > 1 { if len(line.Args) > 1 {
message = line.Args[1] message = line.Args[1]
} }
iscmd := false iscmd := false
filteredMessage := message filteredMessage := message
if !isaction { if !isaction {
@ -244,7 +245,7 @@ func (b *Bot) Help(channel string, parts []string) {
b.SendMessage(channel, msg) 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) msg := b.buildMessage(conn, line)
for _, name := range b.PluginOrdering { for _, name := range b.PluginOrdering {
p := b.Plugins[name] p := b.Plugins[name]

18
main.go
View File

@ -53,12 +53,24 @@ func main() {
// catches anything left, will always return true // catches anything left, will always return true
b.AddHandler("factoid", plugins.NewFactoidPlugin(b)) b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
c.AddHandler("ACTION", func(conn *irc.Conn, line *irc.Line) { c.AddHandler("NICK", func(conn *irc.Conn, line *irc.Line) {
b.MsgRecieved(conn, 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) { 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) { c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"labix.org/v2/mgo" "labix.org/v2/mgo"
"labix.org/v2/mgo/bson" "labix.org/v2/mgo/bson"
"log"
"strings" "strings"
"time" "time"
) )
@ -70,14 +71,20 @@ func (p *DowntimePlugin) record(user string) {
Nick: user, Nick: user,
LastSeen: time.Now(), LastSeen: time.Now(),
}) })
log.Println("Inserted downtime for:", user)
} else { } else {
// Update their entry, they were baaaaaad // Update their entry, they were baaaaaad
entry.LastSeen = time.Now() entry.LastSeen = time.Now()
p.Coll.Upsert(bson.M{"nick": entry.Nick}, entry) 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 // 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 // than the fact that the Plugin interface demands it exist. This may be deprecated at a later
// date. // 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 // Empty event handler because this plugin does not do anything on event recv
func (p *DowntimePlugin) Event(kind string, message bot.Message) bool { 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 // 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 return false
} }