bot

package
v0.0.0-...-4a512e1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: ISC Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHSName   = errors.New("invalid homeserver name")
	ErrHSNameTruncated = errors.New("homeserver name appears truncated")
	ErrBadRealname     = errors.New("realname does not match expected pattern")
)
View Source
var ErrInvalidActionConfig = errors.New("invalid action config")

ErrInvalidActionConfig is returned when an action config is invalid

View Source
var ErrOnlyMatchScannedUser = errors.New("acts on scanned users only")

ErrOnlyMatchScannedUser is returned from any action that will ignore non-scanned users

Functions

This section is empty.

Types

type Action

type Action interface {
	Execute(args *ActionArgs) ([]string, error)
	Enabled() bool
	Toggle()
	fmt.Stringer
}

Action is any action that can be taken on a scanned user.

func GetAction

func GetAction(config ActionConfig) (Action, error)

GetAction returns an Action for the given config, or an error

type ActionArgs

type ActionArgs struct {
	Nick           string
	Ident          string
	Host           string
	Account        string
	IP             string
	RealName       string
	HomeServer     string
	UserWasScanned bool

	Log func(message string)
}

ActionArgs contains all the info passed to action implementations

type ActionConfig

type ActionConfig struct {
	Type         string `toml:"type"`
	Message      string `toml:"message"`
	Duration     int    `toml:"duration"`
	IgnoreSASLed bool   `toml:"ignore_sasl"`
	Enabled_     bool   `toml:"enabled"` //nolint:revive // Its a backing value, and has to be exported
}

ActionConfig represents a config for an action

func (*ActionConfig) Enabled

func (a *ActionConfig) Enabled() bool

Enabled returns whether or not this action is enabled

func (ActionConfig) String

func (a ActionConfig) String() string

func (*ActionConfig) Toggle

func (a *ActionConfig) Toggle()

Toggle toggles the enabled state on this Action

type Bot

type Bot struct {
	ShouldRestart bool
	// contains filtered or unexported fields
}

func New

func New(config *Config, log *logging.Logger) (*Bot, error)

New creates a new bot instance.

func (*Bot) Run

func (b *Bot) Run(ctx context.Context)

Run starts the bot and connects it to IRC

func (*Bot) Stop

func (b *Bot) Stop(message string)

Stop stops the bot.

type Config

type Config struct {
	Connection connection.Config `toml:"connection"`

	Nick               string     `toml:"nick"`
	Ident              string     `toml:"ident"`
	Realname           string     `toml:"realname"`
	ServerPassword     string     `toml:"server_password"`
	ScanTimeoutHours   int        `toml:"scan_timeout_hours"`
	BadFlows           [][]string `toml:"bad_flows"`
	LogChannel         string     `toml:"log_channel"`
	VerboseLogChannel  string     `toml:"verbose_log_channel"`
	VerboseRedirectREs []string   `toml:"verbose_redirect"`

	OperKeyPath   string `toml:"oper_key_path"`
	OperKeyPasswd string `toml:"oper_key_passwd"`
	OperName      string `toml:"oper_name"`

	NSUser   string `toml:"ns_user"`
	NSPasswd string `toml:"ns_passwd"`

	Actions    map[string]ActionConfig `toml:"actions"`
	ScanRanges []string                `toml:"scan_ranges"`

	Version string `toml:"-"`
}

type KLineAction

type KLineAction struct {
	ActionConfig
}

KLineAction klines a given user@host

func (KLineAction) Execute

func (k KLineAction) Execute(args *ActionArgs) ([]string, error)

Execute implements the Action interface

type ScanResult

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

func (*ScanResult) IRCString

func (s *ScanResult) IRCString() string

IRCString is like String() but may include IRC formatting

func (*ScanResult) String

func (s *ScanResult) String() string

type WarnAction

type WarnAction struct {
	ActionConfig
	// contains filtered or unexported fields
}

WarnAction works by using a go format template to set what information is sent to the bots log channel

func (*WarnAction) Execute

func (w *WarnAction) Execute(args *ActionArgs) ([]string, error)

Execute Implements Action

type XLineAction

type XLineAction struct {
	ActionConfig
}

XLineAction X-Lines the homeserver on which a user sits

func (XLineAction) Execute

func (x XLineAction) Execute(args *ActionArgs) ([]string, error)

Execute implements the Action interface

Directories

Path Synopsis
internal
set

Jump to

Keyboard shortcuts

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