+staticcheck
This commit is contained in:
parent
c7f54fe204
commit
5d73848661
28
main.go
28
main.go
@ -6,32 +6,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~qbit/mcchunkie/plugins"
|
"git.sr.ht/~qbit/mcchunkie/plugins"
|
||||||
"github.com/matrix-org/gomatrix"
|
"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() {
|
func main() {
|
||||||
var username, password, userID, accessToken, server, db, avatar string
|
var username, password, userID, accessToken, server, db, avatar string
|
||||||
var key, value, get string
|
var key, value, get string
|
||||||
@ -75,6 +55,11 @@ func main() {
|
|||||||
|
|
||||||
if server == "" {
|
if server == "" {
|
||||||
server, err = store.Get("server")
|
server, err = store.Get("server")
|
||||||
|
if err != nil {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if server == "" {
|
if server == "" {
|
||||||
log.Fatalln("please specify a server")
|
log.Fatalln("please specify a server")
|
||||||
}
|
}
|
||||||
@ -90,6 +75,9 @@ func main() {
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
if setup {
|
if setup {
|
||||||
log.Println("requesting access token")
|
log.Println("requesting access token")
|
||||||
|
@ -74,13 +74,17 @@ type Records struct {
|
|||||||
RecordTimestamp time.Time `json:"record_timestamp"`
|
RecordTimestamp time.Time `json:"record_timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Beer) re() string {
|
||||||
|
return `(?i)^beer: `
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Beer) fix(msg string) string {
|
func (h *Beer) fix(msg string) string {
|
||||||
re := regexp.MustCompile(`(?i)^beer: `)
|
re := regexp.MustCompile(h.re())
|
||||||
return re.ReplaceAllString(msg, "$1")
|
return re.ReplaceAllString(msg, "$1")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Beer) match(msg string) bool {
|
func (h *Beer) match(msg string) bool {
|
||||||
re := regexp.MustCompile(`(?i)^beer: `)
|
re := regexp.MustCompile(h.re())
|
||||||
return re.MatchString(msg)
|
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.
|
// 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
|
// RespondText to looking up of beer requests
|
||||||
func (h *Beer) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
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:
|
case brr.Nhits == 0:
|
||||||
SendText(c, ev.RoomID, "¯\\_(ツ)_/¯")
|
SendText(c, ev.RoomID, "¯\\_(ツ)_/¯")
|
||||||
case brr.Nhits == 1:
|
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:
|
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)))
|
SendText(c, ev.RoomID, fmt.Sprintf("Found %d beers, here is a random one:\n%s", brr.Nhits, h.pretty(*brr, true)))
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func (h *BotSnack) resp() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore we don't need a store, so just return
|
// 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
|
// RespondText to botsnack events
|
||||||
func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -18,7 +18,7 @@ func (h *Hi) match(msg string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore we don't need a store here
|
// 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
|
// RespondText to hi events
|
||||||
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -13,7 +13,7 @@ type HighFive struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore we don't need a store here.
|
// 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
|
// RespondText to high five events
|
||||||
func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -33,7 +33,7 @@ func (h *LoveYou) resp() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore we don't need a store, so just return
|
// 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
|
// RespondText to love events
|
||||||
func (h *LoveYou) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *LoveYou) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -38,7 +38,7 @@ func (h *OpenBSDMan) match(msg string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore does nothing in OpenBSDMan
|
// SetStore does nothing in OpenBSDMan
|
||||||
func (h *OpenBSDMan) SetStore(s PluginStore) { return }
|
func (h *OpenBSDMan) SetStore(s PluginStore) {}
|
||||||
|
|
||||||
// RespondText sends back a man page.
|
// RespondText sends back a man page.
|
||||||
func (h *OpenBSDMan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *OpenBSDMan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -18,7 +18,7 @@ func (h *Source) match(msg string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore does nothing in here
|
// SetStore does nothing in here
|
||||||
func (h *Source) SetStore(s PluginStore) { return }
|
func (h *Source) SetStore(s PluginStore) {}
|
||||||
|
|
||||||
// RespondText to questions about TheSource™©®⑨
|
// RespondText to questions about TheSource™©®⑨
|
||||||
func (h *Source) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *Source) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -23,7 +23,7 @@ func (v *Version) print(to string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore does nothing in here
|
// SetStore does nothing in here
|
||||||
func (h *Version) SetStore(s PluginStore) { return }
|
func (h *Version) SetStore(s PluginStore) {}
|
||||||
|
|
||||||
// RespondText to version events
|
// RespondText to version events
|
||||||
func (v *Version) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (v *Version) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
@ -112,7 +112,7 @@ func (h *Weather) get(loc string) (*WeatherResp, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if key == "" {
|
if key == "" {
|
||||||
return nil, fmt.Errorf("No API key set")
|
return nil, fmt.Errorf("no API key set")
|
||||||
}
|
}
|
||||||
|
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
@ -142,13 +142,17 @@ func (h *Weather) get(loc string) (*WeatherResp, error) {
|
|||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Weather) re() string {
|
||||||
|
return `(?i)^weather: (\d+)$`
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Weather) match(msg string) bool {
|
func (h *Weather) match(msg string) bool {
|
||||||
re := regexp.MustCompile(`(?i)^weather: \d+$`)
|
re := regexp.MustCompile(h.re())
|
||||||
return re.MatchString(msg)
|
return re.MatchString(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Weather) fix(msg string) string {
|
func (h *Weather) fix(msg string) string {
|
||||||
re := regexp.MustCompile(`(?i)^weather: (\d+)$`)
|
re := regexp.MustCompile(h.re())
|
||||||
return re.ReplaceAllString(msg, "$1")
|
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("sorry %s, I can't look up the weather. %s", ev.Sender, err))
|
||||||
}
|
}
|
||||||
SendText(c, ev.RoomID,
|
SendText(c, ev.RoomID,
|
||||||
fmt.Sprintf("%s: %s (%s) Humidity: %s, %s",
|
fmt.Sprintf("%s: %s (%s) Humidity: %s%%, %s",
|
||||||
wd.Name,
|
wd.Name,
|
||||||
wd.f(),
|
wd.f(),
|
||||||
wd.c(),
|
wd.c(),
|
||||||
|
@ -18,7 +18,7 @@ func (h *Wb) match(msg string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetStore we don't need a store here
|
// 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
|
// RespondText to welcome back events
|
||||||
func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user