8000 Add the guild subscription option when creation a client by skwair · Pull Request #40 · skwair/harmony · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add the guild subscription option when creation a client #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Client struct {
largeThreshold int
// See WithSharding for more information.
shard [2]int
// See WithGuildSubscriptions for more information.
guildSubscriptions bool

userID string
sessionID string
Expand Down Expand Up @@ -118,16 +120,17 @@ type Client struct {
// ClientOption.
func NewClient(token string, opts ...ClientOption) (*Client, error) {
c := &Client{
name: "Harmony",
token: "Bot " + token,
baseURL: defaultBaseURL,
client: http.DefaultClient,
limiter: rate.NewLimiter(),
largeThreshold: defaultLargeThreshold,
handlers: make(map[string]handler),
backoff: defaultBackoff,
withStateTracking: true,
logger: log.NewStd(log.LevelError),
name: "Harmony",
token: "Bot " + token,
baseURL: defaultBaseURL,
client: http.DefaultClient,
limiter: rate.NewLimiter(),
largeThreshold: defaultLargeThreshold,
guildSubscriptions: true,
handlers: make(map[string]handler),
backoff: defaultBackoff,
withStateTracking: true,
logger: log.NewStd(log.LevelError),
}

for _, opt := range opts {
Expand Down
12 changes: 11 additions & 1 deletion client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ func WithBaseURL(url string) ClientOption {

// WithSharding allows you to specify a sharding configuration when connecting to the Gateway.
// See https://discordapp.com/developers/docs/topics/gateway#sharding for more details.
// Default to nothing, sharding is not enabled.
// Defaults to nothing, sharding is not enabled.
func WithSharding(current, total int) ClientOption {
return func(c *Client) {
c.shard[0] = current
c.shard[1] = total
}
}

// WithGuildSubscription allows to set whether the client should identify to the Gateway with
// guild subscription enabled or not. Guild subscriptions are guild member presence updates
// and typing events.
// Defaults to true.
func WithGuildSubscription(y bool) ClientOption {
return func(c *Client) {
c.guildSubscriptions = y
}
}

// WithStateTracking allows you to specify whether the client is tracking the state of
// the current connection or not.
// Defaults to true.
Expand Down
18 changes: 10 additions & 8 deletions identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (

// identify is used to trigger the initial handshake with the gateway.
type identify struct {
Token string `json:"token"`
Properties map[string]string `json:"properties"`
Compress bool `json:"compress,omitempty"`
LargeThreshold int `json:"large_threshold,omitempty"`
Shard *[2]int `json:"shard,omitempty"`
Presence *Status `json:"presence,omitempty"`
Token string `json:"token"`
Properties map[string]string `json:"properties"`
Compress bool `json:"compress,omitempty"`
LargeThreshold int `json:"large_threshold,omitempty"`
Shard *[2]int `json:"shard,omitempty"`
Presence *Status `json:"presence,omitempty"`
GuildSubscriptions bool `json:"guild_subscriptions"`
}

// Status is sent by the client to indicate a presence or status update.
Expand All @@ -32,8 +33,9 @@ func (c *Client) identify() error {
"$os": strings.Title(runtime.GOOS),
56C5 "$browser": "github.com/skwair/harmony",
},
Compress: true,
LargeThreshold: c.largeThreshold,
Compress: true,
LargeThreshold: c.largeThreshold,
GuildSubscriptions: c.guildSubscriptions,
}

if c.shard[1] != 0 {
Expand Down
0