Skip to content

Commit ced36fd

Browse files
authored
feat: Added support for application emojis (#1207)
1 parent feafd62 commit ced36fd

File tree

6 files changed

+251
-0
lines changed

6 files changed

+251
-0
lines changed

include/dpp/cluster.h

+49
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,55 @@ class DPP_EXPORT cluster {
27322732
*/
27332733
void guild_emoji_delete(snowflake guild_id, snowflake emoji_id, command_completion_event_t callback = utility::log_error());
27342734

2735+
/**
2736+
* @brief List all Application Emojis
2737+
*
2738+
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
2739+
* @param callback Function to call when the API call completes.
2740+
* 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().
2741+
*/
2742+
void application_emojis_get(command_completion_event_t callback = utility::log_error());
2743+
2744+
/**
2745+
* @brief Get an Application Emoji
2746+
*
2747+
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
2748+
* @param emoji_id The ID of the Emoji to get.
2749+
* @param callback Function to call when the API call completes.
2750+
* 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().
2751+
*/
2752+
void application_emoji_get(snowflake emoji_id, command_completion_event_t callback = utility::log_error());
2753+
2754+
/**
2755+
* @brief Create an Application Emoji
2756+
*
2757+
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
2758+
* @param newemoji The emoji to create
2759+
* @param callback Function to call when the API call completes.
2760+
* 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().
2761+
*/
2762+
void application_emoji_create(const class emoji& newemoji, command_completion_event_t callback = utility::log_error());
2763+
2764+
/**
2765+
* @brief Edit an Application Emoji
2766+
*
2767+
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
2768+
* @param newemoji The emoji to edit
2769+
* @param callback Function to call when the API call completes.
2770+
* 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().
2771+
*/
2772+
void application_emoji_edit(const class emoji& newemoji, command_completion_event_t callback = utility::log_error());
2773+
2774+
/**
2775+
* @brief Delete an Application Emoji
2776+
*
2777+
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
2778+
* @param emoji_id The emoji's ID to delete.
2779+
* @param callback Function to call when the API call completes.
2780+
* 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().
2781+
*/
2782+
void application_emoji_delete(snowflake emoji_id, command_completion_event_t callback = utility::log_error());
2783+
27352784
/**
27362785
* @brief Get prune counts
27372786
*

include/dpp/cluster_coro_calls.h

+54
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,60 @@
708708
*/
709709
[[nodiscard]] async<confirmation_callback_t> co_guild_emojis_get(snowflake guild_id);
710710

711+
/**
712+
* @brief List all Application Emojis
713+
*
714+
* @see dpp::cluster::application_emojis_get
715+
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
716+
* @return emoji_map returned object on completion
717+
* \memberof dpp::cluster
718+
*/
719+
[[nodiscard]] async<confirmation_callback_t> co_application_emojis_get();
720+
721+
/**
722+
* @brief Get an Application Emoji
723+
*
724+
* @see dpp::cluster::application_emoji_get
725+
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
726+
* @param emoji_id The ID of the Emoji to get.
727+
* @return emoji returned object on completion
728+
* \memberof dpp::cluster
729+
*/
730+
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_get(snowflake emoji_id);
731+
732+
/**
733+
* @brief Create an Application Emoji
734+
*
735+
* @see dpp::cluster::application_emoji_create
736+
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
737+
* @param newemoji The emoji to create
738+
* @return emoji returned object on completion
739+
* \memberof dpp::cluster
740+
*/
741+
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_create(const class emoji& newemoji);
742+
743+
/**
744+
* @brief Edit an Application Emoji
745+
*
746+
* @see dpp::cluster::application_emoji_edit
747+
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
748+
* @param newemoji The emoji to edit
749+
* @return emoji returned object on completion
750+
* \memberof dpp::cluster
751+
*/
752+
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_edit(const class emoji& newemoji);
753+
754+
/**
755+
* @brief Delete an Application Emoji
756+
*
757+
* @see dpp::cluster::application_emoji_delete
758+
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
759+
* @param emoji_id The emoji's ID to delete.
760+
* @return confirmation returned object on completion
761+
* \memberof dpp::cluster
762+
*/
763+
[[nodiscard]] async<confirmation_callback_t> co_application_emoji_delete(snowflake emoji_id);
764+
711765
/**
712766
* @brief Returns all entitlements for a given app, active and expired.
713767
*

include/dpp/cluster_sync_calls.h

+69
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,75 @@ emoji guild_emoji_get_sync(snowflake guild_id, snowflake emoji_id);
879879
*/
880880
emoji_map guild_emojis_get_sync(snowflake guild_id);
881881

882+
/**
883+
* @brief List all Application Emojis
884+
*
885+
* @see dpp::cluster::application_emojis_get
886+
* @see https://discord.com/developers/docs/resources/emoji#list-application-emojis
887+
* @return emoji_map returned object on completion
888+
* \memberof dpp::cluster
889+
* @throw dpp::rest_exception upon failure to execute REST function
890+
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
891+
* Avoid direct use of this function inside an event handler.
892+
*/
893+
emoji_map application_emojis_get_sync();
894+
895+
/**
896+
* @brief Get an Application Emoji
897+
*
898+
* @see dpp::cluster::application_emoji_get
899+
* @see https://discord.com/developers/docs/resources/emoji#get-application-emoji
900+
* @param emoji_id The ID of the Emoji to get.
901+
* @return emoji returned object on completion
902+
* \memberof dpp::cluster
903+
* @throw dpp::rest_exception upon failure to execute REST function
904+
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
905+
* Avoid direct use of this function inside an event handler.
906+
*/
907+
emoji application_emoji_get_sync(snowflake emoji_id);
908+
909+
/**
910+
* @brief Create an Application Emoji
911+
*
912+
* @see dpp::cluster::application_emoji_create
913+
* @see https://discord.com/developers/docs/resources/emoji#create-application-emoji
914+
* @param newemoji The emoji to create
915+
* @return emoji returned object on completion
916+
* \memberof dpp::cluster
917+
* @throw dpp::rest_exception upon failure to execute REST function
918+
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
919+
* Avoid direct use of this function inside an event handler.
920+
*/
921+
emoji application_emoji_create_sync(const class emoji& newemoji);
922+
923+
/**
924+
* @brief Edit an Application Emoji
925+
*
926+
* @see dpp::cluster::application_emoji_edit
927+
* @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji
928+
* @param newemoji The emoji to edit
929+
* @return emoji returned object on completion
930+
* \memberof dpp::cluster
931+
* @throw dpp::rest_exception upon failure to execute REST function
932+
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
933+
* Avoid direct use of this function inside an event handler.
934+
*/
935+
emoji application_emoji_edit_sync(const class emoji& newemoji);
936+
937+
/**
938+
* @brief Delete an Application Emoji
939+
*
940+
* @see dpp::cluster::application_emoji_delete
941+
* @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji
942+
* @param emoji_id The emoji's ID to delete.
943+
* @return confirmation returned object on completion
944+
* \memberof dpp::cluster
945+
* @throw dpp::rest_exception upon failure to execute REST function
946+
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
947+
* Avoid direct use of this function inside an event handler.
948+
*/
949+
confirmation application_emoji_delete_sync(snowflake emoji_id);
950+
882951
/**
883952
* @brief Returns all entitlements for a given app, active and expired.
884953
*

src/dpp/cluster/emoji.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,43 @@ void cluster::guild_emojis_get(snowflake guild_id, command_completion_event_t ca
4242
rest_request_list<emoji>(this, API_PATH "/guilds", std::to_string(guild_id), "emojis", m_get, "", callback);
4343
}
4444

45+
//me.id.str()
46+
47+
void cluster::application_emojis_get(command_completion_event_t callback) {
48+
/* Because Discord can't be consistent, we can't just do `rest_request_list<emoji>` because all items are behind `items`.
49+
* so now we end up with this duplicating `rest_request_list` because we need to iterate the `items` array! Thanks Discord!
50+
*/
51+
post_rest(API_PATH "/applications", me.id.str(), "emojis", m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
52+
std::unordered_map<snowflake, emoji> list;
53+
confirmation_callback_t e(this, confirmation(), http);
54+
const std::string key{"id"};
55+
if (!e.is_error()) {
56+
// No const for `fill_from_json`.
57+
auto emojis_list = j["items"];
58+
for (auto & curr_item : emojis_list) {
59+
list[snowflake_not_null(&curr_item, key.c_str())] = emoji().fill_from_json(&curr_item);
60+
}
61+
}
62+
if (callback) {
63+
callback(confirmation_callback_t(this, list, http));
64+
}
65+
});
66+
}
67+
68+
void cluster::application_emoji_get(snowflake emoji_id, command_completion_event_t callback) {
69+
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis/" + emoji_id.str(), m_get, "", callback);
70+
}
71+
72+
void cluster::application_emoji_create(const class emoji& newemoji, command_completion_event_t callback) {
73+
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis", m_post, newemoji.build_json(), callback);
74+
}
75+
76+
void cluster::application_emoji_edit(const class emoji& newemoji, command_completion_event_t callback) {
77+
rest_request<emoji>(this, API_PATH "/applications", me.id.str(), "emojis/" + newemoji.id.str(), m_patch, newemoji.build_json(), callback);
78+
}
79+
80+
void cluster::application_emoji_delete(snowflake emoji_id, command_completion_event_t callback) {
81+
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "emojis/" + emoji_id.str(), m_delete, "", callback);
82+
}
83+
4584
} // namespace dpp

