Skip to content

Commit 1b26ed3

Browse files
committed
feat: added before and limit to channel_pins_get
1 parent d34a3b5 commit 1b26ed3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

include/dpp/cluster.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,17 @@ class DPP_EXPORT cluster {
23792379
*/
23802380
void channel_pins_get(snowflake channel_id, command_completion_event_t callback);
23812381

2382+
/**
2383+
* @brief Get a channel's pins
2384+
* @see https://discord.com/developers/docs/resources/channel#get-pinned-messages
2385+
* @param channel_id Channel ID to get pins for
2386+
* @param before Get messages pinned before this timestamp.
2387+
* @param limit Max number of pins to return (1-50). Defaults to 50 if not set.
2388+
* @param callback Function to call when the API call completes.
2389+
* On success the callback will contain a dpp::message_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
2390+
*/
2391+
void channel_pins_get(snowflake channel_id, std::optional<time_t> before, std::optional<uint64_t> limit, command_completion_event_t callback);
2392+
23822393
/**
23832394
* @brief Adds a recipient to a Group DM using their access token
23842395
* @see https://discord.com/developers/docs/resources/channel#group-dm-add-recipient

src/dpp/cluster/message.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace dpp {
2525

26+
constexpr uint8_t GET_CHANNEL_PINS_MAX = 50;
27+
2628
void cluster::message_add_reaction(const struct message &m, const std::string &reaction, command_completion_event_t callback) {
2729
rest_request<confirmation>(this, API_PATH "/channels", std::to_string(m.channel_id), "messages/" + std::to_string(m.id) + "/reactions/" + utility::url_encode(reaction) + "/@me", m_put, "", callback);
2830
}
@@ -205,10 +207,25 @@ void cluster::poll_end(snowflake message_id, snowflake channel_id, command_compl
205207

206208

207209
void cluster::channel_pins_get(snowflake channel_id, command_completion_event_t callback) {
210+
channel_pins_get(channel_id, {}, {}, callback);
211+
}
212+
213+
void cluster::channel_pins_get(snowflake channel_id, std::optional<time_t> before, std::optional<uint64_t> limit, command_completion_event_t callback) {
214+
if (!limit.has_value())
215+
{
216+
limit = GET_CHANNEL_PINS_MAX;
217+
}
218+
219+
std::string parameters = "messages/pins?limit=" + std::to_string(limit.value());
220+
221+
if (before.has_value()) {
222+
parameters.append("&before=" + ts_to_string(before.value()));
223+
}
224+
208225
/* Have to do it like this because this now returns more than just a list.
209226
* It's now a structure containing the pinned items in "items" and then a boolean called "has_more".
210227
*/
211-
this->post_rest_multipart(API_PATH "/channels", std::to_string(channel_id), "messages/pins", m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
228+
this->post_rest_multipart(API_PATH "/channels", std::to_string(channel_id), parameters, m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
212229
std::unordered_map<snowflake, dpp::message_pin> list;
213230

214231
confirmation_callback_t e(this, confirmation(), http);

0 commit comments

Comments
 (0)