Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new premium upsell button style #1175

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
25 changes: 24 additions & 1 deletion include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
*/
cos_premium,
};

/**
Expand Down Expand Up @@ -387,6 +392,11 @@ class DPP_EXPORT component : public json_interface<component> {
*/
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)
*/
Expand Down Expand Up @@ -489,6 +499,17 @@ class DPP_EXPORT component : public json_interface<component> {
*/
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`
Expand Down Expand Up @@ -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,

Expand Down
19 changes: 15 additions & 4 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Loading