Documentation ¶
Index ¶
- Constants
- func ClientShard(guildID uint64, totalNumberOfShards uint) (shardID uint)
- type ClientState
- func (c *ClientState) Closed() bool
- func (c *ClientState) HaveIdentified() bool
- func (c *ClientState) HaveSessionID() bool
- func (c *ClientState) Heartbeat(client IOFlushWriter) error
- func (c *ClientState) Identify(client IOFlushWriter) error
- func (c *ClientState) Read(client IOReader) (*GatewayPayload, int, error)
- func (c *ClientState) Resume(client IOFlushWriter) error
- func (c *ClientState) WriteClose(client IOFlushWriter) error
- type ClientStateConfig
- type CloseCode
- type CloseErr
- type CloseError
- type DiscordErrorCode
- type DiscordVoiceCloseErr
- type GatewayHello
- type GatewayIdentify
- type GatewayIdentifyProperties
- type GatewayPayload
- type GatewayResume
- type Handler
- type IOFlushReadWriter
- type IOFlushWriter
- type IOFlusher
- type IOReadWriter
- type IOReader
- type IOWriter
- type RawMessage
- type ShardID
- type VoiceCloseEventCode
Constants ¶
const ( VoiceCloseCodeUnknownOpCodeReason = "VoiceCloseCodeUnknownOpCode You sent an invalid opcode" VoiceCloseCodeNotAuthenticatedReason = "VoiceCloseCodeNotAuthenticated You sent a payload before identifying with the Gateway" VoiceCloseCodeAuthenticationFailedReason = "VoiceCloseCodeAuthenticationFailed The token you sent in your identify payload is incorrect" VoiceCloseCodeAlreadyAuthenticatedReason = "VoiceCloseCodeAlreadyAuthenticated You sent more than one identify payload. Stahp" VoiceCloseCodeSessionNoLongerValidReason = "VoiceCloseCodeSessionNoLongerValid Your session is no longer valid" VoiceCloseCodeSessionTimedOutReason = "VoiceCloseCodeSessionTimedOut Your session has timed out" VoiceCloseCodeServerNotFoundReason = "VoiceCloseCodeServerNotFound We can't find the server you're trying to connect to" VoiceCloseCodeUnknownProtocolReason = "VoiceCloseCodeUnknownProtocol We didn't recognize the protocol you sent" VoiceCloseCodeDisconnectedReason = "VoiceCloseCodeDisconnected Either the channel was deleted or you were kicked. Should not reconnect" VoiceCloseCodeVoiceServerCrashedReason = "VoiceCloseCodeVoiceServerCrashed The server crashed. Our bad! Try resuming" VoiceCloseCodeUnknownEncryptionModeReason = "VoiceCloseCodeUnknownEncryptionMode We didn't recognize your encryption" )
Code generated - This file has been automatically generated by internal/generate/errors/main.go - DO NOT EDIT. Warning: This file is overwritten at "go generate", instead adapt error.go and run go generate
const ( CloseCodeUnknownErrorReason = "CloseCodeUnknownError We're not sure what went wrong. Try reconnecting?" CloseCodeUnknownOpCodeReason = "CloseCodeUnknownOpCode You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that!" CloseCodeDecodeErrorReason = "CloseCodeDecodeError You sent an invalid payload to us. Don't do that!" CloseCodeNotAuthenticatedReason = "CloseCodeNotAuthenticated You sent us a payload prior to identifying" CloseCodeAuthenticationFailedReason = "CloseCodeAuthenticationFailed The account token sent with your identify payload is incorrect" CloseCodeAlreadyAuthenticatedReason = "CloseCodeAlreadyAuthenticated You sent more than one identify payload. Don't do that!" CloseCodeInvalidSeqReason = "CloseCodeInvalidSeq The sequence sent when resuming the session was invalid. Reconnect and start a new session" CloseCodeRateLimitedReason = "" /* 132-byte string literal not displayed */ CloseCodeSessionTimedOutReason = "CloseCodeSessionTimedOut Your session timed out. Reconnect and start a new one" CloseCodeInvalidShardReason = "CloseCodeInvalidShard You sent us an invalid shard when identifying" CloseCodeShardingRequiredReason = "" /* 136-byte string literal not displayed */ CloseCodeInvalidAPIVersionReason = "CloseCodeInvalidAPIVersion You sent an invalid version for the gateway" CloseCodeInvalidIntentsReason = "" /* 126-byte string literal not displayed */ CloseCodeDisallowedIntentsReason = "" /* 170-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func ClientShard ¶
Types ¶
type ClientState ¶
type ClientState struct {
// contains filtered or unexported fields
}
ClientState should be discarded after the connection has closed. reconnect must create a new shard instance.
func NewResumableShard ¶
func NewResumableShard(deadShard *ClientState) *ClientState
NewResumableShard when a client/shard disconnects for whatever reason, you must create a new instance. To utilise the resume logic from discord you must use the new client instance below. Note that it is your responsibility to make sure you are allowed to resume. eg. resuming after a "invalid session" will most likely fail, and you need to create a new shard again.
You must use the newly returned instance. The argument/function input should be left for garbage collection.
func NewShard ¶
func NewShard(conf *ClientStateConfig) *ClientState
func NewShardFromPrevious ¶
func NewShardFromPrevious(deadShard *ClientState) *ClientState
func (*ClientState) Closed ¶
func (c *ClientState) Closed() bool
func (*ClientState) HaveIdentified ¶
func (c *ClientState) HaveIdentified() bool
func (*ClientState) HaveSessionID ¶
func (c *ClientState) HaveSessionID() bool
func (*ClientState) Heartbeat ¶
func (c *ClientState) Heartbeat(client IOFlushWriter) error
Heartbeat Close method may be used if Write fails
func (*ClientState) Identify ¶
func (c *ClientState) Identify(client IOFlushWriter) error
Identify Close method may be used if Write fails
func (*ClientState) Read ¶
func (c *ClientState) Read(client IOReader) (*GatewayPayload, int, error)
Read until a new data frame with updated info comes in, or fails.
func (*ClientState) Resume ¶
func (c *ClientState) Resume(client IOFlushWriter) error
Resume Close method may be used if Write fails
func (*ClientState) WriteClose ¶
func (c *ClientState) WriteClose(client IOFlushWriter) error
type ClientStateConfig ¶
type CloseCode ¶
type CloseCode DiscordErrorCode
const ( // CloseCodeUnknownError We're not sure what went wrong. Try reconnecting? CloseCodeUnknownError CloseCode = 4000 + iota // CloseCodeUnknownOpCode You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that! CloseCodeUnknownOpCode // CloseCodeDecodeError You sent an invalid payload to us. Don't do that! CloseCodeDecodeError // CloseCodeNotAuthenticated You sent us a payload prior to identifying CloseCodeNotAuthenticated // CloseCodeAuthenticationFailed The account token sent with your identify payload is incorrect CloseCodeAuthenticationFailed // CloseCodeAlreadyAuthenticated You sent more than one identify payload. Don't do that! CloseCodeAlreadyAuthenticated // CloseCodeInvalidSeq The sequence sent when resuming the session was invalid. Reconnect and start a new session CloseCodeInvalidSeq // CloseCodeRateLimited Woah nelly! You're sending payloads to us too quickly. Slow it down! You will be disconnected on receiving this CloseCodeRateLimited // CloseCodeSessionTimedOut Your session timed out. Reconnect and start a new one CloseCodeSessionTimedOut // CloseCodeInvalidShard You sent us an invalid shard when identifying CloseCodeInvalidShard // CloseCodeShardingRequired The session would have handled too many guilds - you are required to shard your connection in order to connect CloseCodeShardingRequired // CloseCodeInvalidAPIVersion You sent an invalid version for the gateway CloseCodeInvalidAPIVersion // CloseCodeInvalidIntents You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise value CloseCodeInvalidIntents // CloseCodeDisallowedIntents You sent a disallowed intent for a Gateway Intent. You may have tried to specify an intent that you have not enabled or are not whitelisted for CloseCodeDisallowedIntents )
type CloseError ¶
func (*CloseError) Error ¶
func (c *CloseError) Error() string
type DiscordErrorCode ¶
type DiscordErrorCode uint32
const (
HeartbeatAckNotReceived DiscordErrorCode = 3000
)
custom codes
type DiscordVoiceCloseErr ¶
type DiscordVoiceCloseErr struct {
Code VoiceCloseEventCode
}
func (*DiscordVoiceCloseErr) Error ¶
func (e *DiscordVoiceCloseErr) Error() string
type GatewayHello ¶
type GatewayHello struct {
HeartbeatIntervalMilli int64 `json:"heartbeat_interval"`
}
type GatewayIdentify ¶
type GatewayIdentify struct { Token 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.Flag `json:"intents"` }
type GatewayPayload ¶
type GatewayPayload struct { Op uint8 `json:"op"` Data RawMessage `json:"d"` Seq int64 `json:"s,omitempty"` EventName string `json:"t,omitempty"` // EventID event.Flag `json:"-"` Outdated bool `json:"-"` }
type GatewayResume ¶
type IOFlushReadWriter ¶
type IOFlushWriter ¶
type IOReadWriter ¶
type RawMessage ¶
type RawMessage = json.RawMessage
type VoiceCloseEventCode ¶
type VoiceCloseEventCode DiscordErrorCode
const ( // VoiceCloseCodeUnknownOpCode You sent an invalid opcode VoiceCloseCodeUnknownOpCode VoiceCloseEventCode // VoiceCloseCodeNotAuthenticated You sent a payload before identifying with the Gateway VoiceCloseCodeNotAuthenticated // VoiceCloseCodeAuthenticationFailed The token you sent in your identify payload is incorrect VoiceCloseCodeAuthenticationFailed // VoiceCloseCodeAlreadyAuthenticated You sent more than one identify payload. Stahp VoiceCloseCodeAlreadyAuthenticated // VoiceCloseCodeSessionNoLongerValid Your session is no longer valid VoiceCloseCodeSessionNoLongerValid // VoiceCloseCodeSessionTimedOut Your session has timed out VoiceCloseCodeSessionTimedOut // VoiceCloseCodeServerNotFound We can't find the server you're trying to connect to VoiceCloseCodeServerNotFound // VoiceCloseCodeUnknownProtocol We didn't recognize the protocol you sent VoiceCloseCodeUnknownProtocol // VoiceCloseCodeDisconnected Either the channel was deleted or you were kicked. Should not reconnect VoiceCloseCodeDisconnected // VoiceCloseCodeVoiceServerCrashed The server crashed. Our bad! Try resuming VoiceCloseCodeVoiceServerCrashed // VoiceCloseCodeUnknownEncryptionMode We didn't recognize your encryption VoiceCloseCodeUnknownEncryptionMode )