Skip to content

Commit

Permalink
feat: Added support for application emojis (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Jul 22, 2024
1 parent feafd62 commit ced36fd
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
49 changes: 49 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,55 @@ class DPP_EXPORT cluster {
*/
void guild_emoji_delete(snowflake guild_id, snowflake emoji_id, command_completion_event_t callback = utility::log_error());

/**
* @brief List all Application Emojis
*
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::emoji_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().
*/
void application_emojis_get(command_completion_event_t callback = utility::log_error());

/**
* @brief Get an Application Emoji
*
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
* @param emoji_id The ID of the Emoji to get.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::emoji 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().
*/
void application_emoji_get(snowflake emoji_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Create an Application Emoji
*
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
* @param newemoji The emoji to create
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::emoji 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().
*/
void application_emoji_create(const class emoji& newemoji, command_completion_event_t callback = utility::log_error());

/**
* @brief Edit an Application Emoji
*
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
* @param newemoji The emoji to edit
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::emoji 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().
*/
void application_emoji_edit(const class emoji& newemoji, command_completion_event_t callback = utility::log_error());

/**
* @brief Delete an Application Emoji
*
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
* @param emoji_id The emoji's ID to delete.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::confirmation 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().
*/
void application_emoji_delete(snowflake emoji_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Get prune counts
*
Expand Down
54 changes: 54 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,60 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_emojis_get(snowflake guild_id);

/**
* @brief List all Application Emojis
*
* @see dpp::cluster::application_emojis_get
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
* @return emoji_map returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_application_emojis_get();

/**
* @brief Get an Application Emoji
*
* @see dpp::cluster::application_emoji_get
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
* @param emoji_id The ID of the Emoji to get.
* @return emoji returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_get(snowflake emoji_id);

/**
* @brief Create an Application Emoji
*
* @see dpp::cluster::application_emoji_create
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
* @param newemoji The emoji to create
* @return emoji returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_create(const class emoji& newemoji);

/**
* @brief Edit an Application Emoji
*
* @see dpp::cluster::application_emoji_edit
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
* @param newemoji The emoji to edit
* @return emoji returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_edit(const class emoji& newemoji);

/**
* @brief Delete an Application Emoji
*
* @see dpp::cluster::application_emoji_delete
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
* @param emoji_id The emoji's ID to delete.
* @return confirmation returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_delete(snowflake emoji_id);

/**
* @brief Returns all entitlements for a given app, active and expired.
*
Expand Down
69 changes: 69 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,75 @@ emoji guild_emoji_get_sync(snowflake guild_id, snowflake emoji_id);
*/
emoji_map guild_emojis_get_sync(snowflake guild_id);

/**
* @brief List all Application Emojis
*
* @see dpp::cluster::application_emojis_get
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
* @return emoji_map returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
emoji_map application_emojis_get_sync();

/**
* @brief Get an Application Emoji
*
* @see dpp::cluster::application_emoji_get
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
* @param emoji_id The ID of the Emoji to get.
* @return emoji returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
emoji application_emoji_get_sync(snowflake emoji_id);

/**
* @brief Create an Application Emoji
*
* @see dpp::cluster::application_emoji_create
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
* @param newemoji The emoji to create
* @return emoji returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
emoji application_emoji_create_sync(const class emoji& newemoji);

/**
* @brief Edit an Application Emoji
*
* @see dpp::cluster::application_emoji_edit
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
* @param newemoji The emoji to edit
* @return emoji returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
emoji application_emoji_edit_sync(const class emoji& newemoji);

/**
* @brief Delete an Application Emoji
*
* @see dpp::cluster::application_emoji_delete
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
* @param emoji_id The emoji's ID to delete.
* @return confirmation returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
confirmation application_emoji_delete_sync(snowflake emoji_id);

/**
* @brief Returns all entitlements for a given app, active and expired.
*
Expand Down
39 changes: 39 additions & 0 deletions src/dpp/cluster/emoji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,43 @@ void cluster::guild_emojis_get(snowflake guild_id, command_completion_event_t ca
rest_request_list<emoji>(this, API_PATH "/guilds", std::to_string(guild_id), "emojis", m_get, "", callback);
}

//me.id.str()

void cluster::application_emojis_get(command_completion_event_t callback) {
/* Because Discord can't be consistent, we can't just do `rest_request_list<emoji>` because all items are behind `items`.
* so now we end up with this duplicating `rest_request_list` because we need to iterate the `items` array! Thanks Discord!
*/
post_rest(API_PATH "/applications", me.id.str(), "emojis", m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
std::unordered_map<snowflake, emoji> list;
confirmation_callback_t e(this, confirmation(), http);
const std::string key{"id"};
if (!e.is_error()) {
// No const for `fill_from_json`.
auto emojis_list = j["items"];
for (auto & curr_item : emojis_list) {
list[snowflake_not_null(&curr_item, key.c_str())] = emoji().fill_from_json(&curr_item);
}
}
if (callback) {
callback(confirmation_callback_t(this, list, http));
}
});
}

void cluster::application_emoji_get(snowflake emoji_id, command_completion_event_t callback) {
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis/" + emoji_id.str(), m_get, "", callback);
}

void cluster::application_emoji_create(const class emoji& newemoji, command_completion_event_t callback) {
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis", m_post, newemoji.build_json(), callback);
}

void cluster::application_emoji_edit(const class emoji& newemoji, command_completion_event_t callback) {
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis/" + newemoji.id.str(), m_patch, newemoji.build_json(), callback);
}

void cluster::application_emoji_delete(snowflake emoji_id, command_completion_event_t callback) {
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "emojis/" + emoji_id.str(), m_delete, "", callback);
}

} // namespace dpp
20 changes: 20 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ async<confirmation_callback_t> cluster::co_guild_emojis_get(snowflake guild_id)
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_emojis_get), guild_id };
}

