seabird

package module
v0.0.0-...-b28e5fd Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: MIT Imports: 16 Imported by: 44

README

Seabird

Build Status

Requirements

  • go >= 1.12
  • gcc

Documentation

We've got some docs here.

This documentation contains pages on configuration, plugin development, and other goodies.

Plugins

The default set of plugins can be found here. While they may not be useful to everyone directly, at the very least they are a good repository of examples.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxCurrentNick

func CtxCurrentNick(ctx context.Context) string

func CtxLogger

func CtxLogger(ctx context.Context, name string) *logrus.Entry

func CtxRequestID

func CtxRequestID(ctx context.Context) uuid.UUID

func RegisterPlugin

func RegisterPlugin(name string, factory PluginFactory)

RegisterPlugin registers a PluginFactory for a given name. It will panic if multiple plugins are registered with the same name.

Types

type BasicMux

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

BasicMux is a simple IRC event multiplexer. It matches the command against registered Handlers and calls the correct set.

Handlers will be processed in the order in which they were added. Registering a handler with a "*" command will cause it to receive all events. Note that even though "*" will match all commands, glob matching is not used.

func NewBasicMux

func NewBasicMux() *BasicMux

NewBasicMux will create an initialized BasicMux with no handlers.

func (*BasicMux) Event

func (mux *BasicMux) Event(c string, h HandlerFunc)

Event will register a Handler.

func (*BasicMux) HandleEvent

func (mux *BasicMux) HandleEvent(r *Request)

HandleEvent allows us to be a Handler so we can nest Handlers.

The BasicMux simply dispatches all the Handler commands as needed.

type Bot

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

A Bot is our wrapper around the irc.Client. It could be used for a general client, but the provided convenience functions are designed around using this package to write a bot.

func CtxBot

func CtxBot(ctx context.Context) *Bot

func NewBot

func NewBot(confReader io.Reader) (*Bot, error)

NewBot will return a new Bot given an io.Reader pointing to a config file.

func (*Bot) BasicMux

func (b *Bot) BasicMux() *BasicMux

func (*Bot) CommandMux

func (b *Bot) CommandMux() *CommandMux

func (*Bot) Config

func (b *Bot) Config(name string, c interface{}) error

Config will decode the config section for the given name into the given interface{}.

func (*Bot) ConnectAndRun

func (b *Bot) ConnectAndRun() error

ConnectAndRun is a convenience function which will pull the connection information out of the config and connect, then call Run.

func (*Bot) Context

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

func (*Bot) EnsurePlugin

func (b *Bot) EnsurePlugin(name string) error

func (*Bot) MentionMux

func (b *Bot) MentionMux() *MentionMux

func (*Bot) Run

func (b *Bot) Run(c io.ReadWriteCloser) error

Run starts the bot and loops until it dies. It accepts a ReadWriter. If you wish to use the connection feature from the config, use ConnectAndRun.

func (*Bot) SetValue

func (b *Bot) SetValue(key interface{}, value interface{})

func (*Bot) Write

func (b *Bot) Write(line string)

Write will write an raw IRC message to the stream.

func (*Bot) WriteMessage

func (b *Bot) WriteMessage(m *irc.Message)

Send is a simple function to send an IRC event.

func (*Bot) Writef

func (b *Bot) Writef(format string, args ...interface{})

Writef is a convenience method around fmt.Sprintf and Bot.Write.

type CommandMux

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

The CommandMux is given a prefix string and matches all PRIVMSG events which start with it. The first word after the string is moved into the Event.Command.

func NewCommandMux

func NewCommandMux(prefix string) *CommandMux

NewCommandMux will create an initialized BasicMux with no handlers.

func (*CommandMux) Channel

func (m *CommandMux) Channel(c string, h HandlerFunc, help *HelpInfo)

Channel will register a handler as a public command.

func (*CommandMux) Event

func (m *CommandMux) Event(c string, h HandlerFunc, help *HelpInfo)

