Skip to content

Commit

Permalink
Support gateway version config, upgrade to 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Nelson committed Mar 27, 2021
1 parent cd0c59f commit e4bf0e8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func Run() {
Intents: int(conf.RawIntents),
Presence: &conf.Presence,
},
Version: conf.GatewayVersion,
},
REST: rest.NewClient(conf.Token),
LogLevel: logLevel,
Expand Down
19 changes: 14 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ func (d *duration) UnmarshalText(text []byte) (err error) {

// Config represents configuration structure for the gateway
type Config struct {
Token string
Events []string
Intents []string
RawIntents uint
Shards struct {
Token string
Events []string
Intents []string
RawIntents uint
GatewayVersion uint `toml:"gateway_version"`
Shards struct {
Count int
IDs []int
}
Expand Down Expand Up @@ -150,6 +151,14 @@ func (c *Config) LoadEnv() {
}
}

v = os.Getenv("DISCORD_GATEWAY_VERSION")
if v != "" {
i, err := strconv.ParseUint(v, 10, 32)
if err != nil {
c.GatewayVersion = uint(i)
}
}

v = os.Getenv("DISCORD_SHARD_COUNT")
if v != "" {
i, err := strconv.ParseUint(v, 10, 32)
Expand Down
2 changes: 1 addition & 1 deletion gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// DefaultVersion represents the default Gateway version
const DefaultVersion = "7"
const DefaultVersion uint = 8

// Endpoints used for the Gateway
const (
Expand Down
2 changes: 1 addition & 1 deletion gateway/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (s *Shard) startHeartbeater(interval time.Duration, stop <-chan struct{}) {
// gatewayURL returns the Gateway URL with appropriate query parameters
func (s *Shard) gatewayURL() string {
query := url.Values{
"v": {s.opts.Version},
"v": {strconv.FormatUint(uint64(s.opts.Version), 10)},
"encoding": {"json"},
"compress": {"zstd-stream"},
}
Expand Down
4 changes: 2 additions & 2 deletions gateway/shard_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Retryer interface {
// ShardOptions represents NewShard's options
type ShardOptions struct {
Identify *types.Identify
Version string
Version uint
Retryer Retryer
Store ShardStore

Expand All @@ -31,7 +31,7 @@ type ShardOptions struct {
}

func (opts *ShardOptions) init() {
if opts.Version == "" {
if opts.Version == 0 {
opts.Version = DefaultVersion
}

Expand Down

0 comments on commit e4bf0e8

Please sign in to comment.