summaryrefslogtreecommitdiff
path: root/weather.go
blob: 1c9792bb4ea6e43bdb16274bcf0ab099642acfec (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 (
	"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: "Fetch current weather",
		},
	})
}