mcchunkie/plugins/hi.go

44 lines
843 B
Go
Raw Normal View History

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 {
}
// 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 {
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
// RespondText to hi events
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
s := NameRE.ReplaceAllString(ev.Sender, "$1")
2020-02-10 17:10:57 -07:00
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"
}