package main import ( "fmt" "strings" "dim13.org/weather" irc "github.com/fluffle/goirc/client" ) type Weather struct { Command lastCity map[string]string } func (_ Weather) WithArgs(_ int) bool { return true } func (w *Weather) Handle(conn *irc.Conn, line *irc.Line) { var city string q := strings.SplitN(line.Text(), " ", 2) if len(q) == 2 { city = q[1] } else if l, ok := w.lastCity[line.Nick]; ok { city = l } else { conn.Notice(line.Target(), "set your location first") return } if c, err := weather.ByCityName(city); err != nil { conn.Notice(line.Target(), err.Error()) } else { conn.Notice(line.Target(), fmt.Sprint(c)) w.lastCity[line.Nick] = city } } func (_ Weather) Help() string { return "Fetch current weather" } func init() { Register("weather", &Weather{lastCity: make(map[string]string)}) }