summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/main.go b/main.go
index 6150db4..105bf55 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,8 @@ import (
irc "github.com/fluffle/goirc/client"
)
+const maxLen = 500
+
type Notify struct {
conn *irc.Conn
target string
@@ -18,15 +20,19 @@ 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
- sz := len(p)
- if sz > maxLen {
- p = append(p[:maxLen], []byte("...")...)
+func limit(n int, s string) string {
+ r := []rune(s)
+ if sz := len(r); sz > n {
+ r = append(r[:n], []rune("...")...)
}
- log.Println("Send", string(p))
- n.conn.Notice(n.target, string(p))
- return sz, nil
+ return string(r)
+}
+
+func (n *Notify) Write(p []byte) (int, error) {
+ s := limit(maxLen, string(p))
+ log.Println("Send", s)
+ n.conn.Notice(n.target, s)
+ return len(p), nil
}
func privmsg(room string) irc.HandlerFunc {
@@ -57,7 +63,7 @@ func privmsg(room string) irc.HandlerFunc {
fmt.Fprintf(NewNotify(conn, line.Target()), "Title: %v", title)
}
}
- last[line.Nick] = t
+ last[line.Nick] = limit(maxLen, t)
}
}
}