From 28d101636212e8e539512916c4587ea8bf657ddb Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 20 Sep 2015 16:48:35 +0200 Subject: Add weather --- weather.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 weather.go (limited to 'weather.go') diff --git a/weather.go b/weather.go new file mode 100644 index 0000000..30c9be9 --- /dev/null +++ b/weather.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "strings" + + "dim13.org/weather" + irc "github.com/fluffle/goirc/client" +) + +type Weather struct{ Command } + +func (_ Weather) WithArgs(_ int) bool { return true } +func (_ Weather) Handle(conn *irc.Conn, line *irc.Line) { + if q := strings.SplitN(line.Text(), " ", 2); len(q) == 2 { + if c, err := weather.ByCityName(q[1]); err != nil { + conn.Notice(line.Target(), err.Error()) + } else { + conn.Notice(line.Target(), fmt.Sprint(c)) + } + } +} + +func init() { + Register("weather", &Weather{ + Command{ + Help: "Fertch current weather", + }, + }) +} -- cgit v1.2.3