2020-02-01 20:53:56 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Source responds to source requests
|
|
|
|
type Source struct {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// Descr describes this plugin
|
|
|
|
func (h *Source) Descr() string {
|
|
|
|
return "Tell people where they can find more information about myself."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re matches the source code question
|
|
|
|
func (h *Source) Re() string {
|
|
|
|
return `(?i)where is your (source|code)`
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:36:26 -06:00
|
|
|
// Match determines if someone is asking about the source code
|
2020-02-10 17:10:57 -07:00
|
|
|
func (h *Source) Match(user, msg string) bool {
|
2020-02-11 07:56:19 -07:00
|
|
|
re := regexp.MustCompile(h.Re())
|
2020-02-10 17:10:57 -07:00
|
|
|
return re.MatchString(msg) && ToMe(user, msg)
|
2020-02-01 20:53:56 -07:00
|
|
|
}
|
|
|
|
|
2020-02-05 22:04:04 -07:00
|
|
|
// SetStore does nothing in here
|
2020-05-13 17:05:01 -06:00
|
|
|
func (h *Source) SetStore(_ PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2021-04-01 16:15:25 -06:00
|
|
|
// Process does the heavy lifting
|
|
|
|
func (h *Source) Process(from, post string) string {
|
|
|
|
s := NameRE.ReplaceAllString(from, "$1")
|
|
|
|
return fmt.Sprintf("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie")
|
|
|
|
}
|
|
|
|
|
2020-02-02 19:43:26 -07:00
|
|
|
// RespondText to questions about TheSource™©®⑨
|
2020-05-13 17:05:01 -06:00
|
|
|
func (h *Source) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, _ string) error {
|
2021-04-01 16:15:25 -06:00
|
|
|
return SendText(c, ev.RoomID, h.Process(ev.Sender, ""))
|
2020-02-01 20:53:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name Source
|
|
|
|
func (h *Source) Name() string {
|
|
|
|
return "Source"
|
|
|
|
}
|