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-02-10 16:08:33 -07:00
|
|
|
func (h *Hi) SetStore(s PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2020-02-02 19:43:26 -07:00
|
|
|
// RespondText to hi events
|
2020-05-13 16:53:31 -06:00
|
|
|
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) error {
|
2020-02-02 19:43:26 -07:00
|
|
|
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
2020-02-10 17:10:57 -07:00
|
|
|
|
2020-05-13 16:53:31 -06:00
|
|
|
return SendText(c, ev.RoomID, fmt.Sprintf("hi %s!", s))
|
2020-01-31 19:58:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name hi
|
|
|
|
func (h *Hi) Name() string {
|
|
|
|
return "Hi"
|
|
|
|
}
|