rule

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rule

type Rule struct {
	// Return true if the message should be handled by the handler, false otherwise.
	Filter func(msg message.Message) bool
	Next   *Rule
	// Only useful when Next is not nil.
	Operator RuleOp
}

Describes a filter rule, you can create your own rule by implementing this.

func Always added in v1.1.1

func Always() *Rule

Always always returns true

func Command

func Command(prefixList ...string) *Rule

Command creates a filter rule that matches if the raw message is a command and is in the prefixList.

func FullMatch

func FullMatch(strs ...string) *Rule

FullMatch creates a filter rule that matches if the raw message is the same with one of the strings.

func Keyword

func Keyword(forceStart bool, keywords ...string) *Rule

Keyword creates a filter rule that matches if the raw message contains one of the keywords.

If forceStart is true, the keyword must be at the start of the message.

func Never added in v1.1.1

func Never() *Rule

Never never returns true

func Notice

func Notice(typeList ...string) *Rule

Notice filters messages with specified notice types.

Combines it with `ToMe` to filter notice messages directed to the bot.

func OfType

func OfType(typeName, adapterName string) *Rule

OfType filters messages that has the specified type for specified adapter

You must be sure the message has at least one segment

func RegEx

func RegEx(pluginName string, exprs ...string) *Rule

RegEx creates a filter rule that matches if the raw message does match one of the RegEx expressions.

If you wrote a wrong RegEx expression, an error message with plugin name will be printed.

func ToMe

func ToMe() *Rule

ToMe filters messages that are directed to the bot.(@bot or private message, should be identified by adapters)

If your adapter don't, what can i say?

func (*Rule) SubFilter

func (ru *Rule) SubFilter(msg message.Message) (result bool)

type RuleOp

type RuleOp bool

Describes the way the rules are combined.

const (
	Or  RuleOp = false
	And RuleOp = true
)

type Rules

type Rules struct {
	FilterHead *Rule
	FilterTail *Rule
	Next       *Rules
	Last       *Rules
	// Only useful when Next is not nil.
	Operator RuleOp
}

Describes a list of rules, all the Filter results are "OR"ed together, all the Rules results are "AND"ed together.

func NewRules

func NewRules(rule *Rule) *Rules

func (*Rules) And

func (ru *Rules) And(rule *Rule) *Rules

func (*Rules) AndRules

func (ru *Rules) AndRules(rules *Rules) *Rules

func (*Rules) Filter

func (ru *Rules) Filter(msg message.Message) (result bool)

func (*Rules) Or

func (ru *Rules) Or(rule *Rule) *Rules

func (*Rules) OrRules

func (ru *Rules) OrRules(rules *Rules) *Rules

Jump to

Keyboard shortcuts

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