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

Added voice action bitflag for guild_member fixed #417 #419

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion include/dpp/guild.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ enum guild_flags_extra : uint8_t {
};

/**
* @brief Various flags that can be used to indicate the status of a guild member
* @brief Various flags that can be used to indicate the status of a guild member.
* @note Use set_mute and set_deaf member functions and do not toggle the bits yourself.
*/
enum guild_member_flags : uint8_t {
/** Member deafened in voice channels */
Expand All @@ -149,6 +150,8 @@ enum guild_member_flags : uint8_t {
gm_pending = 0b00100,
/** Member has animated guild-specific avatar */
gm_animated_avatar = 0b01000,
/** gm_deaf or gm_mute has been toggled */
gm_voice_action = 0b10000,
};

/**
Expand Down
11 changes: 9 additions & 2 deletions src/dpp/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ guild_member& guild_member::set_nickname(const std::string& nick) {

guild_member& guild_member::set_mute(const bool is_muted) {
this->flags = (is_muted) ? flags | gm_mute : flags & ~gm_mute;
this->flags |= gm_voice_action;
return *this;
}

guild_member& guild_member::set_deaf(const bool is_deafened) {
this->flags = (is_deafened) ? flags | gm_deaf : flags & ~gm_deaf;
this->flags |= gm_voice_action;
return *this;
}

Expand All @@ -125,6 +127,7 @@ guild_member& guild_member::fill_from_json(nlohmann::json* j, snowflake g_id, sn
this->guild_id = g_id;
this->user_id = u_id;
j->get_to(*this);

return *this;
}

Expand Down Expand Up @@ -200,8 +203,12 @@ std::string guild_member::build_json(bool with_id) const {
j["roles"].push_back(std::to_string(role));
}
}
j["mute"] = is_muted();
j["deaf"] = is_deaf();

if (flags & gm_voice_action) {
j["mute"] = is_muted();
j["deaf"] = is_deaf();
braindigitalis marked this conversation as resolved.
Show resolved Hide resolved
}

return j.dump();
}

Expand Down