|
@@ -173,6 +173,12 @@ func unmarshal(data []byte, v interface{}) error {
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
// Login asks the Discord server for an authentication token.
|
|
// Login asks the Discord server for an authentication token.
|
|
|
|
+//
|
|
|
|
+// NOTE: While email/pass authentication is supported by DiscordGo it is
|
|
|
|
+// HIGHLY DISCOURAGED by Discord. Please only use email/pass to obtain a token
|
|
|
|
+// and then use that authentication token for all future connections.
|
|
|
|
+// Also, doing any form of automation with a user (non Bot) account may result
|
|
|
|
+// in that account being permanently banned from Discord.
|
|
func (s *Session) Login(email, password string) (err error) {
|
|
func (s *Session) Login(email, password string) (err error) {
|
|
|
|
|
|
data := struct {
|
|
data := struct {
|
|
@@ -663,11 +669,28 @@ func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error) {
|
|
// userID : The ID of a User
|
|
// userID : The ID of a User
|
|
// days : The number of days of previous comments to delete.
|
|
// days : The number of days of previous comments to delete.
|
|
func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error) {
|
|
func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error) {
|
|
|
|
+ return s.GuildBanCreateWithReason(guildID, userID, "", days)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GuildBanCreateWithReason bans the given user from the given guild also providing a reaso.
|
|
|
|
+// guildID : The ID of a Guild.
|
|
|
|
+// userID : The ID of a User
|
|
|
|
+// reason : The reason for this ban
|
|
|
|
+// days : The number of days of previous comments to delete.
|
|
|
|
+func (s *Session) GuildBanCreateWithReason(guildID, userID, reason string, days int) (err error) {
|
|
|
|
|
|
uri := EndpointGuildBan(guildID, userID)
|
|
uri := EndpointGuildBan(guildID, userID)
|
|
|
|
|
|
|
|
+ queryParams := url.Values{}
|
|
if days > 0 {
|
|
if days > 0 {
|
|
- uri = fmt.Sprintf("%s?delete-message-days=%d", uri, days)
|
|
|
|
|
|
+ queryParams.Set("delete-message-days", strconv.Itoa(days))
|
|
|
|
+ }
|
|
|
|
+ if reason != "" {
|
|
|
|
+ queryParams.Set("reason", reason)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(queryParams) > 0 {
|
|
|
|
+ uri += "?" + queryParams.Encode()
|
|
}
|
|
}
|
|
|
|
|
|
_, err = s.RequestWithBucketID("PUT", uri, nil, EndpointGuildBan(guildID, ""))
|
|
_, err = s.RequestWithBucketID("PUT", uri, nil, EndpointGuildBan(guildID, ""))
|
|
@@ -1294,7 +1317,59 @@ func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend)
|
|
data.Embed.Type = "rich"
|
|
data.Embed.Type = "rich"
|
|
}
|
|
}
|
|
|
|
|
|
- response, err := s.RequestWithBucketID("POST", EndpointChannelMessages(channelID), data, EndpointChannelMessages(channelID))
|
|
|
|
|
|
+ endpoint := EndpointChannelMessages(channelID)
|
|
|
|
+
|
|
|
|
+ var response []byte
|
|
|
|
+ if data.File != nil {
|
|
|
|
+ body := &bytes.Buffer{}
|
|
|
|
+ bodywriter := multipart.NewWriter(body)
|
|
|
|
+
|
|
|
|
+ // What's a better way of doing this? Reflect? Generator? I'm open to suggestions
|
|
|
|
+
|
|
|
|
+ if data.Content != "" {
|
|
|
|
+ if err = bodywriter.WriteField("content", data.Content); err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if data.Embed != nil {
|
|
|
|
+ var embed []byte
|
|
|
|
+ embed, err = json.Marshal(data.Embed)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ err = bodywriter.WriteField("embed", string(embed))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if data.Tts {
|
|
|
|
+ if err = bodywriter.WriteField("tts", "true"); err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var writer io.Writer
|
|
|
|
+ writer, err = bodywriter.CreateFormFile("file", data.File.Name)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, err = io.Copy(writer, data.File.Reader)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ err = bodywriter.Close()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ response, err = s.request("POST", endpoint, bodywriter.FormDataContentType(), body.Bytes(), endpoint, 0)
|
|
|
|
+ } else {
|
|
|
|
+ response, err = s.RequestWithBucketID("POST", endpoint, data, endpoint)
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1427,48 +1502,18 @@ func (s *Session) ChannelMessagesPinned(channelID string) (st []*Message, err er
|
|
// channelID : The ID of a Channel.
|
|
// channelID : The ID of a Channel.
|
|
// name: The name of the file.
|
|
// name: The name of the file.
|
|
// io.Reader : A reader for the file contents.
|
|
// io.Reader : A reader for the file contents.
|
|
-func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (st *Message, err error) {
|
|
|
|
- return s.ChannelFileSendWithMessage(channelID, "", name, r)
|
|
|
|
|
|
+func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (*Message, error) {
|
|
|
|
+ return s.ChannelMessageSendComplex(channelID, &MessageSend{File: &File{Name: name, Reader: r}})
|
|
}
|
|
}
|
|
|
|
|
|
// ChannelFileSendWithMessage sends a file to the given channel with an message.
|
|
// ChannelFileSendWithMessage sends a file to the given channel with an message.
|
|
|
|
+// DEPRECATED. Use ChannelMessageSendComplex instead.
|
|
// channelID : The ID of a Channel.
|
|
// channelID : The ID of a Channel.
|
|
// content: Optional Message content.
|
|
// content: Optional Message content.
|
|
// name: The name of the file.
|
|
// name: The name of the file.
|
|
// io.Reader : A reader for the file contents.
|
|
// io.Reader : A reader for the file contents.
|
|
-func (s *Session) ChannelFileSendWithMessage(channelID, content string, name string, r io.Reader) (st *Message, err error) {
|
|
|
|
-
|
|
|
|
- body := &bytes.Buffer{}
|
|
|
|
- bodywriter := multipart.NewWriter(body)
|
|
|
|
-
|
|
|
|
- if len(content) != 0 {
|
|
|
|
- if err := bodywriter.WriteField("content", content); err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- writer, err := bodywriter.CreateFormFile("file", name)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _, err = io.Copy(writer, r)
|
|
|
|
- if err != nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- err = bodywriter.Close()
|
|
|
|
- if err != nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- response, err := s.request("POST", EndpointChannelMessages(channelID), bodywriter.FormDataContentType(), body.Bytes(), EndpointChannelMessages(channelID), 0)
|
|
|
|
- if err != nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- err = unmarshal(response, &st)
|
|
|
|
- return
|
|
|
|
|
|
+func (s *Session) ChannelFileSendWithMessage(channelID, content string, name string, r io.Reader) (*Message, error) {
|
|
|
|
+ return s.ChannelMessageSendComplex(channelID, &MessageSend{File: &File{Name: name, Reader: r}, Content: content})
|
|
}
|
|
}
|
|
|
|
|
|
// ChannelInvites returns an array of Invite structures for the given channel
|
|
// ChannelInvites returns an array of Invite structures for the given channel
|