gateway

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	LargeThreshold:    50,
	GatewayIntents:    discord.GatewayIntentsDefault,
	Compress:          true,
	AutoReconnect:     true,
	MaxReconnectTries: 10,
	OS:                info.OS,
	Browser:           info.Name,
	Device:            info.Name,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger               log.Logger
	EventHandlerFunc     EventHandlerFunc
	LargeThreshold       int
	GatewayIntents       discord.GatewayIntents
	Compress             bool
	SessionID            *string
	LastSequenceReceived *discord.GatewaySequence
	AutoReconnect        bool
	MaxReconnectTries    int
	RateLimiter          grate.Limiter
	RateLimiterConfig    *grate.Config
	Presence             *discord.UpdatePresenceCommandData
	OS                   string
	Browser              string
	Device               string
}

func (*Config) Apply

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

type ConfigOpt

type ConfigOpt func(config *Config)

func WithAutoReconnect added in v0.7.3

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 WithGatewayIntents

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

func WithLargeThreshold

func WithLargeThreshold(largeThreshold int) ConfigOpt

func WithMaxReconnectTries added in v0.7.2

func WithMaxReconnectTries(maxReconnectTries int) ConfigOpt

func WithOS

func WithOS(os string) ConfigOpt

func WithPresence

func WithPresence(presence discord.UpdatePresenceCommandData) ConfigOpt

func WithRateLimiter

func WithRateLimiter(rateLimiter grate.Limiter) ConfigOpt

func WithRateLimiterConfig

func WithRateLimiterConfig(rateLimiterConfig grate.Config) ConfigOpt

func WithRateLimiterConfigOpts

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

func WithSequence added in v0.7.3

func WithSequence(sequence discord.GatewaySequence) ConfigOpt

func WithSessionID added in v0.7.3

func WithSessionID(sessionID string) ConfigOpt

type EventHandlerFunc

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

type Gateway

type Gateway interface {
	Logger() log.Logger
	Config() Config
	ShardID() int
	ShardCount() int
	Open(ctx context.Context) error
	ReOpen(ctx context.Context, delay time.Duration) error
	Close(ctx context.Context)
	CloseWithCode(ctx context.Context, code int, message string)
	Status() Status
	Send(ctx context.Context, command discord.GatewayCommand) error
	Latency() time.Duration
}

Gateway is what is used to connect to discord

func New

func New(token string, url string, shardID int, shardCount int, eventHandlerFunc EventHandlerFunc, config *Config) 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