Skip to content

Commit

Permalink
feat: added join raid protection guild feature. This bumps the guild …
Browse files Browse the repository at this point in the history
…flags_extra field from 1 byte to 2 bytes!
  • Loading branch information
Commandserver committed May 8, 2023
1 parent dd32a60 commit 2d226dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
39 changes: 25 additions & 14 deletions include/dpp/guild.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,25 @@ enum guild_flags : uint32_t {
/**
* @brief Additional boolean flag values for guild, as guild_flags is full
*/
enum guild_flags_extra : uint8_t {
enum guild_flags_extra : uint16_t {
/** Guild has premium progress bar enabled */
g_premium_progress_bar_enabled = 0b00000001,
g_premium_progress_bar_enabled = 0b0000000000000001,
/** Guild can have an animated banner (doesn't mean it actually has one though) */
g_animated_banner = 0b00000010,
g_animated_banner = 0b0000000000000010,
/** Guild has auto moderation */
g_auto_moderation = 0b00000100,
g_auto_moderation = 0b0000000000000100,
/** Guild has paused invites, preventing new users from joining */
g_invites_disabled = 0b00001000,
g_invites_disabled = 0b0000000000001000,
/** Guild has been set as support server of an app in the App Directory */
g_developer_support_server = 0b00010000,
g_developer_support_server = 0b0000000000010000,
/** Guild role subscription purchase and renewal notifications are off */
g_no_role_subscription_notifications = 0b00100000,
g_no_role_subscription_notifications = 0b0000000000100000,
/** Guild role subscription sticker reply buttons are off */
g_no_role_subscription_notification_replies = 0b01000000,
g_no_role_subscription_notification_replies = 0b0000000001000000,
/** Guild has role subscriptions that can be purchased */
g_role_subscriptions_available_for_purchase = 0b10000000,
g_role_subscriptions_available_for_purchase = 0b0000000010000000,
/** Guild has disabled alerts for join raids in the configured safety alerts channel */
g_raid_alerts_disabled = 0b0000000100000000,
};

/**
Expand Down Expand Up @@ -536,6 +538,9 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
/** Snowflake ID of widget channel, or 0 */
snowflake widget_channel_id;

/** The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord */
snowflake safety_alerts_channel_id;

/** Approximate member count. May be sent as zero */
uint32_t member_count;

Expand All @@ -553,6 +558,11 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
*/
uint32_t max_members;

/**
* @brief Additional flags (values from dpp::guild_flags_extra)
*/
uint16_t flags_extra;

/** Shard ID of the guild */
uint16_t shard_id;

Expand Down Expand Up @@ -585,11 +595,6 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
*/
guild_nsfw_level_t nsfw_level;

/**
* @brief Additional flags
*/
uint8_t flags_extra;

/** Default constructor, zeroes all values */
guild();

Expand Down Expand Up @@ -846,6 +851,12 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
*/
bool has_role_subscriptions_available_for_purchase() const;

/**
* @brief Guild has disabled alerts for join raids in the configured safety alerts channel
* @return bool dpp::g_raid_alerts_disabled flag is set
*/
bool has_raid_alerts_disabled() const;

/**
* @brief Guild has access to set an animated guild icon
* @return bool can have animated icon
Expand Down
14 changes: 12 additions & 2 deletions src/dpp/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const std::map<std::string, std::variant<dpp::guild_flags, dpp::guild_flags_extr
{"NEWS", dpp::g_news },
{"PARTNERED", dpp::g_partnered },
{"PREVIEW_ENABLED", dpp::g_preview_enabled },
{"RAID_ALERTS_DISABLED", dpp::g_raid_alerts_disabled },
{"ROLE_ICONS", dpp::g_role_icons },
{"ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE", dpp::g_role_subscriptions_available_for_purchase },
{"ROLE_SUBSCRIPTIONS_ENABLED", dpp::g_role_subscription_enabled },
Expand All @@ -72,6 +73,7 @@ guild::guild() :
flags(0),
max_presences(0),
max_members(0),
flags_extra(0),
shard_id(0),
premium_subscription_count(0),
afk_timeout(afk_off),
Expand All @@ -81,8 +83,7 @@ guild::guild() :
verification_level(ver_none),
explicit_content_filter(expl_disabled),
mfa_level(mfa_none),
nsfw_level(nsfw_default),
flags_extra(0)
nsfw_level(nsfw_default)
{
}

Expand Down Expand Up @@ -326,6 +327,10 @@ bool guild::has_role_subscriptions_available_for_purchase() const {
return this->flags_extra & g_role_subscriptions_available_for_purchase;
}

bool guild::has_raid_alerts_disabled() const {
return this->flags_extra & g_raid_alerts_disabled;
}

bool guild::has_animated_icon() const {
return this->flags & g_animated_icon;
}
Expand Down Expand Up @@ -426,6 +431,9 @@ std::string guild::build_json(bool with_id) const {
if (!description.empty()) {
j["description"] = description;
}
if (!safety_alerts_channel_id.empty()) {
j["safety_alerts_channel_id"] = safety_alerts_channel_id;
}
return j.dump();
}

Expand Down Expand Up @@ -572,6 +580,8 @@ guild& guild::fill_from_json(discord_client* shard, nlohmann::json* d) {
welcome_screen.welcome_channels.emplace_back(wchan);
}
}

set_snowflake_not_null(d, "safety_alerts_channel_id", this->safety_alerts_channel_id);

} else {
this->flags |= dpp::g_unavailable;
Expand Down

0 comments on commit 2d226dd

Please sign in to comment.