filter

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtErrDefault

func FmtErrDefault(f Filter) string

FmtErrDefault is the default format function to convert failing Filter(s) into an error string

Types

type Error

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

Error is an error that has a failing Filter attached

func (*Error) Error

func (e *Error) Error() string

func (*Error) Filter

func (e *Error) Filter() Filter

Filter returns the violated filter

type Filter

type Filter int

Filter represents a condition that prevents a `Command` or `Event` from firing. Only use the given const filters which range from 2^0 to 2^4.

const (
	// MsgFromSelf ignores handling of messages from the bot itself
	MsgFromSelf Filter = 1 << iota
	// MsgFromBot ignores handling of messages from all bots. Encapsulates MsgFromSelf.
	MsgFromBot
	// MsgFromWebhook ignores handling of messages from webhooks
	MsgFromWebhook
	// MsgNoContent ignores handling if messages without a text body. (e.g. messages with only attachments)
	MsgNoContent
	// MsgIsPrivate ignores handling if the message is sent in a DM
	MsgIsPrivate
	// MsgIsGuildText ignores handling if the message is sent from a guild text channel
	MsgIsGuildText
)

func New

func New(filters ...Filter) Filter

New generates a Filter bitset given filters and performing a bitwise "or" on all of them

func (Filter) AsError

func (f Filter) AsError() error

AsError returns the filter as an error

func (Filter) Contains

func (f Filter) Contains(filter Filter) bool

Contains returns true if the given filter is part of the current filter

func (Filter) Validate

func (f Filter) Validate(ctx context.Context) (bool, Filter)

Validate inspects context and determines if it should be processed or not.

returns true if allowed with a zero value Filter, or false with all failing Filters combined with a bitwise `or`.

if ctx.Msg or ctx.Ses is nil, will return false with a zero value Filter.

Jump to

Keyboard shortcuts

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