Documentation
¶
Overview ¶
Package dispatch is used to dispatch irc messages to event handlers in an concurrent fashion. It supports various event handler types to easily extract information from events, as well as define more succint handlers.
Index ¶
- func MakeChannelFlagsError(flagsRequired string) error
- func MakeChannelLevelError(levelRequired uint8) error
- func MakeFlagsError(flagsRequired string) error
- func MakeGlobalFlagsError(flagsRequired string) error
- func MakeGlobalLevelError(levelRequired uint8) error
- func MakeLevelError(levelRequired uint8) error
- func MakeServerFlagsError(flagsRequired string) error
- func MakeServerLevelError(levelRequired uint8) error
- func MakeUserNotAuthedError(user string) error
- func MakeUserNotFoundError(user string) error
- func MakeUserNotRegisteredError(user string) error
- type CmdDispatcher
- type CommandDispatcher
- func (c *CommandDispatcher) Dispatch(writer irc.Writer, ev *irc.Event, provider data.Provider) (handled bool, err error)
- func (c *CommandDispatcher) EachCmd(network, channel string, cb func(*cmd.Command) bool)
- func (c *CommandDispatcher) Register(network, channel string, command *cmd.Command) (uint64, error)
- func (c *CommandDispatcher) Unregister(id uint64) (found bool)
- type Core
- type Dispatcher
- type EventDispatcher
- type Handler
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeChannelFlagsError ¶
MakeChannelFlagsError creates an error to be shown to the user about required access.
func MakeChannelLevelError ¶
MakeChannelLevelError creates an error to be shown to the user about required access.
func MakeFlagsError ¶
MakeFlagsError creates an error to be shown to the user about required access.
func MakeGlobalFlagsError ¶
MakeGlobalFlagsError creates an error to be shown to the user about required access.
func MakeGlobalLevelError ¶
MakeGlobalLevelError creates an error to be shown to the user about required access.
func MakeLevelError ¶
MakeLevelError creates an error to be shown to the user about required access.
func MakeServerFlagsError ¶
MakeServerFlagsError creates an error to be shown to the user about required access.
func MakeServerLevelError ¶
MakeServerLevelError creates an error to be shown to the user about required access.
func MakeUserNotAuthedError ¶
MakeUserNotAuthedError creates an error to be shown to the user about their target user not being authenticated.
func MakeUserNotFoundError ¶
MakeUserNotFoundError creates an error to be shown to the user about their target user not being found.
func MakeUserNotRegisteredError ¶
MakeUserNotRegisteredError creates an error to be shown to the user about the target user not being registered.
Types ¶
type CmdDispatcher ¶
type CmdDispatcher interface { Register(network, channel string, command *cmd.Command) (uint64, error) Unregister(id uint64) bool Dispatch(irc.Writer, *irc.Event, data.Provider) (bool, error) }
CmdDispatcher dispatches complex commands
type CommandDispatcher ¶
type CommandDispatcher struct { *Core // contains filtered or unexported fields }
CommandDispatcher allows for registration of commands that can involve user access, and provides a rich programming interface for command handling.
func NewCommandDispatcher ¶
func NewCommandDispatcher(fetcher pfxFetcher, core *Core) *CommandDispatcher
NewCommandDispatcher initializes a cmds.
func (*CommandDispatcher) Dispatch ¶
func (c *CommandDispatcher) Dispatch(writer irc.Writer, ev *irc.Event, provider data.Provider) (handled bool, err error)
Dispatch dispatches an IrcEvent into the cmds event handlers.
func (*CommandDispatcher) EachCmd ¶
func (c *CommandDispatcher) EachCmd(network, channel string, cb func(*cmd.Command) bool)
EachCmd iterates through the commands and passes each one to a callback function for consumption. These should be considered read-only. Optionally the results can be filtered by network and channel. To end iteration prematurely the callback function can return true.
func (*CommandDispatcher) Register ¶
Register a command with the bot. See documentation for Cmd for information about how to use this method, as well as see the documentation for CmdHandler for how to respond to commands issued by users. Network and Channel may be given to restrict which networks/channels this event will fire on.
func (*CommandDispatcher) Unregister ¶
func (c *CommandDispatcher) Unregister(id uint64) (found bool)
Unregister a command previously registered with the bot. Use the id returned from Register to do so.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core is a core for any dispatching mechanisms that includes a sync'd a waiter to synchronize the exit of all the event handlers sharing this core.
func (*Core) HandlerFinished ¶
func (d *Core) HandlerFinished()
HandlerFinished tells the core that a handler has ended.
func (*Core) HandlerStarted ¶
func (d *Core) HandlerStarted()
HandlerStarted tells the core that a handler has started and it should be waited on.
func (*Core) PanicHandler ¶
func (d *Core) PanicHandler()
PanicHandler catches any panics and logs a stack trace
func (*Core) WaitForHandlers ¶
func (d *Core) WaitForHandlers()
WaitForHandlers waits for the unfinished handlers to finish.
type Dispatcher ¶
type Dispatcher struct { *Core // contains filtered or unexported fields }
Dispatcher is made for handling dispatching of raw-ish irc events.
func NewDispatcher ¶
func NewDispatcher(core *Core) *Dispatcher
NewDispatcher initializes an empty dispatcher ready to register events.
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(w irc.Writer, ev *irc.Event)
Dispatch an IrcMessage to event handlers handling event also ensures all raw handlers receive all messages.
func (*Dispatcher) Register ¶
func (d *Dispatcher) Register(network, channel, event string, handler Handler) uint64
Register registers an event handler to a particular event. In return a unique identifer is given to later pass into Unregister in case of a need to unregister the event handler. Pass in an empty string to any of network, channel or event to prevent filtering on that parameter. Panics if it's given a type that doesn't implement any of the correct interfaces.
func (*Dispatcher) Unregister ¶
func (d *Dispatcher) Unregister(id uint64) bool
Unregister uses the identifier returned by Register to unregister a callback from the Dispatcher. If the callback was removed it returns true, false if it could not be found.
type EventDispatcher ¶
type EventDispatcher interface { Register(network, channel, event string, handler Handler) uint64 Unregister(id uint64) bool Dispatch(w irc.Writer, ev *irc.Event) }
EventDispatcher dispatches simple events