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: Add flags and is_remix() to dpp::attachment #727

Merged
merged 14 commits into from
Jul 19, 2023
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
24 changes: 24 additions & 0 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,14 @@ struct DPP_EXPORT reaction {
~reaction() = default;
};

/**
* @brief Bitmask flags for a dpp::attachment
*/
enum attachment_flags : uint8_t {
/// this attachment has been edited using the remix feature on mobile
a_is_remix = 1 << 2,
};

/**
* @brief Represents an attachment in a dpp::message
*/
Expand Down Expand Up @@ -794,6 +802,8 @@ struct DPP_EXPORT attachment {
double duration_secs;
/** base64 encoded bytearray representing a sampled waveform (currently for voice messages) */
std::string waveform;
/** Flags. Made of bits in dpp::attachment_flags */
uint8_t flags;
/** Owning message */
struct message* owner;

Expand Down Expand Up @@ -824,6 +834,13 @@ struct DPP_EXPORT attachment {
* itself has an owning cluster, this method will throw a dpp::logic_exception when called.
*/
void download(http_completion_event callback) const;

/**
* @brief Returns true if remixed
*
* @return true if remixed
*/
bool is_remix() const;
};

/**
Expand Down Expand Up @@ -1523,6 +1540,13 @@ struct DPP_EXPORT message : public managed {
* @return true if message is a DM
*/
bool is_dm() const;

/**
* @brief Returns true if message has remixed attachment
*
* @return true if message has remixed attachment
*/
bool has_remix_attachment() const;
};

/** A group of messages */
Expand Down
19 changes: 19 additions & 0 deletions include/dpp/permissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ class DPP_EXPORT permission {
return (value & (0 | ... | values)) == (0 | ... | values);
}

/**
* @brief Check for permission flags set. It uses the Bitwise AND operator
* @tparam T one or more uint64_t permission bits
* @param values The permissions (from dpp::permissions) to check for
*
* **Example:**
*
* ```cpp
* bool is_mod = permission.has_any(dpp::p_administrator, dpp::p_ban_members);
* // Returns true if the permission bitmask contains p_administrator or p_ban_members
* ```
*
* @return bool True if it has any the given permissions
*/
template <typename... T>
constexpr bool has_any(T... values) const noexcept {
return (value & (0 | ... | values)) != 0;
}

/**
* @brief Add a permission with the Bitwise OR operation
* @tparam T one or more uint64_t permission bits
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/discordclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void discord_client::disconnect_voice_internal(snowflake guild_id, bool emit_jso
std::unique_lock lock(voice_mutex);
auto v = connecting_voice_channels.find(guild_id);
if (v != connecting_voice_channels.end()) {
log(ll_debug, "Disconnecting voice, guild: {}" + std::to_string(guild_id));
log(ll_debug, "Disconnecting voice, guild: " + std::to_string(guild_id));
if (emit_json) {
queue_message(jsonobj_to_string(json({
{ "op", 4 },
Expand Down
16 changes: 16 additions & 0 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the License.
*
************************************************************************************/
#include <algorithm>
#include <dpp/message.h>
#include <dpp/user.h>
#include <dpp/channel.h>
Expand Down Expand Up @@ -768,6 +769,7 @@ attachment::attachment(struct message* o)
, width(0)
, height(0)
, ephemeral(false)
, flags(0)
, owner(o)
{
}
Expand All @@ -785,6 +787,7 @@ attachment::attachment(struct message* o, json *j) : attachment(o) {
this->ephemeral = bool_not_null(j, "ephemeral");
this->duration_secs = double_not_null(j, "duration_secs");
this->waveform = string_not_null(j, "waveform");
this->flags = int8_not_null(j, "flags");
}

void attachment::download(http_completion_event callback) const {
Expand All @@ -797,6 +800,10 @@ void attachment::download(http_completion_event callback) const {
}
}

bool attachment::is_remix() const {
return flags & a_is_remix;
}

std::string message::build_json(bool with_id, bool is_interaction_response) const {
/* This is the basics. once it works, expand on it. */
json j({
Expand Down Expand Up @@ -1117,6 +1124,15 @@ message& message::fill_from_json(json* d, cache_policy_t cp) {
return *this;
}

bool message::has_remix_attachment() const {
return std::any_of(
attachments.begin(),
attachments.end(),
[](const auto& a) -> bool {
return a.is_remix();
});
}

sticker::sticker() : managed(0), pack_id(0), type(st_standard), format_type(sf_png), available(true), guild_id(0), sort_value(0) {
}

Expand Down