Event will register a Handler as both a private and public command.

func (*CommandMux) HandleEvent

func (m *CommandMux) HandleEvent(r *Request)

HandleEvent strips off the prefix, pulls the command out and runs HandleEvent on the internal BasicMux.

func (*CommandMux) Private

func (m *CommandMux) Private(c string, h HandlerFunc, help *HelpInfo)

Private will register a handler as a private command.

type Handler

type Handler interface {
	// HandleEvent should read the data, formulate a response action (if needed)
	// and then return. Returning signals that the Handler is done with the
	// current Event and will let the IRC client move on to the next Handler or
	// Event.
	//
	// Note that if there are calls that may block for a long time such as
	// network requests and IO, it may be best to grab the required data and run
	// the response code in a goroutine so the rest of the Client can continue
	// as usual.
	HandleEvent(r *Request)
}

Handler is an interface representing objects which can be registered to serve a particular Event.Command or subcommand in the IRC client.

type HandlerFunc

type HandlerFunc func(r *Request)

The HandlerFunc is an adapter to allow the use of ordinary functions as IRC handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

func (HandlerFunc) HandleEvent

func (f HandlerFunc) HandleEvent(r *Request)

HandleEvent calls f(c, e).

type HelpInfo

type HelpInfo struct {
	Usage       string
	Description string
	// contains filtered or unexported fields
}

HelpInfo is a collection of instructions for command usage that is formatted with <prefix>help.

type MentionMux

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

MentionMux is a simple IRC event multiplexer, based on a slice of Handlers.

The MentionMux uses the current Nick and punctuation to determine if the Client has been mentioned. The nick, punctuation and any leading or trailing spaces are removed from the message.

func NewMentionMux

func NewMentionMux() *MentionMux

NewMentionMux will create an initialized MentionMux with no handlers.

func (*MentionMux) Event

func (m *MentionMux) Event(h HandlerFunc)

Event will register a Handler.

func (*MentionMux) HandleEvent

func (m *MentionMux) HandleEvent(r *Request)

HandleEvent strips off the nick punctuation and spaces and runs the handlers.

type PluginFactory

type PluginFactory func(b *Bot) error

type Request

type Request struct {
	Message *irc.Message
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(ctx context.Context, b *Bot, currentNick string, m *irc.Message) *Request

func (*Request) CTCPReplyf

func (r *Request) CTCPReplyf(format string, v ...interface{}) error

CTCPReply is a convenience function to respond to CTCP requests.

func (*Request) Context

func (r *Request) Context() context.Context

func (*Request) Copy

func (r *Request) Copy() *Request

func (*Request) CurrentNick

func (r *Request) CurrentNick() string

func (*Request) FromChannel

func (r *Request) FromChannel() bool

FromChannel checks if this message came from a channel or not.

func (*Request) GetLogger

func (r *Request) GetLogger(name string) *logrus.Entry

func (*Request) ID

func (r *Request) ID() uuid.UUID

func (*Request) MentionReplyf

func (r *Request) MentionReplyf(format string, v ...interface{}) error

MentionReply acts the same as Bot.Reply but it will prefix it with the user's nick if we are in a channel.

func (*Request) PrivateReplyf

func (r *Request) PrivateReplyf(format string, v ...interface{})

PrivateReply is similar to Reply, but it will always send privately.

func (*Request) Replyf

func (r *Request) Replyf(format string, v ...interface{}) error

Reply to a Request with a convenience wrapper around fmt.Sprintf.

func (*Request) Write

func (r *Request) Write(line string)

Write will write an raw IRC message to the stream.

func (*Request) WriteMessage

func (r *Request) WriteMessage(m *irc.Message)

Send is a simple function to send an IRC event.

func (*Request) Writef

func (r *Request) Writef(format string, args ...interface{})

Writef is a convenience method around fmt.Sprintf and Bot.Write.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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