clarify docs a bit. rename SendMessage to SendText
This commit is contained in:
parent
84ba082334
commit
41e6bf180c
@ -141,16 +141,16 @@ func (h *Beer) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
brr, err := h.get(beer)
|
||||
if err != nil {
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("sorry %s, I can't look for beer. (%s)", ev.Sender, err))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("sorry %s, I can't look for beer. (%s)", ev.Sender, err))
|
||||
}
|
||||
|
||||
switch {
|
||||
case brr.Nhits == 0:
|
||||
SendMessage(c, ev.RoomID, "¯\\_(ツ)_/¯")
|
||||
SendText(c, ev.RoomID, "¯\\_(ツ)_/¯")
|
||||
case brr.Nhits == 1:
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("%s", h.pretty(*brr, false)))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("%s", h.pretty(*brr, false)))
|
||||
case brr.Nhits > 1:
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("Found %d beers, here is a random one:\n%s", brr.Nhits, h.pretty(*brr, true)))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("Found %d beers, here is a random one:\n%s", brr.Nhits, h.pretty(*brr, true)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (h *BotSnack) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string)
|
||||
if ToMe(u, post) {
|
||||
if h.match(post) {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, h.resp())
|
||||
SendText(c, ev.RoomID, h.resp())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func (h *Hi) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) {
|
||||
if ToMe(u, post) {
|
||||
if h.match(post) {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("hi %s!", s))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("hi %s!", s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ func (h *HighFive) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string)
|
||||
if ToMe(u, post) {
|
||||
if strings.Contains(post, "o/") {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("\\o %s", s))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("\\o %s", s))
|
||||
}
|
||||
if strings.Contains(post, "\\o") {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("%s o/", s))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("%s o/", s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func (h *LoveYou) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) {
|
||||
if ToMe(u, post) {
|
||||
if h.match(post) {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, h.resp())
|
||||
SendText(c, ev.RoomID, h.resp())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,15 @@ import (
|
||||
"github.com/matrix-org/gomatrix"
|
||||
)
|
||||
|
||||
// Plugin is an interface that specifies what a plugin needs to respond to.
|
||||
// Plugin defines the functions a plugin must implement to be used by
|
||||
// mcchunkie.
|
||||
type Plugin interface {
|
||||
Respond(c *gomatrix.Client, ev *gomatrix.Event, user string)
|
||||
Name() string
|
||||
}
|
||||
|
||||
// NameRE matches just the name of a matrix user
|
||||
// NameRE matches the "friendly" name. This is typically used in tab
|
||||
// completion.
|
||||
var NameRE = regexp.MustCompile(`@(.+):.+$`)
|
||||
|
||||
// ToMe returns true of the message pertains to the bot
|
||||
@ -21,8 +23,9 @@ func ToMe(user, message string) bool {
|
||||
return strings.Contains(message, user)
|
||||
}
|
||||
|
||||
// SendMessage sends a message to a given room
|
||||
func SendMessage(c *gomatrix.Client, roomID, message string) error {
|
||||
// SendText sends a text message to a given room. It pretends to be
|
||||
// "typing" by calling UserTyping for the caller.
|
||||
func SendText(c *gomatrix.Client, roomID, message string) error {
|
||||
_, err := c.UserTyping(roomID, true, 3)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -37,10 +40,11 @@ func SendMessage(c *gomatrix.Client, roomID, message string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Plugins area collection
|
||||
// Plugins is a collection of our plugins. An instance of this is iterated
|
||||
// over for each message the bot receives.
|
||||
type Plugins []Plugin
|
||||
|
||||
// Plugs are all of our plugins
|
||||
// Plugs defines the "enabled" plugins.
|
||||
var Plugs = Plugins{
|
||||
&Beer{},
|
||||
&BotSnack{},
|
||||
|
@ -28,7 +28,7 @@ func (h *Source) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) {
|
||||
if ToMe(u, post) {
|
||||
if h.match(post) {
|
||||
log.Printf("%s: responding to '%s'", h.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, fmt.Sprintf("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie"))
|
||||
SendText(c, ev.RoomID, fmt.Sprintf("%s: %s ;D", s, "https://git.sr.ht/~qbit/mcchunkie"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (v *Version) Respond(c *gomatrix.Client, ev *gomatrix.Event, user string) {
|
||||
if ToMe(u, post) {
|
||||
if v.match(post) {
|
||||
log.Printf("%s: responding to '%s'", v.Name(), ev.Sender)
|
||||
SendMessage(c, ev.RoomID, v.print(s))
|
||||
SendText(c, ev.RoomID, v.print(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user