add openbsd man page shortcut

This commit is contained in:
Aaron Bieber 2020-02-03 16:19:04 -07:00
parent 8601d4a0f9
commit e318cb2d62
2 changed files with 40 additions and 0 deletions

39
plugins/openbsd_man.go Normal file
View File

@ -0,0 +1,39 @@
package plugins
import (
"fmt"
"log"
"regexp"
"github.com/matrix-org/gomatrix"
)
// OpenBSDMan responds to beer requests
type OpenBSDMan struct {
}
func (h *OpenBSDMan) fix(msg string) string {
re := regexp.MustCompile(`(?i)^man: `)
return re.ReplaceAllString(msg, "$1")
}
func (h *OpenBSDMan) match(msg string) bool {
re := regexp.MustCompile(`(?i)^man: `)
return re.MatchString(msg)
}
// RespondText sends back a man page.
func (h *OpenBSDMan) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
if h.match(post) {
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))
}
}
}
// Name OpenBSDMan!
func (h *OpenBSDMan) Name() string {
return "OpenBSDMan"
}

View File

@ -52,6 +52,7 @@ var Plugs = Plugins{
&HighFive{},
&Hi{},
&LoveYou{},
&OpenBSDMan{},
&Source{},
&Version{},
}