From c3f29601aa0424d0c073929810189e2609b2f368 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Wed, 19 Jun 2024 07:36:52 +0000 Subject: [PATCH 1/4] feat: new premium upsell button style --- include/dpp/message.h | 25 ++++++++++++++++++++++++- src/dpp/message.cpp | 19 +++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/dpp/message.h b/include/dpp/message.h index a8eac3fcbb..59873c84dc 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -188,7 +188,12 @@ enum component_style : uint8_t { /** * @brief An external hyperlink to a website */ - cos_link + cos_link, + + /** + * @brief Premium upsell button, requires set_sku + */ + cos_premium, }; /** @@ -387,6 +392,11 @@ class DPP_EXPORT component : public json_interface { */ std::string url; + /** + * @brief The SKU ID for premium upsell buttons + */ + dpp::snowflake sku_id; + /** * @brief Placeholder text for select menus and text inputs (max 150 characters) */ @@ -489,6 +499,17 @@ class DPP_EXPORT component : public json_interface { */ component& set_type(component_type ct); + /** + * @brief Set the SKU ID for a premium upsell button + * This is only valid for premium upsell buttons of type + * cos_premium. It indicates which premium package to + * link to when the button is clicked. + * + * @param sku The SKU ID + * @return component& reference to self + */ + component& set_sku_id(dpp::snowflake sku); + /** * @brief Set the text style of a text component * @note Sets type to `cot_text` @@ -1869,6 +1890,8 @@ enum message_type { /** * @brief Interaction premium upsell + * @depreciated Replaced with buttons with a style of cos_premium + * This message type may stop working at any point */ mt_interaction_premium_upsell = 26, diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 57ec118b60..7cbadd8cd3 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -235,6 +235,12 @@ component& component::set_max_length(uint32_t max_l) return *this; } +component& component::set_sku_id(dpp::snowflake sku) +{ + sku_id = sku; + return *this; +} + void to_json(json& j, const attachment& a) { if (a.id) { j["id"] = a.id; @@ -274,15 +280,20 @@ void to_json(json& j, const component& cp) { } } if (cp.type == cot_button) { - j["label"] = cp.label; + if (!cp.label.empty()) { + j["label"] = cp.label; + } j["style"] = int(cp.style); - if (cp.type == cot_button && cp.style != cos_link && !cp.custom_id.empty()) { - /* Links cannot have a custom id */ + if (cp.style != cos_link && cp.style != cos_premium && !cp.custom_id.empty()) { + /* Links and premium upsell cannot have a custom id */ j["custom_id"] = cp.custom_id; } - if (cp.type == cot_button && cp.style == cos_link && !cp.url.empty()) { + if (cp.style == cos_link && !cp.url.empty()) { j["url"] = cp.url; } + if (cp.style == cos_premium && !cp.sku_id.empty()) { + j["sku_id"] = cp.sku_id; + } j["disabled"] = cp.disabled; if (cp.emoji.id || !cp.emoji.name.empty()) { From b5c5b4a6aafdc43bba662551d5009dff333db41b Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Wed, 19 Jun 2024 07:40:42 +0000 Subject: [PATCH 2/4] mark interaction type 10 as depreciatd --- include/dpp/appcommand.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/dpp/appcommand.h b/include/dpp/appcommand.h index 8f75001c23..e628bd97f8 100644 --- a/include/dpp/appcommand.h +++ b/include/dpp/appcommand.h @@ -443,6 +443,9 @@ enum interaction_response_type { * @see https://discord.com/developers/docs/monetization/entitlements#premiumrequired-interaction-response * @note Not available for autocomplete and ping interactions. * @warning This response does not support using `content`, `embeds`, or `attachments`, so reply with no data when using this! + * + * @depreciated Replaced with buttons with a style of cos_premium + * This interaction type may stop working at any point */ ir_premium_required = 10, }; From 22cbb941517cbe25cfa0804de13d223ee2b5817d Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Wed, 19 Jun 2024 09:03:46 +0000 Subject: [PATCH 3/4] comments --- include/dpp/message.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/dpp/message.h b/include/dpp/message.h index 59873c84dc..e510ba067c 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -166,32 +166,34 @@ enum text_style_type : uint8_t { */ enum component_style : uint8_t { /** - * @brief Blurple + * @brief Blurple; Primary */ cos_primary = 1, /** - * @brief Grey + * @brief Grey; Secondary */ cos_secondary, /** - * @brief Green + * @brief Green; Success */ cos_success, /** - * @brief Red + * @brief Red; danger */ cos_danger, /** - * @brief An external hyperlink to a website + * @brief An external hyperlink to a website, requires url to be set + * @note Will not work unless url is set */ cos_link, /** - * @brief Premium upsell button, requires set_sku + * @brief Premium upsell button, requires sku_id to be set + * @note Will not work unless sku is set */ cos_premium, }; From f945d832a8b726e042a5a9adf8115808e808229b Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Wed, 19 Jun 2024 09:05:13 +0000 Subject: [PATCH 4/4] remove unneeded includes --- src/dpp/message.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 7cbadd8cd3..8d94a9b35a 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -20,18 +20,11 @@ ************************************************************************************/ #include #include -#include -#include -#include #include #include #include -#include -#include #include - - namespace dpp { using json = nlohmann::json;