2020-02-02 07:23:59 -07:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrix"
|
|
|
|
)
|
|
|
|
|
2020-03-13 15:04:39 -06:00
|
|
|
var version string
|
|
|
|
|
2020-02-02 07:23:59 -07:00
|
|
|
// Version responds to hi messages
|
|
|
|
type Version struct {
|
|
|
|
}
|
|
|
|
|
2020-02-11 07:56:19 -07:00
|
|
|
// Descr describes this plugin
|
|
|
|
func (v *Version) Descr() string {
|
|
|
|
return "Show a bit of information about what we are."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re matches version
|
|
|
|
func (v *Version) Re() string {
|
|
|
|
return `(?i)version$`
|
|
|
|
}
|
|
|
|
|
2020-02-10 17:10:57 -07:00
|
|
|
// Match checks for "version" anywhere. Might want to tighten this one down at
|
|
|
|
// some point
|
|
|
|
func (v *Version) Match(user, msg string) bool {
|
2020-02-11 07:56:19 -07:00
|
|
|
re := regexp.MustCompile(v.Re())
|
2020-02-10 17:10:57 -07:00
|
|
|
return re.MatchString(msg) && ToMe(user, msg)
|
2020-02-02 07:23:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Version) print(to string) string {
|
2020-03-13 15:04:39 -06:00
|
|
|
if version == "" {
|
|
|
|
version = "unknown version"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s running on %s", version, runtime.GOOS)
|
2020-02-02 07:23:59 -07:00
|
|
|
}
|
|
|
|
|
2020-02-05 22:04:04 -07:00
|
|
|
// SetStore does nothing in here
|
2020-02-10 17:10:57 -07:00
|
|
|
func (v *Version) SetStore(s PluginStore) {}
|
2020-02-05 22:04:04 -07:00
|
|
|
|
2020-02-02 19:43:26 -07:00
|
|
|
// RespondText to version events
|
|
|
|
func (v *Version) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
|
|
|
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
2020-02-10 17:10:57 -07:00
|
|
|
|
|
|
|
SendText(c, ev.RoomID, v.print(s))
|
2020-02-02 07:23:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name Version
|
|
|
|
func (v *Version) Name() string {
|
|
|
|
return "Version"
|
|
|
|
}
|