From 5d7384866154a7ed11d14d78f86b792d627c6ca1 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Mon, 10 Feb 2020 16:08:33 -0700 Subject: [PATCH] +staticcheck --- main.go | 28 ++++++++-------------------- plugins/beer.go | 12 ++++++++---- plugins/botsnack.go | 2 +- plugins/hi.go | 2 +- plugins/highfive.go | 2 +- plugins/love.go | 2 +- plugins/openbsd_man.go | 2 +- plugins/source.go | 2 +- plugins/version.go | 2 +- plugins/weather.go | 12 ++++++++---- plugins/welcome_back.go | 2 +- 11 files changed, 32 insertions(+), 36 deletions(-) diff --git a/main.go b/main.go index 35810cf..cdd5828 100644 --- a/main.go +++ b/main.go @@ -6,32 +6,12 @@ import ( "log" "net/http" "os" - "strings" "time" "git.sr.ht/~qbit/mcchunkie/plugins" "github.com/matrix-org/gomatrix" ) -func messageToMe(sn, message string) bool { - return strings.Contains(message, sn) -} - -func sendMessage(c *gomatrix.Client, roomID, message string) error { - _, err := c.UserTyping(roomID, true, 3) - if err != nil { - return err - } - - c.SendText(roomID, message) - - _, err = c.UserTyping(roomID, false, 0) - if err != nil { - return err - } - return nil -} - func main() { var username, password, userID, accessToken, server, db, avatar string var key, value, get string @@ -75,6 +55,11 @@ func main() { if server == "" { server, err = store.Get("server") + if err != nil { + if err != nil { + log.Fatalf("%s\n", err) + } + } if server == "" { log.Fatalln("please specify a server") } @@ -90,6 +75,9 @@ func main() { "", "", ) + if err != nil { + log.Fatalf("%s\n", err) + } if setup { log.Println("requesting access token") diff --git a/plugins/beer.go b/plugins/beer.go index 5e2e00e..8cb549b 100644 --- a/plugins/beer.go +++ b/plugins/beer.go @@ -74,13 +74,17 @@ type Records struct { RecordTimestamp time.Time `json:"record_timestamp"` } +func (h *Beer) re() string { + return `(?i)^beer: ` +} + func (h *Beer) fix(msg string) string { - re := regexp.MustCompile(`(?i)^beer: `) + re := regexp.MustCompile(h.re()) return re.ReplaceAllString(msg, "$1") } func (h *Beer) match(msg string) bool { - re := regexp.MustCompile(`(?i)^beer: `) + re := regexp.MustCompile(h.re()) return re.MatchString(msg) } @@ -130,7 +134,7 @@ func (h *Beer) pretty(b BeerResp, random bool) string { } // SetStore we don't need a store here. -func (h *Beer) SetStore(s PluginStore) { return } +func (h *Beer) SetStore(s PluginStore) {} // RespondText to looking up of beer requests func (h *Beer) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { @@ -147,7 +151,7 @@ func (h *Beer) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post st case brr.Nhits == 0: SendText(c, ev.RoomID, "¯\\_(ツ)_/¯") case brr.Nhits == 1: - SendText(c, ev.RoomID, fmt.Sprintf("%s", h.pretty(*brr, false))) + SendText(c, ev.RoomID, h.pretty(*brr, false)) case brr.Nhits > 1: SendText(c, ev.RoomID, fmt.Sprintf("Found %d beers, here is a random one:\n%s", brr.Nhits, h.pretty(*brr, true))) } diff --git a/plugins/botsnack.go b/plugins/botsnack.go index ce73f4f..dd5096f 100644 --- a/plugins/botsnack.go +++ b/plugins/botsnack.go @@ -32,7 +32,7 @@ func (h *BotSnack) resp() string { } // SetStore we don't need a store, so just return -func (h *BotSnack) SetStore(s PluginStore) { return } +func (h *BotSnack) SetStore(s PluginStore) {} // RespondText to botsnack events func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/hi.go b/plugins/hi.go index eb6d72d..a7b2fc8 100644 --- a/plugins/hi.go +++ b/plugins/hi.go @@ -18,7 +18,7 @@ func (h *Hi) match(msg string) bool { } // SetStore we don't need a store here -func (h *Hi) SetStore(s PluginStore) { return } +func (h *Hi) SetStore(s PluginStore) {} // RespondText to hi events func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/highfive.go b/plugins/highfive.go index d41593a..64be97b 100644 --- a/plugins/highfive.go +++ b/plugins/highfive.go @@ -13,7 +13,7 @@ type HighFive struct { } // SetStore we don't need a store here. -func (h *HighFive) SetStore(s PluginStore) { return } +func (h *HighFive) SetStore(s PluginStore) {} // RespondText to high five events func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/love.go b/plugins/love.go index 467ef58..bd44658 100644 --- a/plugins/love.go +++ b/plugins/love.go @@ -33,7 +33,7 @@ func (h *LoveYou) resp() string { } // SetStore we don't need a store, so just return -func (h *LoveYou) SetStore(s PluginStore) { return } +func (h *LoveYou) SetStore(s PluginStore) {} // RespondText to love events func (h *LoveYou) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/openbsd_man.go b/plugins/openbsd_man.go index 33ee794..b6e92e2 100644 --- a/plugins/openbsd_man.go +++ b/plugins/openbsd_man.go @@ -38,7 +38,7 @@ func (h *OpenBSDMan) match(msg string) bool { } // SetStore does nothing in OpenBSDMan -func (h *OpenBSDMan) SetStore(s PluginStore) { return } +func (h *OpenBSDMan) SetStore(s PluginStore) {} // RespondText sends back a man page. func (h *OpenBSDMan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/source.go b/plugins/source.go index d5599ef..1a95fb7 100644 --- a/plugins/source.go +++ b/plugins/source.go @@ -18,7 +18,7 @@ func (h *Source) match(msg string) bool { } // SetStore does nothing in here -func (h *Source) SetStore(s PluginStore) { return } +func (h *Source) SetStore(s PluginStore) {} // RespondText to questions about TheSource™©®⑨ func (h *Source) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/version.go b/plugins/version.go index b8deac2..7c1fc1e 100644 --- a/plugins/version.go +++ b/plugins/version.go @@ -23,7 +23,7 @@ func (v *Version) print(to string) string { } // SetStore does nothing in here -func (h *Version) SetStore(s PluginStore) { return } +func (h *Version) SetStore(s PluginStore) {} // RespondText to version events func (v *Version) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { diff --git a/plugins/weather.go b/plugins/weather.go index f98fd33..973b631 100644 --- a/plugins/weather.go +++ b/plugins/weather.go @@ -112,7 +112,7 @@ func (h *Weather) get(loc string) (*WeatherResp, error) { } if key == "" { - return nil, fmt.Errorf("No API key set") + return nil, fmt.Errorf("no API key set") } v := url.Values{} @@ -142,13 +142,17 @@ func (h *Weather) get(loc string) (*WeatherResp, error) { return w, nil } +func (h *Weather) re() string { + return `(?i)^weather: (\d+)$` +} + func (h *Weather) match(msg string) bool { - re := regexp.MustCompile(`(?i)^weather: \d+$`) + re := regexp.MustCompile(h.re()) return re.MatchString(msg) } func (h *Weather) fix(msg string) string { - re := regexp.MustCompile(`(?i)^weather: (\d+)$`) + re := regexp.MustCompile(h.re()) return re.ReplaceAllString(msg, "$1") } @@ -163,7 +167,7 @@ func (h *Weather) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post SendText(c, ev.RoomID, fmt.Sprintf("sorry %s, I can't look up the weather. %s", ev.Sender, err)) } SendText(c, ev.RoomID, - fmt.Sprintf("%s: %s (%s) Humidity: %s, %s", + fmt.Sprintf("%s: %s (%s) Humidity: %s%%, %s", wd.Name, wd.f(), wd.c(), diff --git a/plugins/welcome_back.go b/plugins/welcome_back.go index deef635..9526a13 100644 --- a/plugins/welcome_back.go +++ b/plugins/welcome_back.go @@ -18,7 +18,7 @@ func (h *Wb) match(msg string) bool { } // SetStore we don't need a store here -func (h *Wb) SetStore(s PluginStore) { return } +func (h *Wb) SetStore(s PluginStore) {} // RespondText to welcome back events func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {