Add GatewayBot
This commit is contained in:
parent
9d41d8595b
commit
9d3cd03314
4 changed files with 47 additions and 7 deletions
15
endpoints.go
15
endpoints.go
|
@ -18,13 +18,14 @@ var (
|
|||
EndpointSmActive = EndpointSm + "active.json"
|
||||
EndpointSmUpcoming = EndpointSm + "upcoming.json"
|
||||
|
||||
EndpointDiscord = "https://discordapp.com/"
|
||||
EndpointAPI = EndpointDiscord + "api/"
|
||||
EndpointGuilds = EndpointAPI + "guilds/"
|
||||
EndpointChannels = EndpointAPI + "channels/"
|
||||
EndpointUsers = EndpointAPI + "users/"
|
||||
EndpointGateway = EndpointAPI + "gateway"
|
||||
EndpointWebhooks = EndpointAPI + "webhooks/"
|
||||
EndpointDiscord = "https://discordapp.com/"
|
||||
EndpointAPI = EndpointDiscord + "api/"
|
||||
EndpointGuilds = EndpointAPI + "guilds/"
|
||||
EndpointChannels = EndpointAPI + "channels/"
|
||||
EndpointUsers = EndpointAPI + "users/"
|
||||
EndpointGateway = EndpointAPI + "gateway"
|
||||
EndpointGatewayBot = EndpointGateway + "/bot"
|
||||
EndpointWebhooks = EndpointAPI + "webhooks/"
|
||||
|
||||
EndpointCDN = "https://cdn.discordapp.com/"
|
||||
EndpointCDNAttachments = EndpointCDN + "attachments/"
|
||||
|
|
22
restapi.go
22
restapi.go
|
@ -1716,6 +1716,28 @@ func (s *Session) Gateway() (gateway string, err error) {
|
|||
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
|
||||
|
||||
// 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) {
|
||||
|
||||
if dg == nil {
|
||||
|
|
|
@ -512,6 +512,12 @@ type MessageReaction struct {
|
|||
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
|
||||
const (
|
||||
PermissionReadMessages = 1 << (iota + 10)
|
||||
|
|
Loading…
Reference in a new issue