mcchunkie/plugins/plugins.go

68 lines
1.5 KiB
Go
Raw Normal View History

2020-01-31 19:57:40 -07:00
package plugins
import (
"regexp"
"strings"
"github.com/matrix-org/gomatrix"
)
2020-02-05 22:04:04 -07:00
// PluginStore matches MCStore so that the main store can be used by plugins.
type PluginStore interface {
Set(key, values string)
Get(key string) (string, error)
}
// Plugin defines the functions a plugin must implement to be used by
// mcchunkie.
2020-01-31 19:57:40 -07:00
type Plugin interface {
//Respond(c *gomatrix.Client, ev *gomatrix.Event, user string)
RespondText(c *gomatrix.Client, ev *gomatrix.Event, user, path string)
2020-01-31 19:57:40 -07:00
Name() string
2020-02-05 22:04:04 -07:00
SetStore(s PluginStore)
2020-01-31 19:57:40 -07:00
}
// NameRE matches the "friendly" name. This is typically used in tab
// completion.
2020-01-31 19:57:40 -07:00
var NameRE = regexp.MustCompile(`@(.+):.+$`)
// ToMe returns true of the message pertains to the bot
func ToMe(user, message string) bool {
return strings.Contains(message, user)
}
// 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 {
2020-01-31 19:57:40 -07:00
_, err := c.UserTyping(roomID, true, 3)
if err != nil {
return err
}
c.SendText(roomID, message)
_, err = c.UserTyping(roomID, false, 0)
if err != nil {
return err
}
return nil
}
// Plugins is a collection of our plugins. An instance of this is iterated
// over for each message the bot receives.
2020-01-31 19:57:40 -07:00
type Plugins []Plugin
// Plugs defines the "enabled" plugins.
2020-01-31 19:57:40 -07:00
var Plugs = Plugins{
2020-02-01 15:14:46 -07:00
&Beer{},
2020-01-31 20:27:22 -07:00
&BotSnack{},
2020-01-31 19:57:40 -07:00
&HighFive{},
&Hi{},
2020-02-01 15:15:01 -07:00
&LoveYou{},
2020-02-03 16:19:04 -07:00
&OpenBSDMan{},
&Source{},
2020-02-02 07:23:59 -07:00
&Version{},
2020-02-07 16:06:24 -07:00
&Wb{},
2020-02-05 22:13:23 -07:00
&Weather{},
2020-01-31 19:57:40 -07:00
}