summaryrefslogtreecommitdiff
path: root/duck.go
blob: 1d126e1d299a86acb55ce21048bfafd8139244d9 (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
package main

import (
	"strings"

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

type Duck struct{ Command }

func (_ Duck) WithArgs(_ int) bool { return true }

func (_ Duck) Handle(conn *irc.Conn, line *irc.Line) {
	if q := strings.SplitN(line.Text(), " ", 2); len(q) == 2 {
		if a, err := duck.Abstract(q[1]); err != nil {
			conn.Notice(line.Target(), err.Error())
		} else {
			conn.Notice(line.Target(), a)
		}
	}
}

func (_ Duck) Help() string {
	return "Perform nuckduckgo instant answer search"
}

func init() {
	Register("define", &Duck{})
}