Documentation
¶
Index ¶
- func CtxCurrentNick(ctx context.Context) string
- func CtxLogger(ctx context.Context, name string) *logrus.Entry
- func CtxRequestID(ctx context.Context) uuid.UUID
- func RegisterPlugin(name string, factory PluginFactory)
- type BasicMux
- type Bot
- func (b *Bot) BasicMux() *BasicMux
- func (b *Bot) CommandMux() *CommandMux
- func (b *Bot) Config(name string, c interface{}) error
- func (b *Bot) ConnectAndRun() error
- func (b *Bot) Context() context.Context
- func (b *Bot) EnsurePlugin(name string) error
- func (b *Bot) MentionMux() *MentionMux
- func (b *Bot) Run(c io.ReadWriteCloser) error
- func (b *Bot) SetValue(key interface{}, value interface{})
- func (b *Bot) Write(line string)
- func (b *Bot) WriteMessage(m *irc.Message)
- func (b *Bot) Writef(format string, args ...interface{})
- type CommandMux
- type Handler
- type HandlerFunc
- type HelpInfo
- type MentionMux
- type PluginFactory
- type Request
- func (r *Request) CTCPReplyf(format string, v ...interface{}) error
- func (r *Request) Context() context.Context
- func (r *Request) Copy() *Request
- func (r *Request) CurrentNick() string
- func (r *Request) FromChannel() bool
- func (r *Request) GetLogger(name string) *logrus.Entry
- func (r *Request) ID() uuid.UUID
- func (r *Request) MentionReplyf(format string, v ...interface{}) error
- func (r *Request) PrivateReplyf(format string, v ...interface{})
- func (r *Request) Replyf(format string, v ...interface{}) error
- func (r *Request) Write(line string)
- func (r *Request) WriteMessage(m *irc.Message)
- func (r *Request) Writef(format string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CtxCurrentNick ¶
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 ¶
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 (*Bot) CommandMux ¶
func (b *Bot) CommandMux() *CommandMux
func (*Bot) Config ¶
Config will decode the config section for the given name into the given interface{}.
func (*Bot) ConnectAndRun ¶
ConnectAndRun is a convenience function which will pull the connection information out of the config and connect, then call Run.
func (*Bot) EnsurePlugin ¶
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) WriteMessage ¶
Send is a simple function to send an IRC event.
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 ¶
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) HandleEvent ¶
func (m *MentionMux) HandleEvent(r *Request)
HandleEvent strips off the nick punctuation and spaces and runs the handlers.
type PluginFactory ¶
type Request ¶
func NewRequest ¶
func (*Request) CTCPReplyf ¶
CTCPReply is a convenience function to respond to CTCP requests.
func (*Request) CurrentNick ¶
func (*Request) FromChannel ¶
FromChannel checks if this message came from a channel or not.
func (*Request) MentionReplyf ¶
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 ¶
PrivateReply is similar to Reply, but it will always send privately.
func (*Request) WriteMessage ¶
Send is a simple function to send an IRC event.