diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -7,10 +7,16 @@ import ( irc "github.com/fluffle/goirc/client" ) +const maxLen = 500 + func notify(conn *irc.Conn, target string) chan string { c := make(chan string) go func() { for msg := range c { + log.Println("send", msg) + if len(msg) > maxLen { + msg = msg[:maxLen] + "..." + } conn.Notice(target, msg) } }() @@ -21,7 +27,10 @@ func kicker(conn *irc.Conn, channel string) chan string { c := make(chan string) go func() { for nick := range c { - conn.Kick(channel, nick) + if nick != conn.Me().Nick { + log.Println("kick", nick) + conn.Kick(channel, nick) + } } }() return c @@ -39,14 +48,14 @@ func discon(c chan struct{}) irc.HandlerFunc { } } -func privmsg(room string) irc.HandlerFunc { +func privmsg(n, k chan string, room string) irc.HandlerFunc { + go watchNews(n) // TODO shall it be there? + l := links(n) return func(conn *irc.Conn, line *irc.Line) { - go Links(conn, line) - if line.Public() && line.Nick != conn.Me().Nick { - if isFlood(line.Text()) { - log.Println("flood", line.Nick) - conn.Kick(room, line.Nick, "flood") - } + t := line.Text() + l <- t + if isFlood(t) { + k <- line.Nick } } } @@ -58,8 +67,10 @@ func main() { flag.Parse() c := irc.SimpleClient(*name) - c.EnableStateTracking() // XXX + //c.EnableStateTracking() // XXX done := make(chan struct{}) + n := notify(c, *room) + k := kicker(c, *room) // setup event handler handler := []struct { @@ -69,7 +80,7 @@ func main() { {irc.DISCONNECTED, discon(done)}, {irc.CONNECTED, join(*room)}, {irc.KICK, join(*room)}, - {irc.PRIVMSG, privmsg(*room)}, + {irc.PRIVMSG, privmsg(n, k, *room)}, } for _, h := range handler { c.HandleFunc(h.ev, h.f) @@ -80,9 +91,6 @@ func main() { log.Fatal(err) } - n := notify(c, *room) - go watchNews(n) - <-done log.Println("Disconnected") } |