From 10195fcfbb5fc030dc24edd5f5202a52f57adc54 Mon Sep 17 00:00:00 2001 From: Aditya Diwakar Date: Wed, 5 Aug 2020 18:31:38 -0400 Subject: [PATCH 1/4] :sparkles: Add support for news channels Endpoint support added: - @/channels/:id/messages/:id/crosspost - publishes a message in a news channel to followers - @/channels/:id/followers - follows a news channel --- endpoints.go | 2 ++ restapi.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/endpoints.go b/endpoints.go index 0b337a1..88663fe 100644 --- a/endpoints.go +++ b/endpoints.go @@ -112,6 +112,8 @@ var ( EndpointChannelMessagesBulkDelete = func(cID string) string { return EndpointChannel(cID) + "/messages/bulk-delete" } EndpointChannelMessagesPins = func(cID string) string { return EndpointChannel(cID) + "/pins" } EndpointChannelMessagePin = func(cID, mID string) string { return EndpointChannel(cID) + "/pins/" + mID } + EndpointChannelMessageCrosspost = func(cID, mID string) string { return EndpointChannel(cID) + "/messages/" + mID + "/crosspost" } + EndpointChannelFollow = func(cID string) string { return EndpointChannel(cID) + "/followers" } EndpointGroupIcon = func(cID, hash string) string { return EndpointCDNChannelIcons + cID + "/" + hash + ".png" } diff --git a/restapi.go b/restapi.go index 69b7ceb..7eaee29 100644 --- a/restapi.go +++ b/restapi.go @@ -1790,6 +1790,38 @@ func (s *Session) ChannelPermissionDelete(channelID, targetID string) (err error return } +// ChannelMessageCrosspost cross posts a message in a news channel to followers +// of the channel +// channelID : The ID of a Channel +// messageID : The ID of a Message +func (s *Session) ChannelMessageCrosspost(channelID, messageID string) (st *Message, err error) { + + endpoint := EndpointChannelMessageCrosspost(channelID, messageID) + + body, err := s.RequestWithBucketID("POST", endpoint, nil, endpoint) + if err != nil { + return + } + + err = unmarshal(body, &st) + return +} + +// ChannelNewsFollow follows a news channel in the targetID +// channelID : The ID of a News Channel +// targetID : The ID of a Channel where the News Channel should post to +func (s *Session) ChannelNewsFollow(channelID, targetID string) (err error) { + + endpoint := EndpointChannelFollow(channelID) + + data := struct { + WebhookChannelID string `json:"webhook_channel_id"` + }{targetID} + + _, err = s.RequestWithBucketID("POST", endpoint, data, endpoint) + return +} + // ------------------------------------------------------------------------------------------------ // Functions specific to Discord Invites // ------------------------------------------------------------------------------------------------ From eb70c17733f3795f1cc40cd9b8db6c774deb20c0 Mon Sep 17 00:00:00 2001 From: Aditya Diwakar Date: Wed, 5 Aug 2020 18:54:12 -0400 Subject: [PATCH 2/4] Add support for retrieving Webhook ID --- restapi.go | 6 ++++-- structs.go | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/restapi.go b/restapi.go index 7eaee29..a0e85f8 100644 --- a/restapi.go +++ b/restapi.go @@ -1810,7 +1810,7 @@ func (s *Session) ChannelMessageCrosspost(channelID, messageID string) (st *Mess // ChannelNewsFollow follows a news channel in the targetID // channelID : The ID of a News Channel // targetID : The ID of a Channel where the News Channel should post to -func (s *Session) ChannelNewsFollow(channelID, targetID string) (err error) { +func (s *Session) ChannelNewsFollow(channelID, targetID string) (st *ChannelFollow, err error) { endpoint := EndpointChannelFollow(channelID) @@ -1818,7 +1818,9 @@ func (s *Session) ChannelNewsFollow(channelID, targetID string) (err error) { WebhookChannelID string `json:"webhook_channel_id"` }{targetID} - _, err = s.RequestWithBucketID("POST", endpoint, data, endpoint) + body, err := s.RequestWithBucketID("POST", endpoint, data, endpoint) + + err = unmarshal(body, &st) return } diff --git a/structs.go b/structs.go index aefda59..2590a8b 100644 --- a/structs.go +++ b/structs.go @@ -316,6 +316,11 @@ type ChannelEdit struct { RateLimitPerUser int `json:"rate_limit_per_user,omitempty"` } +type ChannelFollow struct { + ChannelID string `json:"channel_id"` + WebhookID string `json:"webhook_id"` +} + // A PermissionOverwrite holds permission overwrite data for a Channel type PermissionOverwrite struct { ID string `json:"id"` From 8648632fc838cac704830fa3c9d0215a4895c7cb Mon Sep 17 00:00:00 2001 From: Aditya Diwakar Date: Wed, 5 Aug 2020 19:02:11 -0400 Subject: [PATCH 3/4] Comment ChannelFollow struct --- structs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/structs.go b/structs.go index 2590a8b..afe9312 100644 --- a/structs.go +++ b/structs.go @@ -316,6 +316,7 @@ type ChannelEdit struct { RateLimitPerUser int `json:"rate_limit_per_user,omitempty"` } +// A ChannelFollow holds data returned after following a news channel type ChannelFollow struct { ChannelID string `json:"channel_id"` WebhookID string `json:"webhook_id"` From b7ef3c8e0f26595dfe55b14bfd0f018f83b67262 Mon Sep 17 00:00:00 2001 From: Aditya Diwakar Date: Thu, 6 Aug 2020 19:31:43 -0400 Subject: [PATCH 4/4] Handle error in ChannelNewsFollow --- restapi.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/restapi.go b/restapi.go index a0e85f8..e4cd6fa 100644 --- a/restapi.go +++ b/restapi.go @@ -1819,6 +1819,9 @@ func (s *Session) ChannelNewsFollow(channelID, targetID string) (st *ChannelFoll }{targetID} body, err := s.RequestWithBucketID("POST", endpoint, data, endpoint) + if err != nil { + return + } err = unmarshal(body, &st) return