36 lines
670 B
Go
36 lines
670 B
Go
package plugins
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"regexp"
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
)
|
|
|
|
// Hi responds to hi messages
|
|
type Hi struct {
|
|
}
|
|
|
|
func (h *Hi) match(msg string) bool {
|
|
re := regexp.MustCompile(`(?i)^hi|hi$`)
|
|
return re.MatchString(msg)
|
|
}
|
|
|
|
// RespondText to hi events
|
|
func (h *Hi) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
|
u := NameRE.ReplaceAllString(user, "$1")
|
|
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
|
if ToMe(u, post) {
|
|
if h.match(post) {
|
|
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
|
SendText(c, ev.RoomID, fmt.Sprintf("hi %s!", s))
|
|
}
|
|
}
|
|
}
|
|
|
|
// Name hi
|
|
func (h *Hi) Name() string {
|
|
return "Hi"
|
|
}
|