diff --git a/Discord.C++/InteractionData.cpp b/Discord.C++/InteractionData.cpp index a5af960..0d04d50 100644 --- a/Discord.C++/InteractionData.cpp +++ b/Discord.C++/InteractionData.cpp @@ -1,20 +1,18 @@ #include "InteractionData.h" -#include "Logger.h" - DiscordCPP::InteractionData::InteractionData(const json& data, const std::string& token) : DiscordCPP::DiscordObject(token, data.at("id").get()), name(data.at("name").get()), type(static_cast(data.at("type").get())) { - if (has_value(data, "resolved")) { - resolved_data = InteractionResolvedData(data.at("resolved"), token); - } if (has_value(data, "options")) { for (const json& option : data.at("options")) { options.push_back(InteractionDataOptionHelper::interaction_data_option_from_json(option)); } } guild_id = get_optional(data, "guild_id"); + if (has_value(data, "resolved")) { + resolved_data = InteractionResolvedData(data.at("resolved"), guild_id.value_or(""), token); + } custom_id = get_optional(data, "custom_id"); target_id = get_optional(data, "target_id"); // component_type diff --git a/Discord.C++/InteractionResolvedData.cpp b/Discord.C++/InteractionResolvedData.cpp index dc8e7e8..bb6485a 100644 --- a/Discord.C++/InteractionResolvedData.cpp +++ b/Discord.C++/InteractionResolvedData.cpp @@ -1,6 +1,8 @@ #include "InteractionResolvedData.h" -DiscordCPP::InteractionResolvedData::InteractionResolvedData(const json& data, const std::string& token) { +#include "Role.h" + +DiscordCPP::InteractionResolvedData::InteractionResolvedData(const json& data, const std::string& guild_id, const std::string& token) { if (has_value(data, "users")) { for (auto [key, value] : data["users"].items()) { users.insert(std::make_pair(key, User(value, token))); @@ -13,7 +15,11 @@ DiscordCPP::InteractionResolvedData::InteractionResolvedData(const json& data, c } } - // roles + if (has_value(data, "roles")) { + for (auto [key, value] : data["roles"].items()) { + roles.insert(std::make_pair(key, Role(value, guild_id, token))); + } + } if (has_value(data, "channels")) { for (auto [key, value] : data["channels"].items()) { diff --git a/Discord.C++/InteractionResolvedData.h b/Discord.C++/InteractionResolvedData.h index 2648114..c046c87 100644 --- a/Discord.C++/InteractionResolvedData.h +++ b/Discord.C++/InteractionResolvedData.h @@ -1,13 +1,16 @@ #pragma once #include +#include #include "Channel.h" #include "ChannelHelper.h" #include "Member.h" #include "Message.h" +#include "Role.h" namespace DiscordCPP { + class InteractionResolvedData { private: /// Map of user ids and user objects. @@ -16,7 +19,8 @@ class InteractionResolvedData { /// Map of user ids and member objects. std::map members; - // roles + /// Map of role ids and role objects. + std::map roles; /// Map of channel ids and channel objects. std::map channels; @@ -27,7 +31,7 @@ class InteractionResolvedData { // attachments public: - DLL_EXPORT InteractionResolvedData(const json& data, const std::string& token); + DLL_EXPORT InteractionResolvedData(const json& data, const std::string& guild_id, const std::string& token); /// @return Map of user ids and user objects. DLL_EXPORT std::map get_users() { return users; } @@ -35,6 +39,9 @@ class InteractionResolvedData { /// @return Map of user ids and member objects. DLL_EXPORT std::map get_members() { return members; } + /// @return Map of role ids and role objects. + std::map get_roles() { return roles; } + /// @return Map of channel ids and channel objects. DLL_EXPORT std::map get_channels() { return channels; } diff --git a/test_bot/main.cpp b/test_bot/main.cpp index abbe16b..ba4b8bf 100644 --- a/test_bot/main.cpp +++ b/test_bot/main.cpp @@ -2,10 +2,6 @@ #include #include -#include "ApplicationCommand.h" -#include "ApplicationCommandOption.h" -#include "InteractionData.h" - #ifndef _WIN32 #include #endif