From f22db3b8ba23c66dce23602c5e948aa7b6d5af31 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 21 Jul 2015 17:06:35 +0200 Subject: Split a bit --- duck.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 duck.go (limited to 'duck.go') diff --git a/duck.go b/duck.go new file mode 100644 index 0000000..83e4440 --- /dev/null +++ b/duck.go @@ -0,0 +1,30 @@ +package main + +import ( + "strings" + + "dim13.org/duck" + irc "github.com/fluffle/goirc/client" +) + +type Duck struct{ Command } + +func (_ Duck) Timeout() bool { return false } +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.Privmsg(line.Target(), err.Error()) + } else { + conn.Privmsg(line.Target(), a) + } + } +} + +func init() { + Register("define", &Duck{ + Command{ + Help: "Perform duckduckgo instant answer search", + }, + }) +} -- cgit v1.2.3