mcchunkie/plugins/highfive.go

59 lines
1.2 KiB
Go
Raw Normal View History

2020-01-31 19:58:17 -07:00
package plugins
import (
"fmt"
"log"
"strings"
"github.com/matrix-org/gomatrix"
)
// HighFive high fives!
type HighFive struct {
}
func rightFive() string {
return "o/"
}
func leftFive() string {
return "\\o"
}
// Descr describes this plugin
func (h *HighFive) Descr() string {
return "Everyone loves highfives."
}
// Re are the regexes that high five uses
func (h *HighFive) Re() string {
return fmt.Sprintf("%s|%s", rightFive(), leftFive())
}
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 *HighFive) SetStore(s PluginStore) {}
2020-02-05 22:04:04 -07:00
2020-02-10 17:10:57 -07:00
// Match determines if we should bother giving a high five
func (h *HighFive) Match(user, msg string) bool {
return ToMe(user, msg)
}
// RespondText to high five events
func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
s := NameRE.ReplaceAllString(ev.Sender, "$1")
2020-02-10 17:10:57 -07:00
if strings.Contains(post, rightFive()) {
2020-02-10 17:10:57 -07:00
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
SendText(c, ev.RoomID, fmt.Sprintf("\\o %s", s))
}
if strings.Contains(post, leftFive()) {
2020-02-10 17:10:57 -07:00
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
SendText(c, ev.RoomID, fmt.Sprintf("%s o/", s))
2020-01-31 19:58:17 -07:00
}
}
// Name returns the name of the HighFive plugin
func (h *HighFive) Name() string {
return "HighFive"
}