Merge branch 'develop' into 1
This commit is contained in:
commit
4edc63dabf
6 changed files with 48 additions and 9 deletions
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
|
// The Discord API version used for the REST and Websocket API.
|
||||||
|
var ApiVersion = "6"
|
||||||
|
|
||||||
// Known Discord API Endpoints.
|
// Known Discord API Endpoints.
|
||||||
var (
|
var (
|
||||||
EndpointStatus = "https://status.discordapp.com/api/v2/"
|
EndpointStatus = "https://status.discordapp.com/api/v2/"
|
||||||
|
@ -19,7 +22,7 @@ var (
|
||||||
EndpointSmUpcoming = EndpointSm + "upcoming.json"
|
EndpointSmUpcoming = EndpointSm + "upcoming.json"
|
||||||
|
|
||||||
EndpointDiscord = "https://discordapp.com/"
|
EndpointDiscord = "https://discordapp.com/"
|
||||||
EndpointAPI = EndpointDiscord + "api/"
|
EndpointAPI = EndpointDiscord + "api/v" + ApiVersion + "/"
|
||||||
EndpointGuilds = EndpointAPI + "guilds/"
|
EndpointGuilds = EndpointAPI + "guilds/"
|
||||||
EndpointChannels = EndpointAPI + "channels/"
|
EndpointChannels = EndpointAPI + "channels/"
|
||||||
EndpointUsers = EndpointAPI + "users/"
|
EndpointUsers = EndpointAPI + "users/"
|
||||||
|
|
16
message.go
16
message.go
|
@ -15,6 +15,19 @@ import (
|
||||||
"strings"
|
"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.
|
// A Message stores all data related to a specific Discord message.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -30,6 +43,7 @@ type Message struct {
|
||||||
Embeds []*MessageEmbed `json:"embeds"`
|
Embeds []*MessageEmbed `json:"embeds"`
|
||||||
Mentions []*User `json:"mentions"`
|
Mentions []*User `json:"mentions"`
|
||||||
Reactions []*MessageReactions `json:"reactions"`
|
Reactions []*MessageReactions `json:"reactions"`
|
||||||
|
Type MessageType `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// File stores info about files you e.g. send in messages.
|
// 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 {
|
content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string {
|
||||||
channel, err := s.State.Channel(mention[2 : len(mention)-1])
|
channel, err := s.State.Channel(mention[2 : len(mention)-1])
|
||||||
if err != nil || channel.Type == "voice" {
|
if err != nil || channel.Type == ChannelTypeGuildVoice {
|
||||||
return mention
|
return mention
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
state.go
4
state.go
|
@ -427,7 +427,7 @@ func (s *State) ChannelAdd(channel *Channel) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.IsPrivate {
|
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
|
||||||
s.PrivateChannels = append(s.PrivateChannels, channel)
|
s.PrivateChannels = append(s.PrivateChannels, channel)
|
||||||
} else {
|
} else {
|
||||||
guild, ok := s.guildMap[channel.GuildID]
|
guild, ok := s.guildMap[channel.GuildID]
|
||||||
|
@ -454,7 +454,7 @@ func (s *State) ChannelRemove(channel *Channel) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.IsPrivate {
|
if channel.Type == ChannelTypeDM || channel.Type == ChannelTypeGroupDM {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
|
16
structs.go
16
structs.go
|
@ -144,18 +144,27 @@ type Invite struct {
|
||||||
Temporary bool `json:"temporary"`
|
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.
|
// A Channel holds all data related to an individual Discord channel.
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Topic string `json:"topic"`
|
Topic string `json:"topic"`
|
||||||
Type string `json:"type"`
|
Type ChannelType `json:"type"`
|
||||||
LastMessageID string `json:"last_message_id"`
|
LastMessageID string `json:"last_message_id"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
Bitrate int `json:"bitrate"`
|
Bitrate int `json:"bitrate"`
|
||||||
IsPrivate bool `json:"is_private"`
|
Recipients []*User `json:"recipient"`
|
||||||
Recipient *User `json:"recipient"`
|
|
||||||
Messages []*Message `json:"-"`
|
Messages []*Message `json:"-"`
|
||||||
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
|
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
|
||||||
}
|
}
|
||||||
|
@ -295,6 +304,7 @@ type Presence struct {
|
||||||
Game *Game `json:"game"`
|
Game *Game `json:"game"`
|
||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
|
Since *int `json:"since"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Game struct holds the name of the "playing .." game for a user
|
// A Game struct holds the name of the "playing .." game for a user
|
||||||
|
|
13
user.go
13
user.go
|
@ -37,3 +37,16 @@ func (u *User) AvatarURL(size string) string {
|
||||||
|
|
||||||
return URL + "?size=" + size
|
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
|
||||||
|
}
|
||||||
|
|
3
wsapi.go
3
wsapi.go
|
@ -15,7 +15,6 @@ import (
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -87,7 +86,7 @@ func (s *Session) Open() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the version and encoding to the URL
|
// 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{}
|
header := http.Header{}
|
||||||
|
|
Loading…
Reference in a new issue