Add GatewayBot
This commit is contained in:
parent
9d41d8595b
commit
9d3cd03314
4 changed files with 47 additions and 7 deletions
|
@ -24,6 +24,7 @@ var (
|
||||||
EndpointChannels = EndpointAPI + "channels/"
|
EndpointChannels = EndpointAPI + "channels/"
|
||||||
EndpointUsers = EndpointAPI + "users/"
|
EndpointUsers = EndpointAPI + "users/"
|
||||||
EndpointGateway = EndpointAPI + "gateway"
|
EndpointGateway = EndpointAPI + "gateway"
|
||||||
|
EndpointGatewayBot = EndpointGateway + "/bot"
|
||||||
EndpointWebhooks = EndpointAPI + "webhooks/"
|
EndpointWebhooks = EndpointAPI + "webhooks/"
|
||||||
|
|
||||||
EndpointCDN = "https://cdn.discordapp.com/"
|
EndpointCDN = "https://cdn.discordapp.com/"
|
||||||
|
|
22
restapi.go
22
restapi.go
|
@ -1716,6 +1716,28 @@ func (s *Session) Gateway() (gateway string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gateway returns the websocket Gateway address and the reccomended number of shards
|
||||||
|
func (s *Session) GatewayBot() (st *GatewayBotResponse, err error) {
|
||||||
|
|
||||||
|
response, err := s.RequestWithBucketID("GET", EndpointGatewayBot, nil, EndpointGatewayBot)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = unmarshal(response, &st)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the gateway always has a trailing slash.
|
||||||
|
// MacOS will fail to connect if we add query params without a trailing slash on the base domain.
|
||||||
|
if !strings.HasSuffix(st.URL, "/") {
|
||||||
|
st.URL += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Functions specific to Webhooks
|
// Functions specific to Webhooks
|
||||||
|
|
||||||
// WebhookCreate returns a new Webhook.
|
// WebhookCreate returns a new Webhook.
|
||||||
|
|
|
@ -166,6 +166,17 @@ func TestGateway(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGatewayBot(t *testing.T) {
|
||||||
|
|
||||||
|
if dg == nil {
|
||||||
|
t.Skip("Skipping, dg not set.")
|
||||||
|
}
|
||||||
|
_, err := dg.GatewayBot()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("GatewayBot() returned error: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVoiceICE(t *testing.T) {
|
func TestVoiceICE(t *testing.T) {
|
||||||
|
|
||||||
if dg == nil {
|
if dg == nil {
|
||||||
|
|
|
@ -512,6 +512,12 @@ type MessageReaction struct {
|
||||||
ChannelID string `json:"channel_id"`
|
ChannelID string `json:"channel_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GatewayBotResponse stores the data for the gateway/bot response
|
||||||
|
type GatewayBotResponse struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Shards int `json:"shards"`
|
||||||
|
}
|
||||||
|
|
||||||
// Constants for the different bit offsets of text channel permissions
|
// Constants for the different bit offsets of text channel permissions
|
||||||
const (
|
const (
|
||||||
PermissionReadMessages = 1 << (iota + 10)
|
PermissionReadMessages = 1 << (iota + 10)
|
||||||
|
|
Loading…
Reference in a new issue