diff --git a/main.go b/main.go index 074c1d5..6f3a71b 100644 --- a/main.go +++ b/main.go @@ -18,10 +18,11 @@ import ( func main() { var username, password, userID, accessToken, server, db, avatar, botOwner string var key, value, get string - var setup, doc bool + var setup, doc, debug bool flag.BoolVar(&doc, "doc", false, "print plugin information and exit") flag.BoolVar(&setup, "s", false, "setup account") + flag.BoolVar(&debug, "debug", false, "print debug messages") flag.StringVar(&avatar, "avatar", "", "set the avatar of the bot to specified url") flag.StringVar(&db, "db", "db", "full path to database directory") @@ -206,8 +207,15 @@ func main() { } if p.Match(username, post) { + log.Printf("%s: responding to '%s'", p.Name(), ev.Sender) p.SetStore(store) + + start := time.Now() p.RespondText(cli, ev, username, post) + elapsed := time.Since(start) + if debug { + log.Printf("%s took %s to run\n", p.Name(), elapsed) + } } } } diff --git a/plugins/beer.go b/plugins/beer.go index 72efffa..02e4c74 100644 --- a/plugins/beer.go +++ b/plugins/beer.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "math/rand" "net/url" "regexp" @@ -120,7 +119,6 @@ func (h *Beer) SetStore(s PluginStore) {} func (h *Beer) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { beer := h.fix(post) if beer != "" { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) var beers = &BeerResp{} u := fmt.Sprintf("%s%s", "https://data.opendatasoft.com/api/records/1.0/search?dataset=open-beer-database%40public-us&q=", diff --git a/plugins/botsnack.go b/plugins/botsnack.go index 792f968..f158154 100644 --- a/plugins/botsnack.go +++ b/plugins/botsnack.go @@ -1,7 +1,6 @@ package plugins import ( - "log" "math/rand" "regexp" "time" @@ -49,7 +48,6 @@ func (h *BotSnack) SetStore(s PluginStore) {} func (h *BotSnack) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { u := NameRE.ReplaceAllString(user, "$1") if ToMe(u, post) { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, h.resp()) } } diff --git a/plugins/federation.go b/plugins/federation.go index 6a84c24..6f00ca3 100644 --- a/plugins/federation.go +++ b/plugins/federation.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "net/url" "regexp" "time" @@ -63,8 +62,6 @@ func (h *Feder) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post s homeServer = u.Hostname() - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) - furl := fmt.Sprintf("%s%s", "https://federationtester.matrix.org/api/report?server_name=", url.PathEscape(homeServer), diff --git a/plugins/hi.go b/plugins/hi.go index 00f6c6b..30c6092 100644 --- a/plugins/hi.go +++ b/plugins/hi.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "regexp" "github.com/matrix-org/gomatrix" @@ -35,7 +34,6 @@ func (h *Hi) SetStore(s PluginStore) {} func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { s := NameRE.ReplaceAllString(ev.Sender, "$1") - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("hi %s!", s)) } diff --git a/plugins/highfive.go b/plugins/highfive.go index 3f50dfb..a6543ac 100644 --- a/plugins/highfive.go +++ b/plugins/highfive.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "strings" "github.com/matrix-org/gomatrix" @@ -43,11 +42,9 @@ func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, pos s := NameRE.ReplaceAllString(ev.Sender, "$1") if strings.Contains(post, rightFive()) { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("\\o %s", s)) } if strings.Contains(post, leftFive()) { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("%s o/", s)) } } diff --git a/plugins/love.go b/plugins/love.go index e9fd547..e987e3d 100644 --- a/plugins/love.go +++ b/plugins/love.go @@ -1,7 +1,6 @@ package plugins import ( - "log" "math/rand" "regexp" "time" @@ -48,7 +47,6 @@ func (h *LoveYou) SetStore(s PluginStore) {} // RespondText to love events func (h *LoveYou) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, h.resp()) } diff --git a/plugins/openbsd_man.go b/plugins/openbsd_man.go index f676f38..6ee3f94 100644 --- a/plugins/openbsd_man.go +++ b/plugins/openbsd_man.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "regexp" "github.com/matrix-org/gomatrix" @@ -51,7 +50,6 @@ func (h *OpenBSDMan) SetStore(s PluginStore) {} func (h *OpenBSDMan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { page := h.fix(post) if page != "" { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("https://man.openbsd.org/%s", page)) } } diff --git a/plugins/snap.go b/plugins/snap.go index f03e0de..0376d80 100644 --- a/plugins/snap.go +++ b/plugins/snap.go @@ -3,7 +3,6 @@ package plugins import ( "fmt" "io/ioutil" - "log" "net/http" "regexp" @@ -35,7 +34,6 @@ func (p *Snap) SetStore(s PluginStore) {} // RespondText to looking up of federation check requests func (p *Snap) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { - log.Printf("%s: responding to '%s'", p.Name(), ev.Sender) resp, err := http.Get("https://ftp.usa.openbsd.org/pub/OpenBSD/snapshots/amd64/BUILDINFO") if err != nil { SendText(c, ev.RoomID, fmt.Sprintf("%s", err)) diff --git a/plugins/source.go b/plugins/source.go index e5c6192..8daaa7d 100644 --- a/plugins/source.go +++ b/plugins/source.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "regexp" "github.com/matrix-org/gomatrix" @@ -35,7 +34,6 @@ func (h *Source) SetStore(s PluginStore) {} func (h *Source) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { s := NameRE.ReplaceAllString(ev.Sender, "$1") - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie")) } diff --git a/plugins/thanks.go b/plugins/thanks.go index d2600e4..ecac208 100644 --- a/plugins/thanks.go +++ b/plugins/thanks.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "math/rand" "regexp" "time" @@ -46,7 +45,6 @@ func (h *Thanks) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post rand.Seed(time.Now().Unix()) - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, a[rand.Intn(len(a))]) } diff --git a/plugins/version.go b/plugins/version.go index c6ffd5b..7e72ad7 100644 --- a/plugins/version.go +++ b/plugins/version.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "regexp" "runtime" @@ -41,7 +40,6 @@ func (v *Version) SetStore(s PluginStore) {} func (v *Version) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { s := NameRE.ReplaceAllString(ev.Sender, "$1") - log.Printf("%s: responding to '%s'", v.Name(), ev.Sender) SendText(c, ev.RoomID, v.print(s)) } diff --git a/plugins/weather.go b/plugins/weather.go index 1e64965..021effc 100644 --- a/plugins/weather.go +++ b/plugins/weather.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "net/http" "net/url" "regexp" @@ -167,7 +166,6 @@ func (h *Weather) fix(msg string) string { func (h *Weather) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { weather := h.fix(post) if weather != "" { - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) wd, err := h.get(weather) if err != nil { SendText(c, ev.RoomID, fmt.Sprintf("sorry %s, I can't look up the weather. %s", ev.Sender, err)) diff --git a/plugins/welcome_back.go b/plugins/welcome_back.go index 251707e..abd1b0f 100644 --- a/plugins/welcome_back.go +++ b/plugins/welcome_back.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "log" "regexp" "github.com/matrix-org/gomatrix" @@ -35,7 +34,6 @@ func (h *Wb) SetStore(s PluginStore) {} func (h *Wb) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) { s := NameRE.ReplaceAllString(ev.Sender, "$1") - log.Printf("%s: responding to '%s'", h.Name(), ev.Sender) SendText(c, ev.RoomID, fmt.Sprintf("thanks %s!", s)) }