Merge pull request #199 from VagantemNumen/bulk-delete
Add bulk delete endpoint to rest api
This commit is contained in:
commit
7d1ed7c738
2 changed files with 37 additions and 8 deletions
17
endpoints.go
17
endpoints.go
|
@ -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 }
|
||||
|
||||
|
|
28
restapi.go
28
restapi.go
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue