gateway

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0 Imports: 15 Imported by: 71

Documentation

Index

Constants

View Source
const Version = 10

Version defines which discord API version disgo should use to connect to discord.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseHandlerFunc added in v0.11.0

type CloseHandlerFunc func(gateway Gateway, err error)

type Config

type Config struct {
	Logger                log.Logger
	Dialer                *websocket.Dialer
	LargeThreshold        int
	GatewayIntents        discord.GatewayIntents
	Compress              bool
	GatewayURL            string
	ShardID               int
	ShardCount            int
	SessionID             *string
	LastSequenceReceived  *int
	AutoReconnect         bool
	MaxReconnectTries     int
	RateLimiter           grate.Limiter
	RateLimiterConfigOpts []grate.ConfigOpt
	Presence              *discord.GatewayMessageDataPresenceUpdate
	OS                    string
	Browser               string
	Device                string
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Apply

func (c *Config) Apply(opts []ConfigOpt)

type ConfigOpt

type ConfigOpt func(config *Config)

func WithAutoReconnect

func WithAutoReconnect(autoReconnect bool) ConfigOpt

func WithBrowser

func WithBrowser(browser string) ConfigOpt

func WithCompress

func WithCompress(compress bool) ConfigOpt

func WithDevice

func WithDevice(device string) ConfigOpt

func WithDialer added in v0.10.0

func WithDialer(dialer *websocket.Dialer) ConfigOpt

func WithGatewayIntents

func WithGatewayIntents(gatewayIntents ...discord.GatewayIntents) ConfigOpt

func WithGatewayURL

func WithGatewayURL(gatewayURL string) ConfigOpt

func WithLargeThreshold

func WithLargeThreshold(largeThreshold int) ConfigOpt

func WithLogger

func WithLogger(logger log.Logger) ConfigOpt

func WithMaxReconnectTries

func WithMaxReconnectTries(maxReconnectTries int) ConfigOpt

func WithOS

func WithOS(os string) ConfigOpt

func WithRateLimiter

func WithRateLimiter(rateLimiter grate.Limiter) ConfigOpt

func WithRateLimiterConfigOpts

func WithRateLimiterConfigOpts(opts ...grate.ConfigOpt) ConfigOpt

func WithSequence

func WithSequence(sequence int) ConfigOpt

func WithSessionID

func WithSessionID(sessionID string) ConfigOpt

func WithShardCount

func WithShardCount(shardCount int) ConfigOpt

func WithShardID

func WithShardID(shardID int) ConfigOpt

type CreateFunc

type CreateFunc func(token string, eventHandlerFunc EventHandlerFunc, closeHandlerFUnc CloseHandlerFunc, opts ...ConfigOpt) Gateway

type EventHandlerFunc

type EventHandlerFunc func(gatewayEventType discord.GatewayEventType, sequenceNumber int, shardID int, payload io.Reader)

type Gateway

type Gateway interface {
	Logger() log.Logger
	ShardID() int
	ShardCount() int
	SessionID() *string
	LastSequenceReceived() *int
	GatewayIntents() discord.GatewayIntents

	Open(ctx context.Context) error
	Close(ctx context.Context)
	CloseWithCode(ctx context.Context, code int, message string)
	Status() Status
	Send(ctx context.Context, op discord.GatewayOpcode, data discord.GatewayMessageData) error
	Latency() time.Duration
}

Gateway is what is used to connect to discord

func New

func New(token string, eventHandlerFunc EventHandlerFunc, closeHandlerFunc CloseHandlerFunc, opts ...ConfigOpt) Gateway

type Status

type Status int

Status is the state that the client is currently in

const (
	StatusUnconnected Status = iota
	StatusConnecting
	StatusWaitingForHello
	StatusIdentifying
	StatusResuming
	StatusWaitingForReady
	StatusReady
	StatusDisconnected
)

Indicates how far along the client is to connecting

func (Status) IsConnected

func (s Status) IsConnected() bool

IsConnected returns whether the Gateway is connected

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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