dispatch

package
v0.0.0-...-27f5e65 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 10 Imported by: 6

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeChannelFlagsError

func MakeChannelFlagsError(flagsRequired string) error

MakeChannelFlagsError creates an error to be shown to the user about required access.

func MakeChannelLevelError

func MakeChannelLevelError(levelRequired uint8) error

MakeChannelLevelError creates an error to be shown to the user about required access.

func MakeFlagsError

func MakeFlagsError(flagsRequired string) error

MakeFlagsError creates an error to be shown to the user about required access.

func MakeGlobalFlagsError

func MakeGlobalFlagsError(flagsRequired string) error

MakeGlobalFlagsError creates an error to be shown to the user about required access.

func MakeGlobalLevelError

func MakeGlobalLevelError(levelRequired uint8) error

MakeGlobalLevelError creates an error to be shown to the user about required access.

func MakeLevelError

func MakeLevelError(levelRequired uint8) error

MakeLevelError creates an error to be shown to the user about required access.

func MakeServerFlagsError

func MakeServerFlagsError(flagsRequired string) error

MakeServerFlagsError creates an error to be shown to the user about required access.

func MakeServerLevelError

func MakeServerLevelError(levelRequired uint8) error

MakeServerLevelError creates an error to be shown to the user about required access.

func MakeUserNotAuthedError

func MakeUserNotAuthedError(user string) error

MakeUserNotAuthedError creates an error to be shown to the user about their target user not being authenticated.

func MakeUserNotFoundError

func MakeUserNotFoundError(user string) error

MakeUserNotFoundError creates an error to be shown to the user about their target user not being found.

func MakeUserNotRegisteredError

func MakeUserNotRegisteredError(user string) error

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

func (c *CommandDispatcher) Register(network, channel string, command *cmd.Command) (uint64, error)

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 NewCore

func NewCore(logger log15.Logger) *Core

NewCore initializes a dispatch 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

type Handler

type Handler interface {
	Handle(w irc.Writer, ev *irc.Event)
}

Handler is the interface for use with normal dispatching

type HandlerFunc

type HandlerFunc func(w irc.Writer, ev *irc.Event)

HandlerFunc implements the Handler interface

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(w irc.Writer, ev *irc.Event)

Handle implements Handler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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