2020-02-01 20:53:56 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Source responds to source requests
|
|
|
|
type Source struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Source) match(msg string) bool {
|
|
|
|
re := regexp.MustCompile(`(?i)where is your (source|code)`)
|
|
|
|
return re.MatchString(msg)
|
|
|
|
}
|
|
|
|
|
2020-02-02 19:43:26 -07:00
|
|
|
// RespondText to questions about TheSource™©®⑨
|
|
|
|
func (h *Source) 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("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie"))
|
2020-02-01 20:53:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name Source
|
|
|
|
func (h *Source) Name() string {
|
|
|
|
return "Source"
|
|
|
|
}
|