Merge pull request #392 from jonas747/feature-gatewaybot

Add GatewayBot
This commit is contained in:
Bruce 2017-07-11 12:57:02 -05:00 committed by GitHub
commit d51cda6e5a
4 changed files with 47 additions and 7 deletions

View file

@ -18,13 +18,14 @@ var (
EndpointSmActive = EndpointSm + "active.json" EndpointSmActive = EndpointSm + "active.json"
EndpointSmUpcoming = EndpointSm + "upcoming.json" EndpointSmUpcoming = EndpointSm + "upcoming.json"
EndpointDiscord = "https://discordapp.com/" EndpointDiscord = "https://discordapp.com/"
EndpointAPI = EndpointDiscord + "api/" EndpointAPI = EndpointDiscord + "api/"
EndpointGuilds = EndpointAPI + "guilds/" EndpointGuilds = EndpointAPI + "guilds/"
EndpointChannels = EndpointAPI + "channels/" EndpointChannels = EndpointAPI + "channels/"
EndpointUsers = EndpointAPI + "users/" EndpointUsers = EndpointAPI + "users/"
EndpointGateway = EndpointAPI + "gateway" EndpointGateway = EndpointAPI + "gateway"
EndpointWebhooks = EndpointAPI + "webhooks/" EndpointGatewayBot = EndpointGateway + "/bot"
EndpointWebhooks = EndpointAPI + "webhooks/"
EndpointCDN = "https://cdn.discordapp.com/" EndpointCDN = "https://cdn.discordapp.com/"
EndpointCDNAttachments = EndpointCDN + "attachments/" EndpointCDNAttachments = EndpointCDN + "attachments/"

View file

@ -1716,6 +1716,28 @@ func (s *Session) Gateway() (gateway string, err error) {
return return
} }
// GatewayBot returns the websocket Gateway address and the recommended 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.

View file

@ -166,6 +166,17 @@ func TestGateway(t *testing.T) {
} }
} }
func TestGatewayBot(t *testing.T) {
if dgBot == nil {
t.Skip("Skipping, dgBot not set.")
}
_, err := dgBot.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 {

View file

@ -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)