2021-08-19 13:33:56 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
2021-09-10 15:57:04 +00:00
|
|
|
"github.com/Luzifer/twitch-bot/twitch"
|
2021-08-19 13:33:56 +00:00
|
|
|
"github.com/go-irc/irc"
|
2021-08-24 22:44:49 +00:00
|
|
|
"github.com/robfig/cron/v3"
|
2021-08-19 13:33:56 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Actor interface {
|
|
|
|
// Execute will be called after the config was read into the Actor
|
2021-09-22 13:36:45 +00:00
|
|
|
Execute(c *irc.Client, m *irc.Message, r *Rule, evtData FieldCollection, attrs FieldCollection) (preventCooldown bool, err error)
|
2021-08-19 13:33:56 +00:00
|
|
|
// IsAsync may return true if the Execute function is to be executed
|
|
|
|
// in a Go routine as of long runtime. Normally it should return false
|
|
|
|
// except in very specific cases
|
|
|
|
IsAsync() bool
|
|
|
|
// Name must return an unique name for the actor in order to identify
|
|
|
|
// it in the logs for debugging purposes
|
|
|
|
Name() string
|
2021-09-22 13:36:45 +00:00
|
|
|
// Validate will be called to validate the loaded configuration. It should
|
|
|
|
// return an error if required keys are missing from the AttributeStore
|
|
|
|
// or if keys contain broken configs
|
|
|
|
Validate(FieldCollection) error
|
2021-08-19 13:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ActorCreationFunc func() Actor
|
|
|
|
|
2021-09-22 13:36:45 +00:00
|
|
|
ActorRegistrationFunc func(name string, acf ActorCreationFunc)
|
|
|
|
|
|
|
|
ActorDocumentationRegistrationFunc func(ActionDocumentation)
|
2021-08-19 13:33:56 +00:00
|
|
|
|
2021-08-24 22:44:49 +00:00
|
|
|
CronRegistrationFunc func(spec string, cmd func()) (cron.EntryID, error)
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
LoggerCreationFunc func(moduleName string) *log.Entry
|
|
|
|
|
2021-09-02 21:26:39 +00:00
|
|
|
MsgFormatter func(tplString string, m *irc.Message, r *Rule, fields FieldCollection) (string, error)
|
2021-08-19 13:33:56 +00:00
|
|
|
|
2021-09-02 13:01:10 +00:00
|
|
|
RawMessageHandlerFunc func(m *irc.Message) error
|
|
|
|
RawMessageHandlerRegisterFunc func(RawMessageHandlerFunc) error
|
|
|
|
|
2021-08-19 13:33:56 +00:00
|
|
|
// RegisterFunc is the type of function your plugin must expose with the name Register
|
|
|
|
RegisterFunc func(RegistrationArguments) error
|
|
|
|
|
|
|
|
RegistrationArguments struct {
|
|
|
|
// FormatMessage is a method to convert templates into strings using internally known variables / configs
|
|
|
|
FormatMessage MsgFormatter
|
|
|
|
// GetLogger returns a sirupsen log.Entry pre-configured with the module name
|
|
|
|
GetLogger LoggerCreationFunc
|
2021-10-03 13:35:58 +00:00
|
|
|
// GetStorageManager returns an interface to access the modules storage
|
|
|
|
GetStorageManager func() StorageManager
|
2021-09-10 15:57:04 +00:00
|
|
|
// GetTwitchClient retrieves a fully configured Twitch client with initialized cache
|
|
|
|
GetTwitchClient func() *twitch.Client
|
2021-08-19 13:33:56 +00:00
|
|
|
// RegisterActor is used to register a new IRC rule-actor implementing the Actor interface
|
|
|
|
RegisterActor ActorRegistrationFunc
|
2021-09-22 13:36:45 +00:00
|
|
|
// RegisterActorDocumentation is used to register an ActorDocumentation for the config editor
|
|
|
|
RegisterActorDocumentation ActorDocumentationRegistrationFunc
|
2021-08-28 15:27:24 +00:00
|
|
|
// RegisterAPIRoute registers a new HTTP handler function including documentation
|
|
|
|
RegisterAPIRoute HTTPRouteRegistrationFunc
|
2021-08-24 22:44:49 +00:00
|
|
|
// RegisterCron is a method to register cron functions in the global cron instance
|
|
|
|
RegisterCron CronRegistrationFunc
|
2021-09-02 13:01:10 +00:00
|
|
|
// RegisterRawMessageHandler is a method to register an handler to receive ALL messages received
|
|
|
|
RegisterRawMessageHandler RawMessageHandlerRegisterFunc
|
2021-08-19 14:40:34 +00:00
|
|
|
// RegisterTemplateFunction can be used to register a new template functions
|
|
|
|
RegisterTemplateFunction TemplateFuncRegister
|
2021-08-19 13:33:56 +00:00
|
|
|
// SendMessage can be used to send a message not triggered by an event
|
|
|
|
SendMessage SendMessageFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageFunc func(*irc.Message) error
|
2021-08-19 14:40:34 +00:00
|
|
|
|
2021-10-03 13:35:58 +00:00
|
|
|
StorageManager interface {
|
|
|
|
DeleteModuleStore(moduleUUID string) error
|
|
|
|
GetModuleStore(moduleUUID string, storedObject StorageUnmarshaller) error
|
|
|
|
SetModuleStore(moduleUUID string, storedObject StorageMarshaller) error
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageMarshaller interface {
|
|
|
|
MarshalStoredObject() ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageUnmarshaller interface {
|
|
|
|
UnmarshalStoredObject([]byte) error
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:40:34 +00:00
|
|
|
TemplateFuncGetter func(*irc.Message, *Rule, map[string]interface{}) interface{}
|
|
|
|
TemplateFuncRegister func(name string, fg TemplateFuncGetter)
|
2021-08-19 13:33:56 +00:00
|
|
|
)
|
2021-08-19 14:40:34 +00:00
|
|
|
|
|
|
|
func GenericTemplateFunctionGetter(f interface{}) TemplateFuncGetter {
|
|
|
|
return func(*irc.Message, *Rule, map[string]interface{}) interface{} { return f }
|
|
|
|
}
|