2020-09-08 11:45:14 -06:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// RFC sends rfc urls when someone references an rfc
|
2020-09-08 11:45:14 -06:00
|
|
|
type RFC struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *RFC) Descr() string {
|
|
|
|
return "Produces a link to tools.ietf.org."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re matches our man format
|
|
|
|
func (h *RFC) Re() string {
|
|
|
|
return `(?i)^rfc\s?([0-9]+)$`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Match checks for our man page re
|
|
|
|
func (h *RFC) Match(_, msg string) bool {
|
|
|
|
re := regexp.MustCompile(h.Re())
|
|
|
|
return re.MatchString(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStore does nothing in RFC
|
|
|
|
func (h *RFC) SetStore(_ PluginStore) {}
|
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// Process does the heavy lifting
|
|
|
|
func (h *RFC) Process(from, post string) string {
|
2020-09-08 11:45:14 -06:00
|
|
|
re := regexp.MustCompile(h.Re())
|
|
|
|
rfcNum := re.ReplaceAllString(post, "$1")
|
|
|
|
if rfcNum != "" {
|
2021-04-01 16:15:25 -06:00
|
|
|
return fmt.Sprintf("https://tools.ietf.org/html/rfc%s", rfcNum)
|
2020-09-08 11:45:14 -06:00
|
|
|
}
|
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
return "that's not an RFC."
|
|
|
|
}
|
|
|
|
|
|
|
|
// RespondText sends back a man page.
|
|
|
|
func (h *RFC) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error {
|
|
|
|
return SendText(c, ev.RoomID, h.Process(ev.Sender, post))
|
2020-09-08 11:45:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name RFC
|
|
|
|
func (h *RFC) Name() string {
|
|
|
|
return "RFC"
|
|
|
|
}
|