Skip to content

Commit

Permalink
feat: added role flag IN_PROMPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandserver committed Jul 15, 2023
1 parent 5b7ca81 commit 4815cc2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3122,7 +3122,7 @@ class DPP_EXPORT cluster {
* @brief Get public archived threads in a channel (Sorted by archive_timestamp in descending order)
* @see https://discord.com/developers/docs/resources/channel#list-public-archived-threads
* @param channel_id Channel to get public archived threads for
* @param before_timestamp Get threads before this timestamp
* @param before_timestamp Get threads archived before this timestamp
* @param limit Number of threads to get
* @param callback Function to call when the API call completes
* On success the callback will contain a dpp::thread_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().
Expand All @@ -3133,7 +3133,7 @@ class DPP_EXPORT cluster {
* @brief Get private archived threads in a channel (Sorted by archive_timestamp in descending order)
* @see https://discord.com/developers/docs/resources/channel#list-private-archived-threads
* @param channel_id Channel to get public archived threads for
* @param before_timestamp Get threads before this timestamp
* @param before_timestamp Get threads archived before this timestamp
* @param limit Number of threads to get
* @param callback Function to call when the API call completes
* On success the callback will contain a dpp::thread_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().
Expand Down
6 changes: 6 additions & 0 deletions include/dpp/role.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum role_flags : uint8_t {
r_premium_subscriber = 0b00001000, //!< Whether this is the guild's booster role
r_available_for_purchase = 0b00010000, //!< Whether the role is available for purchase
r_guild_connections = 0b00100000, //!< Whether the role is a guild's linked role
r_in_prompt = 0b01000000, //!< Whether the role can be selected by members in an onboarding prompt
};

/**
Expand Down Expand Up @@ -287,6 +288,11 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @return bool True if the role is a linked role
*/
bool is_linked() const;
/**
* @brief True if the role can be selected by members in an onboarding prompt
* @return bool True if the role can be selected by members in an onboarding prompt
*/
bool is_selectable_in_prompt() const;
/**
* @brief True if has create instant invite permission
* @note Having the administrator permission causes this method to always return true
Expand Down
17 changes: 17 additions & 0 deletions src/dpp/role.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace dpp {

using json = nlohmann::json;

/* A mapping of discord's flag values to our bitmap (they're different bit positions to fit other stuff in) */
std::map<uint8_t, dpp::role_flags> rolemap = {
{ 1 << 0, dpp::r_in_prompt },
};

role::role() :
managed(),
guild_id(0),
Expand Down Expand Up @@ -70,6 +75,14 @@ role& role::fill_from_json(snowflake _guild_id, nlohmann::json* j)
this->colour = int32_not_null(j, "color");
this->position = int8_not_null(j, "position");
this->permissions = snowflake_not_null(j, "permissions");

uint8_t f = int8_not_null(j, "flags");
for (auto & flag : rolemap) {
if (f & flag.first) {
this->flags |= flag.second;
}
}

this->flags |= bool_not_null(j, "hoist") ? dpp::r_hoist : 0;
this->flags |= bool_not_null(j, "managed") ? dpp::r_managed : 0;
this->flags |= bool_not_null(j, "mentionable") ? dpp::r_mentionable : 0;
Expand Down Expand Up @@ -167,6 +180,10 @@ bool role::is_linked() const {
return this->flags & dpp::r_guild_connections;
}

bool role::is_selectable_in_prompt() const {
return this->flags & dpp::r_in_prompt;
}

bool role::has_create_instant_invite() const {
return has_administrator() || permissions.has(p_create_instant_invite);
}
Expand Down

0 comments on commit 4815cc2

Please sign in to comment.