mcchunkie/plugins/hi.go

44 lines
856 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
2020-05-13 16:53:31 -06:00
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) error {
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"
}