sanitary high5
This commit is contained in:
parent
45d7dc3ae6
commit
5be882f004
@ -10,7 +10,7 @@
|
|||||||
|BotSnack|`(?i)botsnack`|Consumes a botsnack. This pleases mcchunkie and brings balance to the universe.|
|
|BotSnack|`(?i)botsnack`|Consumes a botsnack. This pleases mcchunkie and brings balance to the universe.|
|
||||||
|Feder|`(?i)^feder: (.*)$`|check the Matrix federation status of a given URL.|
|
|Feder|`(?i)^feder: (.*)$`|check the Matrix federation status of a given URL.|
|
||||||
|Ham|`(?i)^ham: (\w+)$`|queries the FCC's [ULS](https://wireless2.fcc.gov/UlsApp/UlsSearch/searchLicense.jsp) for a given callsign.|
|
|Ham|`(?i)^ham: (\w+)$`|queries the FCC's [ULS](https://wireless2.fcc.gov/UlsApp/UlsSearch/searchLicense.jsp) for a given callsign.|
|
||||||
|HighFive|`o/|\o`|Everyone loves highfives.|
|
|HighFive|`o/|\\o`|Everyone loves highfives.|
|
||||||
|Hi|`(?i)^hi|hi$`|Friendly bots say hi.|
|
|Hi|`(?i)^hi|hi$`|Friendly bots say hi.|
|
||||||
|LoveYou|`(?i)i love you`|Spreading love where ever we can by responding when someone shows us love.|
|
|LoveYou|`(?i)i love you`|Spreading love where ever we can by responding when someone shows us love.|
|
||||||
|OpenBSDMan|`(?i)^man: ([1-9][p]?)?\s?(.+)$`|Produces a link to man.openbsd.org.|
|
|OpenBSDMan|`(?i)^man: ([1-9][p]?)?\s?(.+)$`|Produces a link to man.openbsd.org.|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMatch(t *testing.T) {
|
func TestBeatMatch(t *testing.T) {
|
||||||
testStrings := make(map[string]bool)
|
testStrings := make(map[string]bool)
|
||||||
testStrings["what time is it??!!?!"] = true
|
testStrings["what time is it??!!?!"] = true
|
||||||
testStrings["what time is it"] = false
|
testStrings["what time is it"] = false
|
||||||
|
@ -2,7 +2,8 @@ package plugins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
)
|
)
|
||||||
@ -16,7 +17,7 @@ func rightFive() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func leftFive() string {
|
func leftFive() string {
|
||||||
return "\\o"
|
return `\\o`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Descr describes this plugin
|
// Descr describes this plugin
|
||||||
@ -34,18 +35,26 @@ func (h *HighFive) SetStore(s PluginStore) {}
|
|||||||
|
|
||||||
// Match determines if we should bother giving a high five
|
// Match determines if we should bother giving a high five
|
||||||
func (h *HighFive) Match(user, msg string) bool {
|
func (h *HighFive) Match(user, msg string) bool {
|
||||||
return ToMe(user, msg)
|
re := regexp.MustCompile(h.Re())
|
||||||
|
return ToMe(user, msg) && re.MatchString(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RespondText to high five events
|
// RespondText to high five events
|
||||||
func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
func (h *HighFive) RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, post string) {
|
||||||
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
s := NameRE.ReplaceAllString(ev.Sender, "$1")
|
||||||
|
|
||||||
if strings.Contains(post, rightFive()) {
|
rm := regexp.MustCompile(rightFive())
|
||||||
|
lm := regexp.MustCompile(leftFive())
|
||||||
|
|
||||||
|
if rm.MatchString(post) {
|
||||||
SendText(c, ev.RoomID, fmt.Sprintf("\\o %s", s))
|
SendText(c, ev.RoomID, fmt.Sprintf("\\o %s", s))
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
SendText(c, ev.RoomID, fmt.Sprintf("now go wash your hands, %s", s))
|
||||||
}
|
}
|
||||||
if strings.Contains(post, leftFive()) {
|
if lm.MatchString(post) {
|
||||||
SendText(c, ev.RoomID, fmt.Sprintf("%s o/", s))
|
SendText(c, ev.RoomID, fmt.Sprintf("%s o/", s))
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
SendText(c, ev.RoomID, fmt.Sprintf("now go wash your hands, %s", s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
plugins/highfive_test.go
Normal file
20
plugins/highfive_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHighFiveMatch(t *testing.T) {
|
||||||
|
testStrings := make(map[string]bool)
|
||||||
|
testStrings["o/"] = true
|
||||||
|
testStrings[`\o`] = true
|
||||||
|
testStrings["_o"] = false
|
||||||
|
testStrings["o_"] = false
|
||||||
|
|
||||||
|
h := &HighFive{}
|
||||||
|
for msg, should := range testStrings {
|
||||||
|
if h.Match("", msg) != should {
|
||||||
|
t.Errorf("HighFive expected to match %q (%t); but doesn't\n", msg, should)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user