async<confirmation_callback_t> cluster::co_application_emojis_get() {
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::application_emojis_get) };
}

async<confirmation_callback_t> cluster::co_application_emoji_get(snowflake emoji_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_get), emoji_id };
}

async<confirmation_callback_t> cluster::co_application_emoji_create(const class emoji& newemoji) {
return async{ this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_create), newemoji };
}

async<confirmation_callback_t> cluster::co_application_emoji_edit(const class emoji& newemoji) {
return async{ this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_edit), newemoji };
}

async<confirmation_callback_t> cluster::co_application_emoji_delete(snowflake emoji_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_delete), emoji_id };
}

async<confirmation_callback_t> cluster::co_entitlements_get(snowflake user_id, const std::vector<snowflake>& sku_ids, snowflake before_id, snowflake after_id, uint8_t limit, snowflake guild_id, bool exclude_ended) {
return async{ this, static_cast<void (cluster::*)(snowflake, const std::vector<snowflake>&, snowflake, snowflake, uint8_t, snowflake, bool, command_completion_event_t)>(&cluster::entitlements_get), user_id, sku_ids, before_id, after_id, limit, guild_id, exclude_ended };
}
Expand Down
20 changes: 20 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ emoji_map cluster::guild_emojis_get_sync(snowflake guild_id) {
return dpp::sync<emoji_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_emojis_get), guild_id);
}

emoji_map cluster::application_emojis_get_sync() {
return dpp::sync<emoji_map>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::application_emojis_get));
}

emoji cluster::application_emoji_get_sync(snowflake emoji_id) {
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_get), emoji_id);
}

emoji cluster::application_emoji_create_sync(const class emoji& newemoji) {
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_create), newemoji);
}

emoji cluster::application_emoji_edit_sync(const class emoji& newemoji) {
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_edit), newemoji);
}

confirmation cluster::application_emoji_delete_sync(snowflake emoji_id) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_delete), emoji_id);
}

entitlement_map cluster::entitlements_get_sync(snowflake user_id, const std::vector<snowflake>& sku_ids, snowflake before_id, snowflake after_id, uint8_t limit, snowflake guild_id, bool exclude_ended) {
return dpp::sync<entitlement_map>(this, static_cast<void (cluster::*)(snowflake, const std::vector<snowflake>&, snowflake, snowflake, uint8_t, snowflake, bool, command_completion_event_t)>(&cluster::entitlements_get), user_id, sku_ids, before_id, after_id, limit, guild_id, exclude_ended);
}
Expand Down

0 comments on commit ced36fd

Please sign in to comment.