Merge pull request #1 from epsilon-0/master
add banana stabber + emote sending
This commit is contained in:
commit
76f90920b0
57
plugins/banana_stab.go
Normal file
57
plugins/banana_stab.go
Normal file
@ -0,0 +1,57 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/matrix-org/gomatrix"
|
||||
)
|
||||
|
||||
type BananaStab struct {
|
||||
}
|
||||
|
||||
// Descr describes this plugin
|
||||
func (h *BananaStab) Descr() string {
|
||||
return "Stab someone with some bananas."
|
||||
}
|
||||
|
||||
// Re matches our stabbing format
|
||||
func (h *BananaStab) Re() string {
|
||||
return `(?i)^stab: (.+)$`
|
||||
}
|
||||
|
||||
func (h *BananaStab) fix(msg string) string {
|
||||
re := regexp.MustCompile(h.Re())
|
||||
stabee := re.ReplaceAllString(msg, "$1")
|
||||
return stabee
|
||||
}
|
||||
|
||||
// Match checks for our stabee person
|
||||
func (h *BananaStab) Match(_, msg string) bool {
|
||||
re := regexp.MustCompile(h.Re())
|
||||
return re.MatchString(msg)
|
||||
}
|
||||
|
||||
// SetStore does nothing in BananaStab
|
||||
func (h *BananaStab) SetStore(_ PluginStore) {}
|
||||
|
||||
func (h *BananaStab) Process(from, post string) string {
|
||||
stabee := h.fix(post)
|
||||
stabtxt := "..."
|
||||
if stabee != "" {
|
||||
stabtxt = fmt.Sprintf("stabs %s with the fury of a thousand radioactive bananas", stabee)
|
||||
}
|
||||
//jsonmsg := "{ \"body\": \"" + stabtxt + "\", \"type\": \"m.emote\"}"
|
||||
return stabtxt
|
||||
}
|
||||
|
||||
// RespondText stabs an unsuspecting person
|
||||
func (h *BananaStab) RespondText(c *gomatrix.Client, ev *gomatrix.Event, _, post string) error {
|
||||
err := SendEmote(c, ev.RoomID, h.Process(ev.Sender, post))
|
||||
return err
|
||||
}
|
||||
|
||||
// Name BananaStab!
|
||||
func (h *BananaStab) Name() string {
|
||||
return "BananaStab"
|
||||
}
|
@ -139,6 +139,26 @@ func SendText(c *gomatrix.Client, roomID, message string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendEmote sends an emote to a given room. It pretends to be
|
||||
// "typing" by calling UserTyping for the caller.
|
||||
func SendEmote(c *gomatrix.Client, roomID, message string) error {
|
||||
_, err := c.UserTyping(roomID, true, 3)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = c.SendMessageEvent(roomID, "m.room.message", gomatrix.GetHTMLMessage("m.emote", message))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = c.UserTyping(roomID, false, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendHTML sends an html message to a given room. It pretends to be
|
||||
// "typing" by calling UserTyping for the caller.
|
||||
func SendHTML(c *gomatrix.Client, roomID, message string) error {
|
||||
@ -262,6 +282,7 @@ type Plugins []Plugin
|
||||
|
||||
// Plugs defines the "enabled" plugins.
|
||||
var Plugs = Plugins{
|
||||
&BananaStab{},
|
||||
&Beat{},
|
||||
&Beer{},
|
||||
&BotSnack{},
|
||||
|
Loading…
Reference in New Issue
Block a user