summaryrefslogtreecommitdiff
path: root/urban.go
blob: 49007fbbc01b177af5682929f5778d8f396aee89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"fmt"
	"strings"

	"dim13.org/urban"
	irc "github.com/fluffle/goirc/client"
)

type Urban struct{ Command }

func (_ Urban) WithArgs(_ int) bool { return true }
func (_ Urban) Handle(conn *irc.Conn, line *irc.Line) {
	if q := strings.SplitN(line.Text(), " ", 2); len(q) == 2 {
		if u, err := urban.QueryTop(q[1]); err != nil {
			conn.Notice(line.Target(), err.Error())
		} else {
			s := fmt.Sprintf("%v: %v", u.Word, u.Definition)
			conn.Notice(line.Target(), s)
		}
	}
}

func init() {
	Register("urban", &Urban{
		Command{
			Help: "Perform urban dictionary search",
		},
	})
}