From 71507966f6dc49c0845c7b2784d13a2446321535 Mon Sep 17 00:00:00 2001 From: Archie Jaskowicz Date: Thu, 19 Oct 2023 12:15:31 +0100 Subject: [PATCH] feat!: updated integration to now contain more information (#954) --- include/dpp/integration.h | 104 ++++++++++++++++++++------------------ src/dpp/integration.cpp | 71 +++++++++++++++----------- 2 files changed, 96 insertions(+), 79 deletions(-) diff --git a/include/dpp/integration.h b/include/dpp/integration.h index 6310c78bdb..98d5cb507d 100644 --- a/include/dpp/integration.h +++ b/include/dpp/integration.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace dpp { @@ -47,34 +48,30 @@ enum integration_type { * @brief Integration flags */ enum integration_flags { - /// Integration enabled - if_enabled = 0b00000001, - /// Integration syncing - if_syncing = 0b00000010, - /// Emoji integration - if_emoticons = 0b00000100, - /// Integration revoked - if_revoked = 0b00001000, - /// Kick users when their subscription expires - if_expire_kick = 0b00010000, + if_enabled = 0b00000001, //!< is this integration enabled + if_syncing = 0b00000010, //!< is this integration syncing @warning This is not provided for discord bot integrations. + if_emoticons = 0b00000100, //!< whether emoticons should be synced for this integration (twitch only currently) @warning This is not provided for discord bot integrations. + if_revoked = 0b00001000, //!< has this integration been revoked @warning This is not provided for discord bot integrations. + if_expire_kick = 0b00010000, //!< kick user when their subscription expires, otherwise only remove the role that is specified by `role_id`. @warning This is not provided for discord bot integrations. }; /** * @brief An application that has been integrated */ struct DPP_EXPORT integration_app { - /// Integration id - snowflake id; - /// Name - std::string name; - /// Icon - std::string icon; - /// Description - std::string description; - /// Integration summary @deprecated Removed by Discord - std::string summary; - /// Pointer to bot user - class user* bot; + snowflake id; //!< the id of the app + std::string name; //!< the name of the app + utility::iconhash icon; //!< the icon hash of the app + std::string description; //!< the description of the app + class user* bot; //!< the bot associated with this application +}; + +/** + * @brief The account information for an integration. + */ +struct DPP_EXPORT integration_account { + snowflake id; //!< id of the account + std::string name; //!< name of the account }; /** @@ -97,28 +94,17 @@ class DPP_EXPORT integration : public managed, public json_interface scopes; //!< the scopes the application has been authorized for /** Default constructor */ integration(); @@ -126,15 +112,35 @@ class DPP_EXPORT integration : public managed, public json_interfaceid = snowflake_not_null(j, "id"); - this->name = string_not_null(j, "name"); + + set_snowflake_not_null(j, "id", id); + set_string_not_null(j, "name", name); this->type = type_map[string_not_null(j, "type")]; + if (bool_not_null(j, "enabled")) { this->flags |= if_enabled; } if (bool_not_null(j, "syncing")) { this->flags |= if_syncing; } + + set_snowflake_not_null(j, "role_id", role_id); + if (bool_not_null(j, "enable_emoticons")) { this->flags |= if_emoticons; } - if (bool_not_null(j, "revoked")) { - this->flags |= if_revoked; - } if (int8_not_null(j, "expire_behavior")) { this->flags |= if_expire_kick; } - this->expire_grace_period = int32_not_null(j, "expire_grace_period"); - if (j->contains("user")) { - auto t = (*j)["user"]; - this->user_id = snowflake_not_null(&t, "user_id"); + + set_int32_not_null(j, "expire_grace_period", expire_grace_period); + + if(j->contains("user")) { + user_obj = user().fill_from_json(&((*j)["user"])); + } + + /* Should never be null, but best to check in-case they maybe change it */ + if(j->contains("account")) { + auto & ac = (*j)["account"]; + set_snowflake_not_null(&ac, "id", account.id); + set_string_not_null(&ac, "name", account.name); } + + set_ts_not_null(j, "synced_at", synced_at); + set_int32_not_null(j, "subscriber_count", subscriber_count); + + if (bool_not_null(j, "revoked")) { + this->flags |= if_revoked; + } + if (j->contains("application")) { auto & t = (*j)["application"]; - this->app.id = snowflake_not_null(&t, "id"); + set_snowflake_not_null(&t, "id", app.id); + set_string_not_null(&t, "name", app.name); + set_string_not_null(&t, "description", app.description); + set_iconhash_not_null(&t, "icon", app.icon); if (t.find("bot") != t.end()) { auto & b = t["bot"]; this->app.bot = dpp::find_user(snowflake_not_null(&b, "id")); } } - this->subscriber_count = int32_not_null(j, "subscriber_count"); - this->account_id = string_not_null(&((*j)["account"]), "id"); - this->account_name = string_not_null(&((*j)["account"]), "name"); + if(j->contains("scopes")) { + for (const auto& scope : (*j)["scopes"]) { + this->scopes.push_back(to_string(scope)); + } + } return *this; } json integration::to_json_impl(bool with_id) const { return json({ - { "expire_behavior", (flags & if_expire_kick) ? 1 : 0 }, - { "expire_grace_period", expire_grace_period }, - { "enable_emoticons", emoticons_enabled() } - }).dump(); + { "expire_behavior", (flags & if_expire_kick) ? 1 : 0 }, + { "expire_grace_period", expire_grace_period }, + { "enable_emoticons", emoticons_enabled() } + }).dump(); } bool integration::emoticons_enabled() const { @@ -138,5 +150,4 @@ connection& connection::fill_from_json_impl(nlohmann::json* j) { return *this; } - } // namespace dpp