dispatcher

package
v24.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package dispatcher handles opcode dispatching

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ETFPayloadToMessage

func ETFPayloadToMessage(ctx context.Context, ep ETFPayload) (wsapi.WSMessage, error)

ETFPayloadToMessage converts a specialized etf payload to a websocket message

Types

type DispatchHandlerFunc

type DispatchHandlerFunc = func(Payload, wsapi.WSMessage, chan<- wsapi.WSMessage) snowflake.Snowflake

DispatchHandlerFunc is the api that a bot expects a handler function to have

type Dispatcher

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

Dispatcher is the op-code dispatcher

func NewDispatcher

func NewDispatcher(deps dependencies) *Dispatcher

NewDispatcher creates a new Dispatcher object with default state and session management handlers installed

func (*Dispatcher) AddHandler

func (c *Dispatcher) AddHandler(event string, handler DispatchHandlerFunc)

AddHandler adds a new event handler to the dispatch table

func (*Dispatcher) ConnectToBot

func (c *Dispatcher) ConnectToBot(b *bot.DiscordBot)

ConnectToBot attaches this dispatcher to a bot instance

func (*Dispatcher) GenerateHeartbeat

func (c *Dispatcher) GenerateHeartbeat(ctx context.Context, seqNum int) (wsapi.WSMessage, error)

GenerateHeartbeat prepares a heartbeat message to be sent

func (*Dispatcher) HandleRequest

func (c *Dispatcher) HandleRequest(req wsapi.WSMessage, resp chan<- wsapi.WSMessage) snowflake.Snowflake

HandleRequest dispatches a message and queues a response, if there is one

func (*Dispatcher) SetDebug

func (c *Dispatcher) SetDebug(val bool)

SetDebug turns on/off debug mode

type ETFPayload

type ETFPayload interface {
	Payload() (etfapi.Payload, error)
}

ETFPayload is the interface that a specialized etf api payload conforms to

type Logger

type Logger = interface {
	Log(keyvals ...interface{}) error
	Message(string, ...interface{})
	Err(string, error, ...interface{})
	Printf(string, ...interface{})
}

Logger is the interface expected for logging

type Payload

type Payload = interface {
	EventName() string
	Contents() map[string]etfapi.Element
}

Payload is the interface expected for an etf payload

Jump to

Keyboard shortcuts

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