dispatcher

package
v0.0.0-...-abeac51 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StopClient cancels the context and stops the client if returned through handler callback function.
	StopClient = errors.New("disconnect")

	// EndGroups stops iterating over handlers groups if returned through handler callback function.
	EndGroups = errors.New("stopped")
	// ContinueGroups continues iterating over handlers groups if returned through handler callback function.
	ContinueGroups = errors.New("continued")
	// SkipCurrentGroup skips current group and continues iterating over handlers groups if returned through handler callback function.
	SkipCurrentGroup = errors.New("skipped")
)

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	Initialize(context.Context, context.CancelFunc, *telegram.Client, *tg.User)
	Handle(context.Context, tg.UpdatesClass) error
	AddHandler(Handler)
	AddHandlerToGroup(Handler, int)
}

type ErrorHandler

type ErrorHandler func(*ext.Context, *ext.Update, string) error

type Handler

type Handler interface {
	// CheckUpdate checks whether the update should be handled by this handler and processes it.
	CheckUpdate(*ext.Context, *ext.Update) error
}

Handler is the common interface for all the handlers.

type NativeDispatcher

type NativeDispatcher struct {

	// Panic handles all the panics that occur during handler execution.
	Panic PanicHandler
	// Error handles all the unknown errors which are returned by the handler callback functions.
	Error ErrorHandler
	// contains filtered or unexported fields
}

func NewNativeDispatcher

func NewNativeDispatcher(setReply bool, setEntireReplyChain bool, eHandler ErrorHandler, pHandler PanicHandler, p *storage.PeerStorage) *NativeDispatcher

MakeDispatcher creates new custom dispatcher which process and handles incoming updates.

func (*NativeDispatcher) AddHandler

func (dp *NativeDispatcher) AddHandler(h Handler)

AddHandler adds a new handler to the dispatcher. The dispatcher will call CheckUpdate() to see whether the handler should be executed, and then execute it.

func (*NativeDispatcher) AddHandlerToGroup

func (dp *NativeDispatcher) AddHandlerToGroup(h Handler, group int)

AddHandlerToGroup adds a handler to a specific group; lowest number will be processed first.

func (*NativeDispatcher) Handle

func (dp *NativeDispatcher) Handle(ctx context.Context, updates tg.UpdatesClass) error

Handle function handles all the incoming updates, map entities and dispatches updates for further handling.

func (*NativeDispatcher) Initialize

func (dp *NativeDispatcher) Initialize(ctx context.Context, cancel context.CancelFunc, client *telegram.Client, self *tg.User)

type PanicHandler

type PanicHandler func(*ext.Context, *ext.Update, string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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