diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index b55afd3b65..7a5ebfd63b 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -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 * diff --git a/include/dpp/cluster_coro_calls.h b/include/dpp/cluster_coro_calls.h index bc460605c6..0ea93fc9b6 100644 --- a/include/dpp/cluster_coro_calls.h +++ b/include/dpp/cluster_coro_calls.h @@ -708,6 +708,60 @@ */ [[nodiscard]] async 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 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 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 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 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 co_application_emoji_delete(snowflake emoji_id); + /** * @brief Returns all entitlements for a given app, active and expired. * diff --git a/include/dpp/cluster_sync_calls.h b/include/dpp/cluster_sync_calls.h index 1086c4926d..302e57111a 100644 --- a/include/dpp/cluster_sync_calls.h +++ b/include/dpp/cluster_sync_calls.h @@ -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. * diff --git a/src/dpp/cluster/emoji.cpp b/src/dpp/cluster/emoji.cpp index 3e23da45f2..626707d13c 100644 --- a/src/dpp/cluster/emoji.cpp +++ b/src/dpp/cluster/emoji.cpp @@ -42,4 +42,43 @@ void cluster::guild_emojis_get(snowflake guild_id, command_completion_event_t ca rest_request_list(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` 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 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(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(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(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(this, API_PATH "/applications", me.id.str(), "emojis/" + emoji_id.str(), m_delete, "", callback); +} + } // namespace dpp diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index ad48ee1497..d56b3b1013 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -263,6 +263,26 @@ async cluster::co_guild_emojis_get(snowflake guild_id) return async{ this, static_cast(&cluster::guild_emojis_get), guild_id }; } +async cluster::co_application_emojis_get() { + return async{ this, static_cast(&cluster::application_emojis_get) }; +} + +async cluster::co_application_emoji_get(snowflake emoji_id) { + return async{ this, static_cast(&cluster::application_emoji_get), emoji_id }; +} + +async cluster::co_application_emoji_create(const class emoji& newemoji) { + return async{ this, static_cast(&cluster::application_emoji_create), newemoji }; +} + +async cluster::co_application_emoji_edit(const class emoji& newemoji) { + return async{ this, static_cast(&cluster::application_emoji_edit), newemoji }; +} + +async cluster::co_application_emoji_delete(snowflake emoji_id) { + return async{ this, static_cast(&cluster::application_emoji_delete), emoji_id }; +} + async cluster::co_entitlements_get(snowflake user_id, const std::vector& sku_ids, snowflake before_id, snowflake after_id, uint8_t limit, snowflake guild_id, bool exclude_ended) { return async{ this, static_cast&, 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 }; } diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index 70f3618f02..8aa69aba77 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -261,6 +261,26 @@ emoji_map cluster::guild_emojis_get_sync(snowflake guild_id) { return dpp::sync(this, static_cast(&cluster::guild_emojis_get), guild_id); } +emoji_map cluster::application_emojis_get_sync() { + return dpp::sync(this, static_cast(&cluster::application_emojis_get)); +} + +emoji cluster::application_emoji_get_sync(snowflake emoji_id) { + return dpp::sync(this, static_cast(&cluster::application_emoji_get), emoji_id); +} + +emoji cluster::application_emoji_create_sync(const class emoji& newemoji) { + return dpp::sync(this, static_cast(&cluster::application_emoji_create), newemoji); +} + +emoji cluster::application_emoji_edit_sync(const class emoji& newemoji) { + return dpp::sync(this, static_cast(&cluster::application_emoji_edit), newemoji); +} + +confirmation cluster::application_emoji_delete_sync(snowflake emoji_id) { + return dpp::sync(this, static_cast(&cluster::application_emoji_delete), emoji_id); +} + entitlement_map cluster::entitlements_get_sync(snowflake user_id, const std::vector& sku_ids, snowflake before_id, snowflake after_id, uint8_t limit, snowflake guild_id, bool exclude_ended) { return dpp::sync(this, static_cast&, 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); }