mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-12-08 04:57:19 +00:00
Compare commits
4 commits
9bd51e62ac
...
f09a05497b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f09a05497b | ||
|
|
c3dc0bc002 | ||
|
|
3a8d18dcb7 | ||
|
|
d515b9f16e |
|
|
@ -113,6 +113,31 @@ type (
|
|||
IdentifyProperties map[IdentifyPropertyKey]any
|
||||
)
|
||||
|
||||
// https://docs.discord.food/topics/gateway#gateway-capabilities
|
||||
type Capabilities uint
|
||||
|
||||
const (
|
||||
LazyUserNotes Capabilities = 1 << iota
|
||||
NoAffineUserIDs
|
||||
VersionedReadStates
|
||||
VersionedUserGuildSetttings
|
||||
DedupeUserObjects
|
||||
// Requires DedupeUserObjects
|
||||
PrioritizedReadyPayload
|
||||
MultipleGuildExperimentPopulations
|
||||
NonChannelReadStates
|
||||
AuthTokenRefresh
|
||||
UserSettingsProto
|
||||
ClientStateV2
|
||||
PassiveGuildUpdate
|
||||
AutoCallConnect
|
||||
DebounceMessageReactions
|
||||
// Supersedes PassiveGuildUpdate
|
||||
PassiveGuildUpdateV2
|
||||
_
|
||||
AutoLobbyConnect
|
||||
)
|
||||
|
||||
// IdentifyCommand is a command for Op 2. It is the struct for a data that's
|
||||
// sent over in an Identify command.
|
||||
type IdentifyCommand struct {
|
||||
|
|
@ -132,8 +157,7 @@ type IdentifyCommand struct {
|
|||
|
||||
// Capabilities defines the client's capabilities when connecting to the
|
||||
// gateway with a user account. Bot accounts should NOT touch this field.
|
||||
// The official client sets this at 125 at the time of this commit.
|
||||
Capabilities int `json:"capabilities,omitempty"`
|
||||
Capabilities Capabilities `json:"capabilities,omitempty"`
|
||||
// Intents specifies which groups of events the gateway
|
||||
// connection will receive.
|
||||
//
|
||||
|
|
@ -142,7 +166,7 @@ type IdentifyCommand struct {
|
|||
// For bot accounts, it must not be nil, and
|
||||
// Gateway.AddIntents(0) can be used if you want to
|
||||
// specify no intents.
|
||||
Intents option.Uint `json:"intents"`
|
||||
Intents option.Uint `json:"intents,omitempty"`
|
||||
}
|
||||
|
||||
// DefaultIdentifyCommand creates a default IdentifyCommand with the given token.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ import (
|
|||
// StatusTooManyRequests is the HTTP status code discord sends on rate-limiting.
|
||||
const StatusTooManyRequests = 429
|
||||
|
||||
// StatusNirnTimeout is the HTTP status code Nirn Proxy sends when the request
|
||||
// times out.
|
||||
const StatusNirnTimeout = 408
|
||||
|
||||
// Retries is the default attempts to retry if the API returns an error before
|
||||
// giving up. If the value is smaller than 1, then requests will retry forever.
|
||||
var Retries uint = 5
|
||||
|
|
@ -230,10 +234,34 @@ func (c *Client) request(
|
|||
continue
|
||||
}
|
||||
|
||||
if status = r.GetStatus(); status == StatusTooManyRequests || status >= 500 {
|
||||
status = r.GetStatus()
|
||||
|
||||
if status == StatusNirnTimeout || status >= 500 {
|
||||
continue
|
||||
}
|
||||
|
||||
if status == StatusTooManyRequests {
|
||||
var body = r.GetBody()
|
||||
defer body.Close()
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
buf.ReadFrom(body)
|
||||
|
||||
var errBody struct {
|
||||
RetryAfter float32 `json:"retry_after"`
|
||||
}
|
||||
|
||||
err := json.Unmarshal(buf.Bytes(), &errBody)
|
||||
|
||||
if err == nil {
|
||||
time.Sleep(time.Duration(errBody.RetryAfter) * time.Second)
|
||||
continue
|
||||
} else {
|
||||
doErr = fmt.Errorf("failed to parse rate limit body: %w", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue