2020-01-31 19:58:17 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hi responds to hi messages
|
|
|
|
type Hi struct {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *Hi) Descr() string {
|
|
|
|
return "Friendly bots say hi."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re is the regex for matching hi messages.
|
|
|
|
func (h *Hi) Re() string {
|
|
|
|
return `(?i)^hi|hi$`
|
|
|
|
}
|
|
|
|
|
2020-02-10 17:10:57 -07:00
|
|
|
// Match determines if we are highfiving
|
|
|
|
func (h *Hi) Match(user, msg string) bool {
|
2020-02-11 07:56:19 -07:00
|
|
|
re := regexp.MustCompile(h.Re())
|
2020-02-10 17:10:57 -07:00
|
|
|
return re.MatchString(msg) && ToMe(user, msg)
|
2020-01-31 19:58:17 -07:00
|
|
|
}
|
|
|
|
|
2020-02-05 22:04:04 -07:00
|
|
|
// SetStore we don't need a store here
|
2020-05-13 17:05:01 -06:00
|
|
|
func (h *Hi) SetStore(_ PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// Process does the lifting
|
|
|
|
func (h *Hi) Process(from, post string) string {
|
|
|
|
s := NameRE.ReplaceAllString(from, "$1")
|
|
|
|
return fmt.Sprintf("hi %s!", s)
|
|
|
|
}
|
2020-02-10 17:10:57 -07:00
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// RespondText to hi events
|
|
|
|
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error {
|
|
|
|
return SendText(c, ev.RoomID, h.Process(ev.Sender, post))
|
2020-01-31 19:58:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name hi
|
|
|
|
func (h *Hi) Name() string {
|
|
|
|
return "Hi"
|
|
|
|
}
|