From 1552dcb143edbc82c1ef49169f20fd1b5441b688 Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 26 Aug 2019 23:47:50 +0200 Subject: Replace bwmarrin/discordgo with matterbridge/discordgo (#878) Needed for #872 --- vendor/github.com/bwmarrin/discordgo/restapi.go | 71 +++++++++++++++++++++++-- vendor/github.com/bwmarrin/discordgo/structs.go | 2 +- vendor/modules.txt | 2 +- 3 files changed, 70 insertions(+), 5 deletions(-) (limited to 'vendor') diff --git a/vendor/github.com/bwmarrin/discordgo/restapi.go b/vendor/github.com/bwmarrin/discordgo/restapi.go index 84a2a31e..ebeea876 100644 --- a/vendor/github.com/bwmarrin/discordgo/restapi.go +++ b/vendor/github.com/bwmarrin/discordgo/restapi.go @@ -675,7 +675,7 @@ func (s *Session) GuildLeave(guildID string) (err error) { return } -// GuildBans returns an array of User structures for all bans of a +// GuildBans returns an array of GuildBan structures for all bans of a // given guild. // guildID : The ID of a Guild. func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error) { @@ -2067,15 +2067,80 @@ func (s *Session) WebhookDeleteWithToken(webhookID, token string) (st *Webhook, // WebhookExecute executes a webhook. // webhookID: The ID of a webhook. // token : The auth token for the webhook -func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *WebhookParams) (err error) { +// wait : Wait for server to confirm the message arrival +// +// If `wait` is `false`, the returned *Message is always empty, because server +// does not provide the response data. +func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *WebhookParams) (st *Message, err error) { uri := EndpointWebhookToken(webhookID, token) if wait { uri += "?wait=true" } - _, err = s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken("", "")) + var response []byte + if data.File != nil { + body := &bytes.Buffer{} + bodywriter := multipart.NewWriter(body) + var payload []byte + payload, err = json.Marshal(data) + if err != nil { + return + } + + var p io.Writer + + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", `form-data; name="payload_json"`) + h.Set("Content-Type", "application/json") + + p, err = bodywriter.CreatePart(h) + if err != nil { + return + } + + if _, err = p.Write(payload); err != nil { + return + } + + { + file := data.File + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, quoteEscaper.Replace(file.Name))) + contentType := file.ContentType + if contentType == "" { + contentType = "application/octet-stream" + } + h.Set("Content-Type", contentType) + + p, err = bodywriter.CreatePart(h) + if err != nil { + return + } + + if _, err = io.Copy(p, file.Reader); err != nil { + return + } + } + + err = bodywriter.Close() + if err != nil { + return + } + + response, err = s.request("POST", uri, bodywriter.FormDataContentType(), body.Bytes(), EndpointWebhookToken("", ""), 0) + } else { + response, err = s.RequestWithBucketID("POST", uri, data, EndpointWebhookToken("", "")) + } + if err != nil { + return + } + if !wait { + return + } + + err = unmarshal(response, &st) return } diff --git a/vendor/github.com/bwmarrin/discordgo/structs.go b/vendor/github.com/bwmarrin/discordgo/structs.go index 4465ec52..29468a71 100644 --- a/vendor/github.com/bwmarrin/discordgo/structs.go +++ b/vendor/github.com/bwmarrin/discordgo/structs.go @@ -832,7 +832,7 @@ type WebhookParams struct { Username string `json:"username,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` TTS bool `json:"tts,omitempty"` - File string `json:"file,omitempty"` + File *File `json:"-"` Embeds []*MessageEmbed `json:"embeds,omitempty"` } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1416f316..80871d8c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,7 +23,7 @@ github.com/Rhymen/go-whatsapp/crypto/cbc github.com/Rhymen/go-whatsapp/crypto/curve25519 github.com/Rhymen/go-whatsapp/crypto/hkdf github.com/Rhymen/go-whatsapp/binary/token -# github.com/bwmarrin/discordgo v0.19.0 +# github.com/bwmarrin/discordgo v0.19.0 => github.com/matterbridge/discordgo v0.0.0-20190818085008-57c6e0fc2f40 github.com/bwmarrin/discordgo # github.com/d5/tengo v1.24.1 github.com/d5/tengo/script -- cgit v1.2.3