Documentation ¶
Overview ¶
Package plugins defines interfaces and helpers for plugin (internal and external ones) development and integration
Index ¶
- Constants
- Variables
- func DeriveChannel(m *irc.Message, evtData *fieldcollection.FieldCollection) string
- func DeriveUser(m *irc.Message, evtData *fieldcollection.FieldCollection) string
- type ActionDocumentation
- type ActionDocumentationField
- type ActionDocumentationFieldType
- type Actor
- type ActorCreationFunc
- type ActorDocumentationRegistrationFunc
- type ActorKit
- func (ActorKit) ValidateRequireNonEmpty(attrs *fieldcollection.FieldCollection, fields ...string) error
- func (ActorKit) ValidateRequireValidTemplate(tplValidator TemplateValidatorFunc, attrs *fieldcollection.FieldCollection, ...) error
- func (ActorKit) ValidateRequireValidTemplateIfSet(tplValidator TemplateValidatorFunc, attrs *fieldcollection.FieldCollection, ...) error
- type ActorRegistrationFunc
- type ChannelAnyPermissionCheckFunc
- type ChannelPermissionCheckFunc
- type CronRegistrationFunc
- type DatabaseCopyFunc
- type EventHandlerFunc
- type EventHandlerRegisterFunc
- type HTTPRouteParamDocumentation
- type HTTPRouteRegistrationArgs
- type HTTPRouteRegistrationFunc
- type HTTPRouteResponseType
- type LoggerCreationFunc
- type ModuleConfig
- type ModuleConfigGetterFunc
- type MsgFormatter
- type MsgModificationFunc
- type MsgModificationRegistrationFunc
- type RawMessageHandlerFunc
- type RawMessageHandlerRegisterFunc
- type RegisterFunc
- type RegistrationArguments
- type Rule
- func (r *Rule) GetMatchMessage() *regexp.Regexp
- func (r Rule) MatcherID() string
- func (r *Rule) Matches(m *irc.Message, event *string, timerStore TimerStore, ...) bool
- func (r *Rule) SetCooldown(timerStore TimerStore, m *irc.Message, ...)
- func (r *Rule) UpdateFromSubscription(ctx context.Context) (bool, error)
- func (r Rule) Validate(tplValidate TemplateValidatorFunc) error
- type RuleAction
- type SendMessageFunc
- type TemplateFuncDocumentation
- type TemplateFuncDocumentationExample
- type TemplateFuncGetter
- type TemplateFuncRegister
- type TemplateValidatorFunc
- type TimerEntry
- type TimerStore
- type TimerType
- type ValidateTokenFunc
Constants ¶
const DefaultConfigName = "default"
DefaultConfigName is the name the default configuration must have when defined
Variables ¶
var ErrSkipSendingMessage = errors.New("skip sending message")
ErrSkipSendingMessage should be returned by a MsgModificationFunc to prevent the message to be sent to the Twitch servers
var ErrStopRuleExecution = errors.New("stop rule execution now")
ErrStopRuleExecution is a way for actions to terminate execution of the current rule gracefully. No actions after this has been returned will be executed and no error state will be set
Functions ¶
func DeriveChannel ¶
func DeriveChannel(m *irc.Message, evtData *fieldcollection.FieldCollection) string
DeriveChannel takes an irc.Message and a FieldCollection and tries to extract from them the channel the event / message has taken place
func DeriveUser ¶
func DeriveUser(m *irc.Message, evtData *fieldcollection.FieldCollection) string
DeriveUser takes an irc.Message and a FieldCollection and tries to extract from them the user causing the event / message
Types ¶
type ActionDocumentation ¶
type ActionDocumentation struct { Description string `json:"description"` Name string `json:"name"` Type string `json:"type"` Fields []ActionDocumentationField `json:"fields"` }
ActionDocumentation contains the documentation for a single actor to be rendered into the documentation site
type ActionDocumentationField ¶
type ActionDocumentationField struct { Default string `json:"default"` DefaultComment string `json:"default_comment"` Description string `json:"description"` Key string `json:"key"` Long bool `json:"long"` Name string `json:"name"` Optional bool `json:"optional"` SupportTemplate bool `json:"support_template"` Type ActionDocumentationFieldType `json:"type"` }
ActionDocumentationField documents fields available in the actor
type ActionDocumentationFieldType ¶
type ActionDocumentationFieldType string
ActionDocumentationFieldType defines known field types
const ( ActionDocumentationFieldTypeBool ActionDocumentationFieldType = "bool" ActionDocumentationFieldTypeDuration ActionDocumentationFieldType = "duration" ActionDocumentationFieldTypeInt64 ActionDocumentationFieldType = "int64" ActionDocumentationFieldTypeString ActionDocumentationFieldType = "string" ActionDocumentationFieldTypeStringSlice ActionDocumentationFieldType = "stringslice" )
Enum of available field types
type Actor ¶
type Actor interface { // Execute will be called after the config was read into the Actor Execute(c *irc.Client, m *irc.Message, r *Rule, evtData *fieldcollection.FieldCollection, attrs *fieldcollection.FieldCollection) (preventCooldown bool, err error) // 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 // 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(TemplateValidatorFunc, *fieldcollection.FieldCollection) error }
Actor defines an interface to implement in the plugin for actors
type ActorCreationFunc ¶
type ActorCreationFunc func() Actor
ActorCreationFunc is a function to return a new instance of the plugins actor
type ActorDocumentationRegistrationFunc ¶
type ActorDocumentationRegistrationFunc func(ActionDocumentation)
ActorDocumentationRegistrationFunc is passed from the bot to the plugins RegisterFunc to register a new actor documentation
type ActorKit ¶ added in v3.16.0
type ActorKit struct{}
ActorKit contains some common validation functions to be used when implementing actors
func (ActorKit) ValidateRequireNonEmpty ¶ added in v3.16.0
func (ActorKit) ValidateRequireNonEmpty(attrs *fieldcollection.FieldCollection, fields ...string) error
ValidateRequireNonEmpty checks whether the fields are gettable (not returning ErrValueNotSet) and does not contain zero value recognized by reflect (to just check whether the field is set but allow zero values use HasAll on the FieldCollection)
func (ActorKit) ValidateRequireValidTemplate ¶ added in v3.16.0
func (ActorKit) ValidateRequireValidTemplate(tplValidator TemplateValidatorFunc, attrs *fieldcollection.FieldCollection, fields ...string) error
ValidateRequireValidTemplate checks whether fields are gettable as strings and do have a template which validates (this does not check for empty strings as an empty template is indeed valid)
func (ActorKit) ValidateRequireValidTemplateIfSet ¶ added in v3.16.0
func (ActorKit) ValidateRequireValidTemplateIfSet(tplValidator TemplateValidatorFunc, attrs *fieldcollection.FieldCollection, fields ...string) error
ValidateRequireValidTemplateIfSet checks whether the field is either not set or a valid template (this does not check for empty strings as an empty template is indeed valid)
type ActorRegistrationFunc ¶
type ActorRegistrationFunc func(name string, acf ActorCreationFunc)
ActorRegistrationFunc is passed from the bot to the plugins RegisterFunc to register a new actor in the bot
type ChannelAnyPermissionCheckFunc ¶ added in v3.2.0
ChannelAnyPermissionCheckFunc is available to check whether the bot has stored scopes / permissions for the given channel. Any of the given scopes need to be available to return true.
type ChannelPermissionCheckFunc ¶ added in v3.2.0
ChannelPermissionCheckFunc is available to check whether the bot has stored scopes / permissions for the given channel. All given scopes need to be available to return true.
type CronRegistrationFunc ¶
CronRegistrationFunc is passed from the bot to the plugins RegisterFunc to register a new cron function in the internal cron scheduler
type DatabaseCopyFunc ¶ added in v3.20.0
DatabaseCopyFunc defines the function type the plugin must implement and register to enable the bot to replicate its database stored content into a new database
type EventHandlerFunc ¶
type EventHandlerFunc func(evt string, eventData *fieldcollection.FieldCollection) error
EventHandlerFunc defines the type of function required to listen for events
type EventHandlerRegisterFunc ¶
type EventHandlerRegisterFunc func(EventHandlerFunc) error
EventHandlerRegisterFunc is passed from the bot to the plugins RegisterFunc to register a new event handler function which is then fed with all events occurring in the bot
type HTTPRouteParamDocumentation ¶
type HTTPRouteParamDocumentation struct { Description string Name string Required bool Type string }
HTTPRouteParamDocumentation documents parameters expected by a HTTP route and to be documented in the API documentation
type HTTPRouteRegistrationArgs ¶
type HTTPRouteRegistrationArgs struct { Accept []string Description string HandlerFunc http.HandlerFunc IsPrefix bool Method string Module string Name string Path string QueryParams []HTTPRouteParamDocumentation RequiresEditorsAuth bool RequiresWriteAuth bool ResponseType HTTPRouteResponseType RouteParams []HTTPRouteParamDocumentation SkipDocumentation bool }
HTTPRouteRegistrationArgs defines the HTTP route to be added in using the HTTPRouteRegistrationFunc
type HTTPRouteRegistrationFunc ¶
type HTTPRouteRegistrationFunc func(HTTPRouteRegistrationArgs) error
HTTPRouteRegistrationFunc is passed from the bot to the plugins RegisterFunc to register a new route in the API router
type HTTPRouteResponseType ¶
type HTTPRouteResponseType uint64
HTTPRouteResponseType pre-defines response types known to the API documentation
const ( HTTPRouteResponseTypeNo200 HTTPRouteResponseType = iota HTTPRouteResponseTypeTextPlain HTTPRouteResponseTypeJSON HTTPRouteResponseTypeMultiple )
Enum of known HTTPRouteResponseType
type LoggerCreationFunc ¶
LoggerCreationFunc is passed from the bot to the plugins RegisterFunc to retrieve a pre-configured logrus.Entry scoped for the given module name
type ModuleConfig ¶ added in v3.18.0
type ModuleConfig map[string]map[string]*fieldcollection.FieldCollection
ModuleConfig represents a mapping of configurations per channel and module
func (ModuleConfig) GetChannelConfig ¶ added in v3.18.0
func (m ModuleConfig) GetChannelConfig(module, channel string) *fieldcollection.FieldCollection
GetChannelConfig reads the channel specific configuration for the given module. This is created by taking an empty FieldCollection, merging in the default configuration and finally overwriting all existing channel configurations.
type ModuleConfigGetterFunc ¶ added in v3.18.0
type ModuleConfigGetterFunc func(module, channel string) *fieldcollection.FieldCollection
ModuleConfigGetterFunc is passed from the bot to the plugins RegisterFunc to fetch module generic or channel specific configuration from the module configuration
type MsgFormatter ¶
type MsgFormatter func(tplString string, m *irc.Message, r *Rule, fields *fieldcollection.FieldCollection) (string, error)
MsgFormatter is passed from the bot to the plugins RegisterFunc to format messages using all registered and available template functions
type MsgModificationFunc ¶
type MsgModificationFunc func(*irc.Message) error
MsgModificationFunc can be used to modify messages between the plugins generating them and the bot sending them to the Twitch servers
type MsgModificationRegistrationFunc ¶
type MsgModificationRegistrationFunc func(linePrefix string, modFn MsgModificationFunc)
MsgModificationRegistrationFunc is passed from the bot to the plugins RegisterFunc to register a new MsgModificationFunc for the given prefix
type RawMessageHandlerFunc ¶
type RawMessageHandlerFunc func(m *irc.Message) error
RawMessageHandlerFunc is the type of function to implement in your plugin in order to process raw-messages from the IRC connection
type RawMessageHandlerRegisterFunc ¶
type RawMessageHandlerRegisterFunc func(RawMessageHandlerFunc) error
RawMessageHandlerRegisterFunc is passed from the bot to the plugins RegisterFunc to register a new RawMessageHandlerFunc
type RegisterFunc ¶
type RegisterFunc func(RegistrationArguments) error
RegisterFunc is the type of function your plugin must expose with the name Register
type RegistrationArguments ¶
type RegistrationArguments struct { // CreateEvent allows to create an event handed out to all modules to handle CreateEvent EventHandlerFunc // FormatMessage is a method to convert templates into strings using internally known variables / configs FormatMessage MsgFormatter // FrontendNotify is a way to send a notification to the frontend FrontendNotify func(string) // GetBaseURL returns the configured BaseURL for the bot GetBaseURL func() string // GetDatabaseConnector returns an active database.Connector to access the backend storage database GetDatabaseConnector func() database.Connector // GetLogger returns a sirupsen log.Entry pre-configured with the module name GetLogger LoggerCreationFunc // GetModuleConfigForChannel returns the module configuration for the given channel if available GetModuleConfigForChannel ModuleConfigGetterFunc // GetTwitchClient retrieves a fully configured Twitch client with initialized cache GetTwitchClient func() *twitch.Client // GetTwitchClientForChannel retrieves a fully configured Twitch client with initialized cache for extended permission channels GetTwitchClientForChannel func(string) (*twitch.Client, error) // HasAnyPermissionForChannel checks whether ANY of the given permissions were granted for the given channel HasAnyPermissionForChannel ChannelAnyPermissionCheckFunc // HasPermissionForChannel checks whether ALL of the given permissions were granted for the given channel HasPermissionForChannel ChannelPermissionCheckFunc // RegisterActor is used to register a new IRC rule-actor implementing the Actor interface RegisterActor ActorRegistrationFunc // RegisterActorDocumentation is used to register an ActorDocumentation for the config editor RegisterActorDocumentation ActorDocumentationRegistrationFunc // RegisterAPIRoute registers a new HTTP handler function including documentation RegisterAPIRoute HTTPRouteRegistrationFunc // RegisterCopyDatabaseFunc registers a DatabaseCopyFunc for the // database migration tool. Modules not registering such a func // will not be copied over when migrating to another database. RegisterCopyDatabaseFunc func(name string, fn DatabaseCopyFunc) // RegisterCron is a method to register cron functions in the global cron instance RegisterCron CronRegistrationFunc // RegisterEventHandler is a method to register a handler function receiving ALL events RegisterEventHandler EventHandlerRegisterFunc // RegisterMessageModFunc is a method to register a handler to modify / react on messages RegisterMessageModFunc MsgModificationRegistrationFunc // RegisterRawMessageHandler is a method to register an handler to receive ALL messages received RegisterRawMessageHandler RawMessageHandlerRegisterFunc // RegisterTemplateFunction can be used to register a new template functions RegisterTemplateFunction TemplateFuncRegister // SendMessage can be used to send a message not triggered by an event SendMessage SendMessageFunc // ValidateToken offers a way to validate a token and determine whether it has permissions on a given module ValidateToken ValidateTokenFunc }
RegistrationArguments is the object your RegisterFunc will receive and can use to interact with the bot instance
type Rule ¶
type Rule struct { UUID string `hash:"-" json:"uuid,omitempty" yaml:"uuid,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` SubscribeFrom *string `json:"subscribe_from,omitempty" yaml:"subscribe_from,omitempty"` Actions []*RuleAction `json:"actions,omitempty" yaml:"actions,omitempty"` Cooldown *time.Duration `json:"cooldown,omitempty" yaml:"cooldown,omitempty"` ChannelCooldown *time.Duration `json:"channel_cooldown,omitempty" yaml:"channel_cooldown,omitempty"` UserCooldown *time.Duration `json:"user_cooldown,omitempty" yaml:"user_cooldown,omitempty"` SkipCooldownFor []string `json:"skip_cooldown_for,omitempty" yaml:"skip_cooldown_for,omitempty"` MatchChannels []string `json:"match_channels,omitempty" yaml:"match_channels,omitempty"` MatchEvent *string `json:"match_event,omitempty" yaml:"match_event,omitempty"` MatchMessage *string `json:"match_message,omitempty" yaml:"match_message,omitempty"` MatchUsers []string `json:"match_users,omitempty" yaml:"match_users,omitempty" ` DisableOnMatchMessages []string `json:"disable_on_match_messages,omitempty" yaml:"disable_on_match_messages,omitempty"` Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty"` DisableOnOffline *bool `json:"disable_on_offline,omitempty" yaml:"disable_on_offline,omitempty"` DisableOnPermit *bool `json:"disable_on_permit,omitempty" yaml:"disable_on_permit,omitempty"` DisableOnTemplate *string `json:"disable_on_template,omitempty" yaml:"disable_on_template,omitempty"` DisableOn []string `json:"disable_on,omitempty" yaml:"disable_on,omitempty"` EnableOn []string `json:"enable_on,omitempty" yaml:"enable_on,omitempty"` // contains filtered or unexported fields }
Rule represents a rule in the bot configuration
func (*Rule) GetMatchMessage ¶
GetMatchMessage returns the cached Regexp if available or compiles the given match string into a Regexp
func (Rule) MatcherID ¶
MatcherID returns the rule UUID or a hash for the rule if no UUID is available
func (*Rule) Matches ¶
func (r *Rule) Matches(m *irc.Message, event *string, timerStore TimerStore, msgFormatter MsgFormatter, twitchClient *twitch.Client, eventData *fieldcollection.FieldCollection) bool
Matches checks whether the Rule should be executed for the given parameters
func (*Rule) SetCooldown ¶
func (r *Rule) SetCooldown(timerStore TimerStore, m *irc.Message, evtData *fieldcollection.FieldCollection)
SetCooldown uses the given TimerStore to set the cooldowns for the Rule after execution
func (*Rule) UpdateFromSubscription ¶
UpdateFromSubscription fetches the remote Rule source if one is defined and updates the rule with its content
func (Rule) Validate ¶
func (r Rule) Validate(tplValidate TemplateValidatorFunc) error
Validate executes some basic checks on the validity of the Rule
type RuleAction ¶
type RuleAction struct { Type string `json:"type" yaml:"type,omitempty"` Attributes *fieldcollection.FieldCollection `json:"attributes" yaml:"attributes,omitempty"` }
RuleAction represents an action to be executed when running a Rule
type SendMessageFunc ¶
type SendMessageFunc func(*irc.Message) error
SendMessageFunc is available through the RegistrationArguments and MUST be used to send messages to the Twitch servers
type TemplateFuncDocumentation ¶ added in v3.17.0
type TemplateFuncDocumentation struct { Name string Description string Syntax string Example *TemplateFuncDocumentationExample Remarks string }
TemplateFuncDocumentation contains a documentation for a template function to be rendered into the documentation site
type TemplateFuncDocumentationExample ¶ added in v3.17.0
type TemplateFuncDocumentationExample struct { MatchMessage string MessageContent string Template string ExpectedOutput string FakedOutput string }
TemplateFuncDocumentationExample contains an example of the function execution to be rendered as an example how to use the template function
type TemplateFuncGetter ¶
type TemplateFuncGetter func(*irc.Message, *Rule, *fieldcollection.FieldCollection) any
TemplateFuncGetter is the type of function to implement in the plugin to create a new template function on request of the bot
func GenericTemplateFunctionGetter ¶
func GenericTemplateFunctionGetter(f any) TemplateFuncGetter
GenericTemplateFunctionGetter wraps a generic template function not requiring access to the irc.Message, Rule or FieldCollection to satisfy the TemplateFuncGetter interface
type TemplateFuncRegister ¶
type TemplateFuncRegister func(name string, fg TemplateFuncGetter, doc ...TemplateFuncDocumentation)
TemplateFuncRegister is passed from the bot to the plugins RegisterFunc to register a new TemplateFuncGetter
type TemplateValidatorFunc ¶
TemplateValidatorFunc is passed from the bot to the plugins RegisterFunc to validate templates considering all registered template functions
type TimerEntry ¶
TimerEntry represents a time for the given type in the TimerStore
type TimerStore ¶
type TimerStore interface { AddCooldown(tt TimerType, limiter, ruleID string, expiry time.Time) error InCooldown(tt TimerType, limiter, ruleID string) (bool, error) AddPermit(channel, username string) error HasPermit(channel, username string) (bool, error) }
TimerStore defines what to expect when interacting with a store
type ValidateTokenFunc ¶
ValidateTokenFunc is passed from the bot to the plugins RegisterFunc to validate tokens and their access permissions