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)
|
|
|
|
}
|
|
|
|
|
2020-02-02 13:55:18 -07:00
|
|
|
// Plugin defines the functions a plugin must implement to be used by
|
|
|
|
// mcchunkie.
|
2020-01-31 19:57:40 -07:00
|
|
|
type Plugin interface {
|
2020-02-02 19:43:26 -07:00
|
|
|
//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
|
|
|
}
|
|
|
|
|
2020-02-02 13:55:18 -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)
|
|
|
|
}
|
|
|
|
|
2020-02-02 13:55:18 -07:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-02-02 13:55:18 -07:00
|
|
|
// 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
|
|
|
|
|
2020-02-02 13:55:18 -07:00
|
|
|
// 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{},
|
2020-02-01 20:53:56 -07:00
|
|
|
&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
|
|
|
}
|