plugins

package
v3.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueNotSet   = errors.New("specified value not found")
	ErrValueMismatch = errors.New("specified value has different format")
)
View Source
var ErrSkipSendingMessage = errors.New("skip sending message")
View Source
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) string

func DeriveUser

func DeriveUser(m *irc.Message, evtData *FieldCollection) string

Types

type ActionDocumentation

type ActionDocumentation struct {
	Description string `json:"description"`
	Name        string `json:"name"`
	Type        string `json:"type"`

	Fields []ActionDocumentationField `json:"fields"`
}

type ActionDocumentationField

type ActionDocumentationField struct {
	Default         string                       `json:"default"`
	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"`
}

type ActionDocumentationFieldType

type ActionDocumentationFieldType string
const (
	ActionDocumentationFieldTypeBool        ActionDocumentationFieldType = "bool"
	ActionDocumentationFieldTypeDuration    ActionDocumentationFieldType = "duration"
	ActionDocumentationFieldTypeInt64       ActionDocumentationFieldType = "int64"
	ActionDocumentationFieldTypeString      ActionDocumentationFieldType = "string"
	ActionDocumentationFieldTypeStringSlice ActionDocumentationFieldType = "stringslice"
)

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, attrs *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) error
}

type ActorCreationFunc

type ActorCreationFunc func() Actor

type ActorDocumentationRegistrationFunc

type ActorDocumentationRegistrationFunc func(ActionDocumentation)

type ActorRegistrationFunc

type ActorRegistrationFunc func(name string, acf ActorCreationFunc)

type ChannelAnyPermissionCheckFunc added in v3.2.0

type ChannelAnyPermissionCheckFunc func(channel string, scopes ...string) (bool, error)

type ChannelPermissionCheckFunc added in v3.2.0

type ChannelPermissionCheckFunc func(channel string, scopes ...string) (bool, error)

type CronRegistrationFunc

type CronRegistrationFunc func(spec string, cmd func()) (cron.EntryID, error)

type EventHandlerFunc

type EventHandlerFunc func(evt string, eventData *FieldCollection) error

type EventHandlerRegisterFunc

type EventHandlerRegisterFunc func(EventHandlerFunc) error

type FieldCollection

type FieldCollection struct {
	// contains filtered or unexported fields
}

func FieldCollectionFromData

func FieldCollectionFromData(data map[string]any) *FieldCollection

FieldCollectionFromData is a wrapper around NewFieldCollection and SetFromData

func NewFieldCollection

func NewFieldCollection() *FieldCollection

NewFieldCollection creates a new FieldCollection with empty data store

func (*FieldCollection) Any added in v3.8.0

func (f *FieldCollection) Any(name string) (any, error)

Any tries to read key name as any-type (interface)

func (*FieldCollection) Bool

func (f *FieldCollection) Bool(name string) (bool, error)

Bool tries to read key name as bool

func (*FieldCollection) CanBool

func (f *FieldCollection) CanBool(name string) bool

CanBool tries to read key name as bool and checks whether error is nil

func (*FieldCollection) CanDuration

func (f *FieldCollection) CanDuration(name string) bool

CanDuration tries to read key name as time.Duration and checks whether error is nil

func (*FieldCollection) CanInt64

func (f *FieldCollection) CanInt64(name string) bool

CanInt64 tries to read key name as int64 and checks whether error is nil

func (*FieldCollection) CanString

func (f *FieldCollection) CanString(name string) bool

CanString tries to read key name as string and checks whether error is nil

func (*FieldCollection) Clone

func (f *FieldCollection) Clone() *FieldCollection

Clone is a wrapper around n.SetFromData(o.Data())

func (*FieldCollection) Data

func (f *FieldCollection) Data() map[string]any

Data creates a map-copy of the data stored inside the FieldCollection

func (*FieldCollection) Duration

func (f *FieldCollection) Duration(name string) (time.Duration, error)

Duration tries to read key name as time.Duration

func (*FieldCollection) Expect

func (f *FieldCollection) Expect(keys ...string) error

Expect takes a list of keys and returns an error with all non-found names

func (*FieldCollection) HasAll

func (f *FieldCollection) HasAll(keys ...string) bool

HasAll takes a list of keys and returns whether all of them exist inside the FieldCollection

func (*FieldCollection) Int64

func (f *FieldCollection) Int64(name string) (int64, error)

Int64 tries to read key name as int64

func (*FieldCollection) MarshalJSON

func (f *FieldCollection) MarshalJSON() ([]byte, error)

func (*FieldCollection) MarshalYAML

func (f *FieldCollection) MarshalYAML() (any, error)

func (*FieldCollection) MustBool

func (f *FieldCollection) MustBool(name string, defVal *bool) bool

MustBool is a wrapper around Bool and panics if an error was returned

func (*FieldCollection) MustDuration

func (f *FieldCollection) MustDuration(name string, defVal *time.Duration) time.Duration

MustDuration is a wrapper around Duration and panics if an error was returned

