Documentation ¶
Overview ¶
Package bot implements the top-level package that any non-extension will use to start a bot instance.
Index ¶
- func CheckConfig(c *config.Config) bool
- func NewAPIServer(b *Bot) *apiServer
- func NewCoreCmds(b *Bot) (*coreCmds, error)
- func RegisterExtension(name string, ext Extension)
- func Run(cb func(b *Bot)) error
- type Bot
- func (b *Bot) Cleanup() error
- func (b *Bot) Close() error
- func (b *Bot) DumpConfig() error
- func (b *Bot) NetworkWriter(networkID string) (w irc.Writer)
- func (b *Bot) ReadConfig(fn configCallback)
- func (b *Bot) Register(network, channel, event string, handler dispatch.Handler) uint64
- func (b *Bot) RegisterCmd(network, channel string, command *cmd.Command) (uint64, error)
- func (b *Bot) RegisterGlobal(event string, handler dispatch.Handler) uint64
- func (b *Bot) RegisterGlobalCmd(command *cmd.Command) (uint64, error)
- func (b *Bot) Rehash() error
- func (b *Bot) ReplaceConfig(newConfig *config.Config) bool
- func (b *Bot) Start() <-chan error
- func (b *Bot) StartNetwork(networkID string) (started bool)
- func (b *Bot) State(networkID string) *data.State
- func (b *Bot) Stop()
- func (b *Bot) StopNetwork(networkID string) (stopped bool)
- func (b *Bot) Store() *data.Store
- func (b *Bot) Unregister(id uint64) bool
- func (b *Bot) UnregisterCmd(id uint64) bool
- func (b *Bot) WriteConfig(fn configCallback)
- type ConnProvider
- type Extension
- type LoggerProvider
- type Server
- type Status
- type StoreProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckConfig ¶
CheckConfig checks a bots config for validity.
func NewCoreCmds ¶
NewCoreCmds initializes the core commands and registers them with the bot.
func RegisterExtension ¶
RegisterExtension with the bot. This should be called on init(), and the extension should rely upon import side effects in order to have that init() called. Panics if a name is registered twice.
func Run ¶
Run makes a very typical bot. It will call the cb function passed in before starting to allow registration of extensions etc. Returns error if the bot could not be created. Does NOT return until dead. The following are featured behaviors: Reads configuration file from ./config.toml Watches for Keyboard Input OR SIGTERM OR SIGKILL and shuts down normally. Pauses after death to allow all goroutines to come to a graceful shutdown.
Types ¶
type Bot ¶
type Bot struct { // Logging log15.Logger // contains filtered or unexported fields }
Bot is a main type that joins together all the packages into a functioning irc bot. It should be able to carry out most major functions that a bot would need through it's exported functions.
func New ¶
New simplifies the call to createBotFull by using default caps and conn provider functions.
func (*Bot) DumpConfig ¶
DumpConfig dumps the config to a file. It attempts to use the previously read config file name if loaded from a file... If not it will use a default file name.
func (*Bot) NetworkWriter ¶
NetworkWriter retrieves a network's writer. Will be nil if the network does not exist.
func (*Bot) ReadConfig ¶
func (b *Bot) ReadConfig(fn configCallback)
ReadConfig opens the config for reading, for the duration of the callback the config is synchronized.
func (*Bot) Register ¶
Register event handlers to the specified network and channel. Leave either blank to create a filter based on that field alone. Returns an identifier that can be used to unregister the event.
func (*Bot) RegisterCmd ¶
RegisterCmd registers a command with the bot filtered based on the network and channel. Leave either field blank to create a filter based on that field alone. See cmds.Cmds.Register for in-depth documentation.
func (*Bot) RegisterGlobal ¶
RegisterGlobal event handler to the bot. Returns an identifier that can be used to unregister the event.
func (*Bot) RegisterGlobalCmd ¶
RegisterGlobalCmd registers a command with the bot. See cmds.Cmds.Register for in-depth documentation.
func (*Bot) Rehash ¶
Rehash loads the config from a file. It attempts to use the previously read config file name if loaded from a file... If not it will use a default file name. It then calls Bot.ReplaceConfig.
func (*Bot) ReplaceConfig ¶
ReplaceConfig replaces the current configuration for the bot. Running servers not present in the new config will be shut down immediately, while new servers will be connected to and started. Updates updateable attributes from the new configuration for each server. Returns false if the config had an error.
func (*Bot) Start ¶
Start runs the bot. A channel is returned, every time a server is killed permanently it reports the error on this channel. When the channel is closed, there are no more servers left to run and the program can safely exit.
func (*Bot) StartNetwork ¶
StartNetwork starts a network by name. Start() should have been called prior to this.
func (*Bot) State ¶
State returns the state db for that network id. If the server doesn't exist or state is disabled, returns nil.
func (*Bot) StopNetwork ¶
StopNetwork stops a network by name.
func (*Bot) Unregister ¶
Unregister an event handler from the bot.
func (*Bot) UnregisterCmd ¶
UnregisterCmd from the bot. All parameters can be blank except for cmd. Leaving ext blank wipes out other extension's commands with the same name.
func (*Bot) WriteConfig ¶
func (b *Bot) WriteConfig(fn configCallback)
WriteConfig opens the config for writing, for the duration of the callback the config is synchronized.
type ConnProvider ¶
ConnProvider transforms a "server:port" string into a net.Conn
type Extension ¶
type Extension interface { // Init attaches event handlers and commands Init(*Bot) error // Deinit detaches event handlers and commands Deinit(*Bot) error }
Extension provides methods to initialize and de-initialize itself. The bot type is passed in as the interface with which to register event handlers, commands, and access the databases. The de-init should destroy the extension until it is called upon again.
Event handlers can execute in parallel and so there must be provisions to protect mutable state within the implementation.
type LoggerProvider ¶
type LoggerProvider func() log15.Handler
LoggerProvider returns a log15.Handler suitable for logging.
type Server ¶
type Server struct { log15.Logger // contains filtered or unexported fields }
Server is all the details around a specific server connection. Also contains the connection and configuration for the specific server.