Skip to content

Commit 6267de0

Browse files
authored
Use new pin endpoints (#457)
* Use new pin endpoints * dumbass * topi didnt say anything so im pushing this hoping he notices and lets me know
1 parent 3bfbd77 commit 6267de0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

discord/message.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,13 @@ func (n *Nonce) UnmarshalJSON(b []byte) error {
421421

422422
return nil
423423
}
424+
425+
type ChannelPins struct {
426+
Items []MessagePin `json:"items"`
427+
HasMore bool `json:"has_more"`
428+
}
429+
430+
type MessagePin struct {
431+
PinnedAt time.Time `json:"pinned_at"`
432+
Message Message `json:"message"`
433+
}

rest/channels.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ type Channels interface {
4141
RemoveAllReactions(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error
4242
RemoveAllReactionsForEmoji(channelID snowflake.ID, messageID snowflake.ID, emoji string, opts ...RequestOpt) error
4343

44+
// Deprecated: Use GetChannelPins instead
4445
GetPinnedMessages(channelID snowflake.ID, opts ...RequestOpt) ([]discord.Message, error)
46+
47+
GetChannelPins(channelID snowflake.ID, before snowflake.ID, limit int, opts ...RequestOpt) (*discord.ChannelPins, error)
4548
PinMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error
4649
UnpinMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error
50+
4751
Follow(channelID snowflake.ID, targetChannelID snowflake.ID, opts ...RequestOpt) (*discord.FollowedChannel, error)
4852

4953
GetPollAnswerVotes(channelID snowflake.ID, messageID snowflake.ID, answerID int, after snowflake.ID, limit int, opts ...RequestOpt) ([]discord.User, error)
@@ -206,11 +210,24 @@ func (s *channelImpl) RemoveAllReactionsForEmoji(channelID snowflake.ID, message
206210
return s.client.Do(RemoveAllReactionsForEmoji.Compile(nil, channelID, messageID, emoji), nil, nil, opts...)
207211
}
208212

213+
// Deprecated: Use GetChannelPins instead
209214
func (s *channelImpl) GetPinnedMessages(channelID snowflake.ID, opts ...RequestOpt) (messages []discord.Message, err error) {
210215
err = s.client.Do(GetPinnedMessages.Compile(nil, channelID), nil, &messages, opts...)
211216
return
212217
}
213218

219+
func (s *channelImpl) GetChannelPins(channelID snowflake.ID, before snowflake.ID, limit int, opts ...RequestOpt) (pins *discord.ChannelPins, err error) {
220+
values := discord.QueryValues{}
221+
if before != 0 {
222+
values["before"] = before
223+
}
224+
if limit != 0 {
225+
values["limit"] = limit
226+
}
227+
err = s.client.Do(GetChannelPins.Compile(values, channelID), nil, &pins, opts...)
228+
return
229+
}
230+
214231
func (s *channelImpl) PinMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error {
215232
return s.client.Do(PinMessage.Compile(nil, channelID, messageID), nil, nil, opts...)
216233
}

rest/rest_endpoints.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,12 @@ var (
215215
DeleteMessage = NewEndpoint(http.MethodDelete, "/channels/{channel.id}/messages/{message.id}")
216216
BulkDeleteMessages = NewEndpoint(http.MethodPost, "/channels/{channel.id}/messages/bulk-delete")
217217

218+
// Deprecated: Use GetChannelPins instead
218219
GetPinnedMessages = NewEndpoint(http.MethodGet, "/channels/{channel.id}/pins")
219-
PinMessage = NewEndpoint(http.MethodPut, "/channels/{channel.id}/pins/{message.id}")
220-
UnpinMessage = NewEndpoint(http.MethodDelete, "/channels/{channel.id}/pins/{message.id}")
220+
221+
GetChannelPins = NewEndpoint(http.MethodGet, "/channels/{channel.id}/messages/pins")
222+
PinMessage = NewEndpoint(http.MethodPut, "/channels/{channel.id}/messages/pins/{message.id}")
223+
UnpinMessage = NewEndpoint(http.MethodDelete, "/channels/{channel.id}/messages/pins/{message.id}")
221224

222225
CrosspostMessage = NewEndpoint(http.MethodPost, "/channels/{channel.id}/messages/{message.id}/crosspost")
223226

0 commit comments

Comments
 (0)