func (*FieldCollection) MustInt64

func (f *FieldCollection) MustInt64(name string, defVal *int64) int64

MustInt64 is a wrapper around Int64 and panics if an error was returned

func (*FieldCollection) MustString

func (f *FieldCollection) MustString(name string, defVal *string) string

MustString is a wrapper around String and panics if an error was returned

func (*FieldCollection) MustStringSlice added in v3.8.0

func (f *FieldCollection) MustStringSlice(name string) []string

MustStringSlice is a wrapper around StringSlice and returns nil in case name is not set

func (*FieldCollection) Set

func (f *FieldCollection) Set(key string, value any)

Set sets a single key to specified value

func (*FieldCollection) SetFromData

func (f *FieldCollection) SetFromData(data map[string]any)

SetFromData takes a map of data and copies all data into the FieldCollection

func (*FieldCollection) String

func (f *FieldCollection) String(name string) (string, error)

String tries to read key name as string

func (*FieldCollection) StringSlice

func (f *FieldCollection) StringSlice(name string) ([]string, error)

StringSlice tries to read key name as []string

func (*FieldCollection) UnmarshalJSON

func (f *FieldCollection) UnmarshalJSON(raw []byte) error

func (*FieldCollection) UnmarshalYAML

func (f *FieldCollection) UnmarshalYAML(unmarshal func(any) error) error

type HTTPRouteParamDocumentation

type HTTPRouteParamDocumentation struct {
	Description string
	Name        string
	Required    bool
	Type        string
}

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
}

type HTTPRouteRegistrationFunc

type HTTPRouteRegistrationFunc func(HTTPRouteRegistrationArgs) error

type HTTPRouteResponseType

type HTTPRouteResponseType uint64
const (
	HTTPRouteResponseTypeNo200 HTTPRouteResponseType = iota
	HTTPRouteResponseTypeTextPlain
	HTTPRouteResponseTypeJSON
	HTTPRouteResponseTypeMultiple
)

type LoggerCreationFunc

type LoggerCreationFunc func(moduleName string) *log.Entry

type MsgFormatter

type MsgFormatter func(tplString string, m *irc.Message, r *Rule, fields *FieldCollection) (string, error)

type MsgModificationFunc

type MsgModificationFunc func(*irc.Message) error

type MsgModificationRegistrationFunc

type MsgModificationRegistrationFunc func(linePrefix string, modFn MsgModificationFunc)

type RawMessageHandlerFunc

type RawMessageHandlerFunc func(m *irc.Message) error

type RawMessageHandlerRegisterFunc

type RawMessageHandlerRegisterFunc func(RawMessageHandlerFunc) error

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
	// 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
	// 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
	// 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
}

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
}

func (*Rule) GetMatchMessage

func (r *Rule) GetMatchMessage() *regexp.Regexp

func (Rule) MatcherID

func (r Rule) MatcherID() string

func (*Rule) Matches

func (r *Rule) Matches(m *irc.Message, event *string, timerStore TimerStore, msgFormatter MsgFormatter, twitchClient *twitch.Client, eventData *FieldCollection) bool

func (*Rule) SetCooldown

func (r *Rule) SetCooldown(timerStore TimerStore, m *irc.Message, evtData *FieldCollection)

func (*Rule) UpdateFromSubscription

func (r *Rule) UpdateFromSubscription() (bool, error)

func (Rule) Validate

func (r Rule) Validate(tplValidate TemplateValidatorFunc) error

type RuleAction

type RuleAction struct {
	Type       string           `json:"type" yaml:"type,omitempty"`
	Attributes *FieldCollection `json:"attributes" yaml:"attributes,omitempty"`
}

type SendMessageFunc

type SendMessageFunc func(*irc.Message) error

type StorageManager

type StorageManager interface {
	DeleteModuleStore(moduleUUID string) error
	GetModuleStore(moduleUUID string, storedObject StorageUnmarshaller) error
	SetModuleStore(moduleUUID string, storedObject StorageMarshaller) error
}

type StorageMarshaller

type StorageMarshaller interface {
	MarshalStoredObject() ([]byte, error)
}

type StorageUnmarshaller

type StorageUnmarshaller interface {
	UnmarshalStoredObject([]byte) error
}

type TemplateFuncGetter

type TemplateFuncGetter func(*irc.Message, *Rule, *FieldCollection) interface{}

func GenericTemplateFunctionGetter

func GenericTemplateFunctionGetter(f interface{}) TemplateFuncGetter

type TemplateFuncRegister

type TemplateFuncRegister func(name string, fg TemplateFuncGetter)

type TemplateValidatorFunc

type TemplateValidatorFunc func(raw string) error

type TimerEntry

type TimerEntry struct {
	Kind TimerType `json:"kind"`
	Time time.Time `json:"time"`
}

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)
}

type TimerType

type TimerType uint8
const (
	TimerTypePermit TimerType = iota
	TimerTypeCooldown
)

type ValidateTokenFunc

type ValidateTokenFunc func(token string, modules ...string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL