plugins

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: Apache-2.0 Imports: 14 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")
)

Functions

func DeriveChannel added in v0.18.0

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

func DeriveUser added in v0.18.0

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

Types

type ActionDocumentation added in v1.0.0

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

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

type ActionDocumentationField added in v1.0.0

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 added in v1.0.0

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(FieldCollection) error
}

type ActorCreationFunc

type ActorCreationFunc func() Actor

type ActorDocumentationRegistrationFunc added in v1.0.0

type ActorDocumentationRegistrationFunc func(ActionDocumentation)

type ActorRegistrationFunc

type ActorRegistrationFunc func(name string, acf ActorCreationFunc)

type CronRegistrationFunc added in v0.17.0

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

type FieldCollection added in v0.18.0

type FieldCollection map[string]interface{}

func (FieldCollection) Bool added in v0.18.0

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

func (FieldCollection) CanBool added in v1.0.0

func (f FieldCollection) CanBool(name string) bool

func (FieldCollection) CanDuration added in v1.0.0

func (f FieldCollection) CanDuration(name string) bool

func (FieldCollection) CanInt64 added in v1.0.0

func (f FieldCollection) CanInt64(name string) bool

func (FieldCollection) CanString added in v1.0.0

func (f FieldCollection) CanString(name string) bool

func (FieldCollection) Duration added in v0.18.0

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

func (FieldCollection) Expect added in v0.18.0

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

func (FieldCollection) HasAll added in v1.0.0

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

func (FieldCollection) Int64 added in v0.18.0

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

func (FieldCollection) MustBool added in v0.18.0

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

func (FieldCollection) MustDuration added in v0.18.0

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

func (FieldCollection) MustInt64 added in v0.18.0

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

func (FieldCollection) MustString added in v0.18.0

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

func (FieldCollection) String added in v0.18.0

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

func (FieldCollection) StringSlice added in v0.18.0

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

type HTTPRouteParamDocumentation added in v0.17.0

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

type HTTPRouteRegistrationArgs added in v0.17.0

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 added in v0.17.0

type HTTPRouteRegistrationFunc func(HTTPRouteRegistrationArgs) error

type HTTPRouteResponseType added in v0.17.0

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 RawMessageHandlerFunc added in v0.18.0

type RawMessageHandlerFunc func(m *irc.Message) error

type RawMessageHandlerRegisterFunc added in v0.18.0

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 {
	// 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
	// GetStorageManager returns an interface to access the modules storage
	GetStorageManager func() StorageManager
	// GetTwitchClient retrieves a fully configured Twitch client with initialized cache
	GetTwitchClient func() *twitch.Client
	// 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
	// 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
}

type Rule

type Rule struct {
	UUID        string `hash:"-" json:"uuid,omitempty" yaml:"uuid,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,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)

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 added in v1.2.0

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

type StorageMarshaller added in v1.2.0

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

type StorageUnmarshaller added in v1.2.0

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 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)
	InCooldown(tt TimerType, limiter, ruleID string) bool
	AddPermit(channel, username string)
	HasPermit(channel, username string) bool
}

type TimerType

type TimerType uint8
const (
	TimerTypePermit TimerType = iota
	TimerTypeCooldown
)

Jump to

Keyboard shortcuts

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