src/dpp/cluster_coro_calls.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,26 @@ async<confirmation_callback_t> cluster::co_guild_emojis_get(snowflake guild_id)
263263
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_emojis_get), guild_id };
264264
}
265265

266+
async<confirmation_callback_t> cluster::co_application_emojis_get() {
267+
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::application_emojis_get) };
268+
}
269+
270+
async<confirmation_callback_t> cluster::co_application_emoji_get(snowflake emoji_id) {
271+
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_get), emoji_id };
272+
}
273+
274+
async<confirmation_callback_t> cluster::co_application_emoji_create(const class emoji& newemoji) {
275+
return async{ this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_create), newemoji };
276+
}
277+
278+
async<confirmation_callback_t> cluster::co_application_emoji_edit(const class emoji& newemoji) {
279+
return async{ this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_edit), newemoji };
280+
}
281+
282+
async<confirmation_callback_t> cluster::co_application_emoji_delete(snowflake emoji_id) {
283+
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_delete), emoji_id };
284+
}
285+
266286
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) {
267287
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 };
268288
}

src/dpp/cluster_sync_calls.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ emoji_map cluster::guild_emojis_get_sync(snowflake guild_id) {
261261
return dpp::sync<emoji_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_emojis_get), guild_id);
262262
}
263263

264+
emoji_map cluster::application_emojis_get_sync() {
265+
return dpp::sync<emoji_map>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::application_emojis_get));
266+
}
267+
268+
emoji cluster::application_emoji_get_sync(snowflake emoji_id) {
269+
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_get), emoji_id);
270+
}
271+
272+
emoji cluster::application_emoji_create_sync(const class emoji& newemoji) {
273+
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_create), newemoji);
274+
}
275+
276+
emoji cluster::application_emoji_edit_sync(const class emoji& newemoji) {
277+
return dpp::sync<emoji>(this, static_cast<void (cluster::*)(const class emoji&, command_completion_event_t)>(&cluster::application_emoji_edit), newemoji);
278+
}
279+
280+
confirmation cluster::application_emoji_delete_sync(snowflake emoji_id) {
281+
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::application_emoji_delete), emoji_id);
282+
}
283+
264284
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) {
265285
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);
266286
}

0 commit comments

Comments
 (0)