bottom

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 6 Imported by: 6

README

bottom

codecov GoDoc Go Report Card

Package bottom is an IRC Bot mini-framework (for want of a better word)

It sets up different message handlers for different messages, has the concept of middlewares, and exposes everything underneath for when you need just a little more control.

Everything is pretty intuitive, but the examples directory will get you where you need to go.

It also makes a series of assumptions, such as SASL, and so may not be right for lots of projects.

Types

type Bottom

type Bottom struct { ... }

Bottom is the transport logic for an IRC Bot

It handles things like routing messages and error handling

func New

func New(user, password, server string, verifyTLS bool) (b Bottom, err error)

New accepts some connection parameters, initialises an IRC client, and sets up an empty Middlewares list, and a default ErrorFunc

It will error for malformed server addresses. The form it expects is:

[irc|ircs]://hostname:port

So:

1. `irc://irc.example.com:6667`
2. `ircs://irc.example.com:6697`

Are valid, whereas

1. `irc.example.com`

Is not.

type Context

type Context map[string]interface{ ... }

Context holds key/value pairs for the current irc event like sender, or message

Because this is a map of strings to interface, you will need to typecast whatever comes back

type Middleware

type Middleware interface { ... }

Middleware provides a way of handling different events in different ways, such as gating certain commands

type Middlewares

type Middlewares []Middleware

Middlewares holds a set of Middleware implementations, providing a set of ways to manipulate insertions

func NewMiddlewares

func NewMiddlewares() *Middlewares

NewMiddlewares returns an empty set of Middlewares

func (*Middlewares) Push

func (m *Middlewares) Push(nm Middleware)

Push puts a new Middleware implementation to the back of Middlewares

func (*Middlewares) Unshift

func (m *Middlewares) Unshift(nm Middleware)

Unshift puts a new Middleware implementation to the front of Middlewares

type Router

type Router struct { ... }

Router is a Middleware implementation, containing routing logic for different Events.

These events are pattern matched to a specific RouterFunc

func NewRouter

func NewRouter() *Router

NewRouter returns a new, empty Router, with no routes setup

func (*Router) AddRoute

func (r *Router) AddRoute(pattern string, f RouterFunc) (err error)

AddRoute configures a RouterFunc to run when a certain route pattern matches.

If many patterns match, the first pattern wins If the pattern contains groups, then these are passed as the second arg to RouterFunc

func (*Router) Do

func (r *Router) Do(ctx Context, e girc.Event) (err error)

Do implements the Middleware interface.

It matches message contents to route patterns, as passed to AddRoute, and calls the associated RouterFunc, passing any regexp groups as it goes.

type RouterFunc

type RouterFunc func(sender, channel string, groups []string) error

RouterFunc is used in routing events

Functions should expect the following information:

1. sender - the nick of the author of the message
2. channel - the channel the message was sent in (if sender == channel, then assume a private message)
3. groups - any regexp groups extracted from the message. groups[0] is *always* the full message

Sub Packages


Readme created from Go doc with goreadme

Documentation

Overview

Package bottom is an IRC Bot mini-framework (for want of a better word)

It sets up different message handlers for different messages, has the concept of middlewares, and exposes everything underneath for when you need just a little more control.

Everything is pretty intuitive, but the examples directory will get you where you need to go.

It also makes a series of assumptions, such as SASL, and so may not be right for lots of projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bottom

type Bottom struct {
	Middlewares *Middlewares
	Client      *girc.Client
	ErrorFunc   func(Context, error)

	// The following are extra tunables which are not
	// passed in via args, partially for backwards
	// compatability reasons, but part because the defaults
	// are sane enough- setting them is not compulsary
	AutoAcceptInvites bool
	// contains filtered or unexported fields
}

Bottom is the transport logic for an IRC Bot

It handles things like routing messages and error handling

func New

func New(user, password, server string, verifyTLS bool) (b Bottom, err error)

New accepts some connection parameters, initialises an IRC client, and sets up an empty Middlewares list, and a default ErrorFunc

It will error for malformed server addresses. The form it expects is:

[irc|ircs]://hostname:port

So:

  1. `irc://irc.example.com:6667`
  2. `ircs://irc.example.com:6697`

Are valid, whereas

  1. `irc.example.com`

Is not.

type Context

type Context map[string]interface{}

Context holds key/value pairs for the current irc event like `sender`, or `message`

Because this is a map of strings to interface, you will need to typecast whatever comes back

type Middleware

type Middleware interface {
	Do(Context, girc.Event) error
}

Middleware provides a way of handling different events in different ways, such as gating certain commands

type Middlewares

type Middlewares []Middleware

Middlewares holds a set of Middleware implementations, providing a set of ways to manipulate insertions

func NewMiddlewares

func NewMiddlewares() *Middlewares

NewMiddlewares returns an empty set of Middlewares

func (*Middlewares) Push

func (m *Middlewares) Push(nm Middleware)

Push puts a new Middleware implementation to the back of Middlewares

func (*Middlewares) Unshift

func (m *Middlewares) Unshift(nm Middleware)

Unshift puts a new Middleware implementation to the front of Middlewares

type Router

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

Router is a Middleware implementation, containing routing logic for different Events.

These events are pattern matched to a specific RouterFunc

func NewRouter

func NewRouter() *Router

NewRouter returns a new, empty Router, with no routes setup

func (*Router) AddRoute

func (r *Router) AddRoute(pattern string, f RouterFunc) (err error)

AddRoute configures a RouterFunc to run when a certain route pattern matches.

If many patterns match, the first pattern wins If the pattern contains groups, then these are passed as the second arg to RouterFunc

func (*Router) Do

func (r *Router) Do(ctx Context, e girc.Event) (err error)

Do implements the Middleware interface.

It matches message contents to route patterns, as passed to AddRoute, and calls the associated RouterFunc, passing any regexp groups as it goes.

type RouterFunc

type RouterFunc func(sender, channel string, groups []string) error

RouterFunc is used in routing events

Functions should expect the following information:

  1. sender - the nick of the author of the message
  2. channel - the channel the message was sent in (if sender == channel, then assume a private message)
  3. groups - any regexp groups extracted from the message. groups[0] is *always* the full message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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