all repos — paprika @ time

go rewrite of taigabot

plugins/location.go (view raw)

 1package plugins
 2
 3import (
 4	"fmt"
 5	"strings"
 6
 7	"git.icyphox.sh/paprika/plugins/location"
 8	"gopkg.in/irc.v3"
 9)
10
11func init() {
12	Register(Location{})
13}
14
15type Location struct{}
16
17func (Location) Triggers() []string {
18	return []string{".loc", ".location"}
19}
20
21func (Location) Execute(m *irc.Message) (string, error) {
22	parsed := strings.SplitN(m.Trailing(), " ", 2)
23	trigger := parsed[0]
24	if len(parsed) != 2 {
25		return fmt.Sprintf("Usage: %s <location>", trigger), nil
26	}
27	loc := parsed[1]
28
29	err := location.SetLocation(loc, m.Prefix.Name)
30	if err != nil {
31		return "Error setting location", err
32	}
33
34	return "Successfully set location", nil
35}