Documentation
¶
Index ¶
- Constants
- Variables
- func NewCommandRateLimiter() (<-chan int, io.Closer)
- func NewIdentifyRateLimiter() (<-chan int, io.Closer)
- func NewRateLimiter(burstCapacity int, burstDuration time.Duration) (<-chan int, io.Closer)
- func ValidateDialURL(URLString string) (string, error)
- type DiscordError
- type GatewayPayload
- type GatewayState
- func (gs *GatewayState) Close() error
- func (gs *GatewayState) EventIsWhitelisted(evt event.Type) bool
- func (gs *GatewayState) HaveIdentified() bool
- func (gs *GatewayState) HaveSessionID() bool
- func (gs *GatewayState) Heartbeat(client io.Writer) error
- func (gs *GatewayState) Identify(client io.Writer) error
- func (gs *GatewayState) InvalidateSession(closeWriter io.Writer)
- func (gs *GatewayState) ProcessCloseCode(code closecode.Type, reason string, closeWriter io.Writer) error
- func (gs *GatewayState) ProcessNextMessage(pipe io.Reader, textWriter, closeWriter io.Writer) (payload *GatewayPayload, redundant bool, err error)
- func (gs *GatewayState) ProcessPayload(payload *GatewayPayload, textWriter, closeWriter io.Writer) (redundant bool, err error)
- func (gs *GatewayState) Read(client io.Reader) (*GatewayPayload, int, error)
- func (gs *GatewayState) Resume(client io.Writer) error
- func (gs *GatewayState) SessionID() string
- func (gs *GatewayState) String() string
- func (gs *GatewayState) Write(client io.Writer, opc command.Type, payload json.RawMessage) (err error)
- type Handler
- type HandlerStruct
- type Hello
- type Identify
- type IdentifyConnectionProperties
- type IdentifyRateLimiter
- type Option
- func WithCommandRateLimiter(ratelimiter <-chan int) Option
- func WithDirectMessageEvents(events ...event.Type) Option
- func WithGuildEvents(events ...event.Type) Option
- func WithIdentifyConnectionProperties(properties *IdentifyConnectionProperties) Option
- func WithIdentifyRateLimiter(ratelimiter IdentifyRateLimiter) Option
- func WithIntents(intents intent.Type) Option
- func WithSequenceNumber(seq int64) Option
- func WithSessionID(id string) Option
- func WithShardCount(count uint) Option
- func WithShardID(id ShardID) Option
- type RawMessage
- type Ready
- type Resume
- type ShardID
Constants ¶
View Source
const ( NormalCloseCode uint16 = 1000 RestartCloseCode uint16 = 1012 )
Variables ¶
View Source
var ErrIncompleteDialURL = errors.New("incomplete url is missing one or many of: 'version', 'encoding', 'scheme'")
View Source
var ErrSequenceNumberSkipped = errors.New("the sequence number increased with more than 1, events lost")
View Source
var ErrURLScheme = errors.New("url scheme was not websocket (ws nor wss)")
View Source
var ErrUnsupportedAPICodec = fmt.Errorf("only %+v is supported", supportedAPICodes)
View Source
var ErrUnsupportedAPIVersion = fmt.Errorf("only discord api version %+v is supported", supportedAPIVersions)
Functions ¶
func NewCommandRateLimiter ¶
func NewIdentifyRateLimiter ¶
func NewRateLimiter ¶
func ValidateDialURL ¶
Types ¶
type DiscordError ¶
func (DiscordError) CanReconnect ¶
func (c DiscordError) CanReconnect() bool
func (*DiscordError) Error ¶
func (c *DiscordError) Error() string
type GatewayPayload ¶
type GatewayState ¶
type GatewayState struct {
// contains filtered or unexported fields
}
GatewayState should be discarded after the connection has closed. reconnect must create a new shard instance.
func NewGatewayState ¶
func NewGatewayState(botToken string, options ...Option) (*GatewayState, error)
func (*GatewayState) Close ¶
func (gs *GatewayState) Close() error
func (*GatewayState) EventIsWhitelisted ¶
func (gs *GatewayState) EventIsWhitelisted(evt event.Type) bool
func (*GatewayState) HaveIdentified ¶
func (gs *GatewayState) HaveIdentified() bool
func (*GatewayState) HaveSessionID ¶
func (gs *GatewayState) HaveSessionID() bool
func (*GatewayState) Heartbeat ¶
func (gs *GatewayState) Heartbeat(client io.Writer) error
Heartbeat Close method may be used if Write fails
func (*GatewayState) Identify ¶
func (gs *GatewayState) Identify(client io.Writer) error
Identify Close method may be used if Write fails
func (*GatewayState) InvalidateSession ¶
func (gs *GatewayState) InvalidateSession(closeWriter io.Writer)
func (*GatewayState) ProcessCloseCode ¶
func (gs *GatewayState) ProcessCloseCode(code closecode.Type, reason string, closeWriter io.Writer) error
ProcessCloseCode process close code sent by discord
func (*GatewayState) ProcessNextMessage ¶
func (gs *GatewayState) ProcessNextMessage(pipe io.Reader, textWriter, closeWriter io.Writer) (payload *GatewayPayload, redundant bool, err error)
func (*GatewayState) ProcessPayload ¶
func (gs *GatewayState) ProcessPayload(payload *GatewayPayload, textWriter, closeWriter io.Writer) (redundant bool, err error)
func (*GatewayState) Read ¶
func (gs *GatewayState) Read(client io.Reader) (*GatewayPayload, int, error)
func (*GatewayState) Resume ¶
func (gs *GatewayState) Resume(client io.Writer) error
Resume Close method may be used if Write fails
func (*GatewayState) SessionID ¶
func (gs *GatewayState) SessionID() string
func (*GatewayState) String ¶
func (gs *GatewayState) String() string
func (*GatewayState) Write ¶
func (gs *GatewayState) Write(client io.Writer, opc command.Type, payload json.RawMessage) (err error)
type HandlerStruct ¶
type HandlerStruct struct { ShardID Name event.Type Data RawMessage }
type Identify ¶
type Identify struct { BotToken string `json:"token"` Properties interface{} `json:"properties"` Compress bool `json:"compress,omitempty"` LargeThreshold uint8 `json:"large_threshold,omitempty"` Shard [2]uint `json:"shard"` Presence interface{} `json:"presence"` Intents intent.Type `json:"intents"` }
type IdentifyRateLimiter ¶
type Option ¶
type Option func(st *GatewayState) error
Option for initializing a new gateway state. An option must be deterministic regardless of when or how many times it is executed.
func WithCommandRateLimiter ¶
func WithDirectMessageEvents ¶
func WithGuildEvents ¶
func WithIdentifyConnectionProperties ¶
func WithIdentifyConnectionProperties(properties *IdentifyConnectionProperties) Option
func WithIdentifyRateLimiter ¶
func WithIdentifyRateLimiter(ratelimiter IdentifyRateLimiter) Option
func WithIntents ¶
func WithSequenceNumber ¶
func WithSessionID ¶
func WithShardCount ¶
func WithShardID ¶
type RawMessage ¶
type RawMessage = json.RawMessage
Source Files
¶
Click to show internal directories.
Click to hide internal directories.