summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-21 17:48:26 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-21 17:48:26 +0200
commit8bd2d3eebb19cd2641d5a12f6d26f4c13f9d1c0b (patch)
tree6dc16e10c5df3452a2b90384ca9ae28e45a5161d
parent6dd926817d0fc77fdeeb5aea0c5ad156d5007c4e (diff)
Extract rfc from the line
-rw-r--r--main.go1
-rw-r--r--rfc.go22
2 files changed, 6 insertions, 17 deletions
diff --git a/main.go b/main.go
index b09d1c1..eba02eb 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,7 @@ func privmsg(conn *irc.Conn, line *irc.Line) {
}
Dispatch(conn, line)
ExtractLinks(conn, line)
+ ExtractRFC(conn, line)
DetectFlood(conn, line)
}
diff --git a/rfc.go b/rfc.go
index 69c0b7e..a072cc1 100644
--- a/rfc.go
+++ b/rfc.go
@@ -3,7 +3,6 @@ package main
import (
"fmt"
"log"
- "strconv"
"strings"
"dim13.org/rfc"
@@ -12,20 +11,14 @@ import (
var rfcMap = make(map[int]rfc.Entry)
-type RFC struct{ Command }
-
-func (_ RFC) Timeout() bool { return false }
-func (_ RFC) WithArgs(n int) bool { return n == 2 }
-func (_ RFC) Handle(conn *irc.Conn, line *irc.Line) {
- if q := strings.Fields(line.Text()); len(q) == 2 {
- if id, err := strconv.Atoi(q[1]); err != nil {
- conn.Privmsg(line.Target(), err.Error())
- } else {
+func ExtractRFC(conn *irc.Conn, line *irc.Line) {
+ for _, v := range strings.Fields(line.Text()) {
+ var id int
+ w := strings.ToUpper(v)
+ if _, err := fmt.Sscanf(w, "RFC%d", &id); err == nil {
if entry, ok := rfcMap[id]; ok {
s := fmt.Sprint(entry)
conn.Privmsg(line.Target(), s)
- } else {
- conn.Privmsg(line.Target(), "not found")
}
}
}
@@ -44,9 +37,4 @@ func init() {
id := e.ID()
rfcMap[id] = e
}
- Register("rfc", &RFC{
- Command{
- Help: "Perform RFC lookup",
- },
- })
}