rules

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action describes how the message is handled after matching a RuleSet.

const (
	// Accept accepts the message.
	Accept Action = "accept"
	// Reject drops the message.
	Reject Action = "reject"
)

type ErrExtraParam

type ErrExtraParam struct {
	ExtraParams []string
}

ErrExtraParam is returned when a Match contains extra parameters.

func (ErrExtraParam) Error

func (c ErrExtraParam) Error() string

type ErrMatchSetInvalid

type ErrMatchSetInvalid struct {
	Errors []struct {
		Index int
		Error error
	}
}

ErrMatchSetInvalid is returned when a MatchSet contains errors.

func (ErrMatchSetInvalid) Error

func (c ErrMatchSetInvalid) Error() string

type ErrMissingParam

type ErrMissingParam struct {
	Tag string
}

ErrMissingParam is returned when a Match lacks a paramater.

func (ErrMissingParam) Error

func (c ErrMissingParam) Error() string

type Match

type Match struct {
	// Match mode
	// See Also: Mode
	Mode Mode `yaml:"mode"`

	// Match options
	Regex bool `yaml:"regex,omitempty"`

	// Match parameters
	// Only filled in as required by the Mode specified.
	// See Also: Mode
	ChannelName string `yaml:"channel_name,omitempty"`
	UserName    string `yaml:"user_name,omitempty"`
	UserID      uint   `yaml:"user_id,omitempty"`
	IsAdmin     *bool  `yaml:"is_admin,omitempty"`

	MessageTitle    string `yaml:"message_title,omitempty"`
	MessageText     string `yaml:"message_text,omitempty"`
	MessageExtra    string `yaml:"message_extra,omitempty"`
	MessagePriority *int   `yaml:"priority,omitempty"`
}

Match describes a Match.

func (Match) Check

func (c Match) Check() error

Check checks a match for syntax errors. Possible errors include: extra parameters, missing parameter.

func (Match) Match

func (c Match) Match(msg model.Message) (matched bool)

Match matches a message against a Match.

type MatchSet

type MatchSet []Match

MatchSet is a set of Matches. MatchSet matches message by validating every Match and only success when all Match is satisfied.

func (MatchSet) Check

func (c MatchSet) Check() error

Check checks a MatchSet for syntax errors.

func (MatchSet) Match

func (c MatchSet) Match(msg model.Message) bool

Match matches a Matchset with a message.

type Mode

type Mode string

Mode describes a Match matches which aspect of the message.

const (
	// ModeAny matches all messages.
	// No parameters are required.
	ModeAny Mode = "any"

	// ModeChannelName matches the channel name the message is sent through.
	// Use parameter channel_name to specity the channel name to match.
	// Use parameter regex: true to enable regex matching.
	ModeChannelName Mode = "channel_name"
	// ModeUserName matches the user name of the message (matches the sender on the recipient side and matches the recipient on the sender side).
	// Use parameter user_name to specify the user name to match.
	// Use parameter regex: true to enable regex matching.
	ModeUserName Mode = "user_name"
	// ModeUserID matches the user ID of the message (matches the sender on the recipient side and matches the recipient on the sender side).
	// Use parameter user_id to specify the user ID to match.
	// Use parameter regex: true to enable regex matching.
	ModeUserID Mode = "user_id"
	// ModeIsAdmin matches whether the user is an admin (matches the sender on the recipient side and matches the recipient on the sender side).
	// Use parameter is_admin to specity whether to match admins or non-admins.
	ModeIsAdmin Mode = "is_admin"

	// ModeMessageTitle matches the message title.
	// Use parameter message_title to specify the title to match.
	// Use parameter regex: true to enable regex matching.
	ModeMessageTitle Mode = "message_title"
	// ModeMessageText matches the message text.
	// Use parameter message_text to specity the text to match.
	// Use parameter regex: true to enable regex matching.
	ModeMessageText Mode = "message_text"
	// ModeMessageExtra matches whether the message possesses an extra.
	// Use parameter message_extra to specity the key of the extra to match.
	// Use parameter regex: true to enable regex matching.
	ModeMessageExtra Mode = "message_extra"

	// ModePriorityLt matches messages with priority less then a specified value.
	// Use parameter priority to specity the priority threshold.
	ModePriorityLt Mode = "message_priority_lt"
	// ModePriorityGt matches messages with priority greater then a specified value.
	// Use parameter priority to specity the priority threshold.
	ModePriorityGt Mode = "message_priority_gt"
	// ModePriority matches messages with priority at a specified value.
	// Use parameter priority to specity the priority.
	ModePriority Mode = "message_priority"
)

type Rule

type Rule struct {
	Match  MatchSet `yaml:"match"`
	Action Action   `yaml:"action"`
}

Rule is a message rule that performs an Action when a MatchSet is matched.

type RuleChain

type RuleChain []Rule

RuleChain is a set of rules that are applied in chain.

func (RuleChain) Check

func (c RuleChain) Check() error

Check checks a RuleChain for errors.

func (RuleChain) Match

func (c RuleChain) Match(msg model.Message, defaultAction Action) Action

Match matches a message against a RuleChain. defaultAction is returned when non of the Rule matches.

type RuleChainError

type RuleChainError struct {
	Errors []struct {
		Index int
		Error error
	}
}

RuleChainError is the errors in a rulechain.

func (RuleChainError) Error

func (c RuleChainError) Error() string

type RuleItemError

type RuleItemError struct {
	Index int
	Err   error
}

RuleItemError is returned when a Rule in a RuleChain contains errors.

func (RuleItemError) Error

func (c RuleItemError) Error() string

Jump to

Keyboard shortcuts

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