ext

package
v1.0.0-beta02 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EndGroups        = errors.New("end")
	ContinueGroup    = errors.New("continue")
	SkipCurrentGroup = errors.New("skip")
)

Functions

This section is empty.

Types

type Context

type Context struct {
	EffectiveUser    *gottbot.User
	EffectiveMessage *gottbot.Message
	EffectiveQuery   *gottbot.Callback
	EffectiveChatId  int64
	Data             map[string]any
	*gottbot.Update
}

Context contains the important data of the current update.

func NewContext

func NewContext(u *gottbot.Update) *Context

type Dispatcher

type Dispatcher interface {
	// setUpdateChan(update chan gottbot.Update)
	AddHandlerToGroup(group int, handler Handler) HandlerID
	AddHandler(handler Handler) HandlerID
	RemoveHandler(id HandlerID) bool
	Run(bot *gottbot.Bot, updateChan chan *gottbot.Update)
}

type GeneralDispatcher

type GeneralDispatcher struct {
	ErrorHandler func(*gottbot.Bot, *gottbot.Update, error)
	// contains filtered or unexported fields
}

GeneralDispatcher is the default dispatcher.

func NewDispatcher

func NewDispatcher(errorHandler func(*gottbot.Bot, *gottbot.Update, error)) *GeneralDispatcher

NewDispatcher creates a new general dispatcher.

func (*GeneralDispatcher) AddHandler

func (g *GeneralDispatcher) AddHandler(handler Handler) HandlerID

AddHandler appends the provided handler to the handler group 0.

func (*GeneralDispatcher) AddHandlerToGroup

func (g *GeneralDispatcher) AddHandlerToGroup(group int, handler Handler) HandlerID

AddHandlerToGroup appends the provided handler to the provided handler group.

func (*GeneralDispatcher) RemoveGroup

func (g *GeneralDispatcher) RemoveGroup(group int)

RemoveGroup removes the whole handler group.

func (*GeneralDispatcher) RemoveHandler

func (g *GeneralDispatcher) RemoveHandler(id HandlerID) bool

RemoveHandler removes the handler from any further service.

func (*GeneralDispatcher) Run

func (g *GeneralDispatcher) Run(bot *gottbot.Bot, updateChan chan *gottbot.Update)

type Handler

type Handler interface {
	HandleUpdate(bot *gottbot.Bot, ctx *Context) error
	CheckUpdate(update *gottbot.Update) bool
	GetHandlerID() HandlerID
}

type HandlerID

type HandlerID string

type Updater

type Updater struct {
	Dispatcher Dispatcher
	// contains filtered or unexported fields
}

Updater fetches the updates from bot api

Either by StartWebhook or by StartPolling

func NewUpdater

func NewUpdater(opts *UpdaterOpts) *Updater

NewUpdater creates a new Updater.

func (*Updater) Idle

func (u *Updater) Idle()

func (*Updater) StartPolling

func (u *Updater) StartPolling(bot *gottbot.Bot, opts *gottbot.GetUpdatesOpts)

func (*Updater) StartWebhook

func (u *Updater) StartWebhook(bot *gottbot.Bot, opts *WebhookOpts)

type UpdaterOpts

type UpdaterOpts struct {
	Dispatcher   Dispatcher
	ErrorHandler func(*gottbot.Bot, *gottbot.Update, error)
}

Optional fields for the NewUpdater

type WebhookOpts

type WebhookOpts struct {
	Domain      string
	Port        int
	Path        string
	ReadTimeout time.Duration
}

Jump to

Keyboard shortcuts

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