summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go36
1 files changed, 20 insertions, 16 deletions
diff --git a/main.go b/main.go
index 8d142ce..dc83ac2 100644
--- a/main.go
+++ b/main.go
@@ -8,19 +8,24 @@ import (
irc "github.com/fluffle/goirc/client"
)
-func notify(conn *irc.Conn, target string) chan string {
+type Notify struct {
+ conn *irc.Conn
+ target string
+}
+
+func NewNotify(conn *irc.Conn, target string) *Notify {
+ return &Notify{conn: conn, target: target}
+}
+
+func (n *Notify) Write(p []byte) (int, error) {
const maxLen = 500
- c := make(chan string, 1)
- go func() {
- for msg := range c {
- if len(msg) > maxLen {
- msg = msg[:maxLen] + "..."
- }
- log.Println("send", msg)
- conn.Notice(target, msg)
- }
- }()
- return c
+ sz := len(p)
+ if sz > maxLen {
+ p = append(p[:maxLen], []byte("...")...)
+ }
+ log.Printf("Send %s", p)
+ n.conn.Notice(n.target, string(p))
+ return sz, nil
}
func privmsg(room string) irc.HandlerFunc {
@@ -33,13 +38,12 @@ func privmsg(room string) irc.HandlerFunc {
}
default:
for _, v := range getLinks(t) {
- log.Println("URL", v)
title, err := getTitle(v)
if err != nil {
- log.Println(err)
+ log.Printf("URL %v: %v", v, err)
}
if title != "" {
- conn.Notice(line.Target(), fmt.Sprintf("Title: %v", t))
+ fmt.Fprintf(NewNotify(conn, line.Target()), "Title: %v", t)
}
}
}
@@ -66,7 +70,7 @@ func main() {
conn.HandleFunc(irc.CONNECTED, func(conn *irc.Conn, _ *irc.Line) {
conn.Join(*room)
- go Watch(notify(conn, *room), Feeds)
+ go Watch(NewNotify(conn, *room), Feeds)
})
conn.HandleFunc(irc.PRIVMSG, privmsg(*room))