Merge branch 'develop' of https://github.com/bwmarrin/Discordgo into develop

This commit is contained in:
Bruce Marriner 2016-05-14 15:59:03 -05:00
commit dc3b3ea170
4 changed files with 63 additions and 18 deletions

View file

@ -73,14 +73,15 @@ var (
GUILD_ICON = func(gID, hash string) string { return GUILDS + gID + "/icons/" + hash + ".jpg" }
GUILD_SPLASH = func(gID, hash string) string { return GUILDS + gID + "/splashes/" + hash + ".jpg" }
CHANNEL = func(cID string) string { return CHANNELS + cID }
CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
CHANNEL_PERMISSION = func(cID, tID string) string { return CHANNELS + cID + "/permissions/" + tID }
CHANNEL_INVITES = func(cID string) string { return CHANNELS + cID + "/invites" }
CHANNEL_TYPING = func(cID string) string { return CHANNELS + cID + "/typing" }
CHANNEL_MESSAGES = func(cID string) string { return CHANNELS + cID + "/messages" }
CHANNEL_MESSAGE = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID }
CHANNEL_MESSAGE_ACK = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID + "/ack" }
CHANNEL = func(cID string) string { return CHANNELS + cID }
CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
CHANNEL_PERMISSION = func(cID, tID string) string { return CHANNELS + cID + "/permissions/" + tID }
CHANNEL_INVITES = func(cID string) string { return CHANNELS + cID + "/invites" }
CHANNEL_TYPING = func(cID string) string { return CHANNELS + cID + "/typing" }
CHANNEL_MESSAGES = func(cID string) string { return CHANNELS + cID + "/messages" }
CHANNEL_MESSAGE = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID }
CHANNEL_MESSAGE_ACK = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID + "/ack" }
CHANNEL_MESSAGES_BULK_DELETE = func(cID string) string { return CHANNEL(cID) + "/messages/bulk_delete" }
INVITE = func(iID string) string { return API + "invite/" + iID }

View file

@ -1107,6 +1107,34 @@ func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error)
return
}
// ChannelMessagesBulkDelete bulk deletes the messages from the channel for the provided messageIDs.
// If only one messageID is in the slice call channelMessageDelete funciton.
// If the slice is empty do nothing.
// channelID : The ID of the channel for the messages to delete.
// messages : The IDs of the messages to be deleted. A slice of string IDs. A maximum of 100 messages.
func (s *Session) ChannelMessagesBulkDelete(channelID string, messages []string) (err error) {
if len(messages) == 0 {
return
}
if len(messages) == 1 {
err = s.ChannelMessageDelete(channelID, messages[0])
return
}
if len(messages) > 100 {
messages = messages[:100]
}
data := struct {
Messages []string `json:"messages"`
}{messages}
_, err = s.Request("POST", CHANNEL_MESSAGES_BULK_DELETE(channelID), data)
return
}
// ChannelFileSend sends a file to the given channel.
// channelID : The ID of a Channel.
// io.Reader : A reader for the file contents.

View file

@ -253,6 +253,8 @@ type Presence struct {
// A Game struct holds the name of the "playing .." game for a user
type Game struct {
Name string `json:"name"`
Type int `json:"type"`
URL string `json:"url"`
}
// A Member stores user information for Guild members.

View file

@ -306,13 +306,9 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
}
}
type updateStatusGame struct {
Name string `json:"name"`
}
type updateStatusData struct {
IdleSince *int `json:"idle_since"`
Game *updateStatusGame `json:"game"`
IdleSince *int `json:"idle_since"`
Game *Game `json:"game"`
}
type updateStatusOp struct {
@ -320,10 +316,12 @@ type updateStatusOp struct {
Data updateStatusData `json:"d"`
}
// UpdateStatus is used to update the authenticated user's status.
// If idle>0 then set status to idle. If game>0 then set game.
// UpdateStreamingStatus is used to update the user's streaming status.
// If idle>0 then set status to idle.
// If game!="" then set game.
// If game!="" and url!="" then set the status type to streaming with the URL set.
// if otherwise, set status to active, and no game.
func (s *Session) UpdateStatus(idle int, game string) (err error) {
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) {
s.log(LogInformational, "called")
@ -339,7 +337,15 @@ func (s *Session) UpdateStatus(idle int, game string) (err error) {
}
if game != "" {
usd.Game = &updateStatusGame{game}
gameType := 0
if url != "" {
gameType = 1
}
usd.Game = &Game{
Name: game,
Type: gameType,
URL: url,
}
}
s.wsMutex.Lock()
@ -349,6 +355,14 @@ func (s *Session) UpdateStatus(idle int, game string) (err error) {
return
}
// UpdateStatus is used to update the user's status.
// If idle>0 then set status to idle.
// If game!="" then set game.
// if otherwise, set status to active, and no game.
func (s *Session) UpdateStatus(idle int, game string) (err error) {
return s.UpdateStreamingStatus(idle, game, "")
}
// onEvent is the "event handler" for all messages received on the
// Discord Gateway API websocket connection.
//