Merge branch 'develop' into 1

This commit is contained in:
LEGOlord208 2017-07-23 08:39:19 +02:00
commit 4edc63dabf
No known key found for this signature in database
GPG key ID: 3A818BC1F5617A24
6 changed files with 48 additions and 9 deletions

View file

@ -11,6 +11,9 @@
package discordgo
// The Discord API version used for the REST and Websocket API.
var ApiVersion = "6"
// Known Discord API Endpoints.
var (
EndpointStatus = "https://status.discordapp.com/api/v2/"
@ -19,7 +22,7 @@ var (
EndpointSmUpcoming = EndpointSm + "upcoming.json"
EndpointDiscord = "https://discordapp.com/"
EndpointAPI = EndpointDiscord + "api/"
EndpointAPI = EndpointDiscord + "api/v" + ApiVersion + "/"
EndpointGuilds = EndpointAPI + "guilds/"
EndpointChannels = EndpointAPI + "channels/"
EndpointUsers = EndpointAPI + "users/"

View file

@ -15,6 +15,19 @@ import (
"strings"
)
type MessageType int
const (
MessageTypeDefault MessageType = iota
MessageTypeRecipientAdd
MessageTypeRecipientRemove
MessageTypeCall
MessageTypeChannelNameChange
MessageTypeChannelIconChange
MessageTypeChannelPinnedMessage
MessageTypeGuildMemberJoin
)
// A Message stores all data related to a specific Discord message.
type Message struct {
ID string `json:"id"`
@ -30,6 +43,7 @@ type Message struct {
Embeds []*MessageEmbed `json:"embeds"`
Mentions []*User `json:"mentions"`
Reactions []*MessageReactions `json:"reactions"`
Type MessageType `json:"type"`
}
// File stores info about files you e.g. send in messages.
@ -226,7 +240,7 @@ func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, e
content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string {
channel, err := s.State.Channel(mention[2 : len(mention)-1])
if err != nil || channel.Type == "voice" {
if err != nil || channel.Type == ChannelTypeGuildVoice {
return mention
}

View file

@ -427,7 +427,7 @@ func (s *State) ChannelAdd(channel *Channel) error {
return nil
}
if channel.IsPrivate {
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
s.PrivateChannels = append(s.PrivateChannels, channel)
} else {
guild, ok := s.guildMap[channel.GuildID]
@ -454,7 +454,7 @@ func (s *State) ChannelRemove(channel *Channel) error {
return err
}
if channel.IsPrivate {
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
s.Lock()
defer s.Unlock()

View file

@ -144,18 +144,27 @@ type Invite struct {
Temporary bool `json:"temporary"`
}
type ChannelType int
const (
ChannelTypeGuildText ChannelType = iota
ChannelTypeDM
ChannelTypeGuildVoice
ChannelTypeGroupDM
ChannelTypeGuildCategory
)
// A Channel holds all data related to an individual Discord channel.
type Channel struct {
ID string `json:"id"`
GuildID string `json:"guild_id"`
Name string `json:"name"`
Topic string `json:"topic"`
Type string `json:"type"`
Type ChannelType `json:"type"`
LastMessageID string `json:"last_message_id"`
Position int `json:"position"`
Bitrate int `json:"bitrate"`
IsPrivate bool `json:"is_private"`
Recipient *User `json:"recipient"`
Recipients []*User `json:"recipient"`
Messages []*Message `json:"-"`
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
}
@ -295,6 +304,7 @@ type Presence struct {
Game *Game `json:"game"`
Nick string `json:"nick"`
Roles []string `json:"roles"`
Since *int `json:"since"`
}
// A Game struct holds the name of the "playing .." game for a user

13
user.go
View file

@ -37,3 +37,16 @@ func (u *User) AvatarURL(size string) string {
return URL + "?size=" + size
}
// AvatarURL returns a URL to the user's avatar.
// size: The size of the user's avatar as a power of two
func (u *User) AvatarURL(size string) string {
var URL string
if strings.HasPrefix(u.Avatar, "a_") {
URL = EndpointUserAvatarAnimated(u.ID, u.Avatar)
} else {
URL = EndpointUserAvatar(u.ID, u.Avatar)
}
return URL + "?size=" + size
}

View file

@ -15,7 +15,6 @@ import (
"compress/zlib"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"runtime"
@ -87,7 +86,7 @@ func (s *Session) Open() (err error) {
}
// Add the version and encoding to the URL
s.gateway = fmt.Sprintf("%s?v=5&encoding=json", s.gateway)
s.gateway = s.gateway + "?v=" + ApiVersion + "&encoding=json"
}
header := http.Header{}