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

Dev #86

Merged
merged 7 commits into from
Jun 2, 2023
Merged
2 changes: 1 addition & 1 deletion include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ struct DPP_EXPORT interaction_modal_response : public interaction_response, publ
std::string custom_id;

/**
* @brief Title of the modal form box
* @brief Title of the modal form box (max 25 characters)
*/
std::string title;

Expand Down
37 changes: 30 additions & 7 deletions include/dpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,39 @@ class DPP_EXPORT channel : public managed, public json_interface<channel> {
channel& set_rate_limit_per_user(const uint16_t rate_limit_per_user);

/**
* @brief Add a permission_overwrite to this channel object
*
* @param id ID of the role or the member you want to add overwrite for
* @brief Add permission overwrites for a user or role.
* If the channel already has permission overwrites for the passed target, the existing ones will be adjusted by the passed permissions
*
* @param target ID of the role or the member you want to adjust overwrites for
* @param type type of overwrite
* @param allowed_permissions bitmask of allowed permissions (refer to enum dpp::permissions) for this user/role in this channel
* @param denied_permissions bitmask of denied permissions (refer to enum dpp::permissions) for this user/role in this channel
* @param allowed_permissions bitmask of dpp::permissions you want to allow for this user/role in this channel. Note: You can use the dpp::permission class
* @param denied_permissions bitmask of dpp::permissions you want to deny for this user/role in this channel. Note: You can use the dpp::permission class
*
* @return Reference to self, so these method calls may be chained
* @return Reference to self, so these method calls may be chained
*/
channel& add_permission_overwrite(const snowflake target, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions);
/**
* @brief Set permission overwrites for a user or role on this channel object. Old permission overwrites for the target will be overwritten
*
* @param target ID of the role or the member you want to set overwrites for
* @param type type of overwrite
* @param allowed_permissions bitmask of allowed dpp::permissions for this user/role in this channel. Note: You can use the dpp::permission class
* @param denied_permissions bitmask of denied dpp::permissions for this user/role in this channel. Note: You can use the dpp::permission class
*
* @return Reference to self, so these method calls may be chained
*
* @note If both `allowed_permissions` and `denied_permissions` parameters are 0, the permission overwrite for the target will be removed
*/
channel& set_permission_overwrite(const snowflake target, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions);
/**
* @brief Remove channel specific permission overwrites of a user or role
*
* @param target ID of the role or the member you want to remove permission overwrites of
* @param type type of overwrite
*
* @return Reference to self, so these method calls may be chained
*/
channel& add_permission_overwrite(const snowflake id, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions);
channel& remove_permission_overwrite(const snowflake target, const overwrite_type type);

/**
* @brief Get the channel type
Expand Down
28 changes: 25 additions & 3 deletions include/dpp/invite.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@
#include <dpp/stage_instance.h>
#include <unordered_map>
#include <dpp/json_interface.h>
#include <dpp/channel.h>
#include <dpp/user.h>
#include <dpp/guild.h>

namespace dpp {

/**
* @brief Invite target types for dpp::invite
*/
enum invite_target_t : uint8_t {
itt_none = 0, //!< Undefined invite target type
itt_stream = 1, //!< Stream target type
itt_embedded_application = 2, //!< Embedded Application target type
};

/**
* @brief Represents an invite to a discord guild or channel
*/
Expand All @@ -43,18 +55,28 @@ class DPP_EXPORT invite : public json_interface<invite> {
/** Guild ID this invite is for
*/
snowflake guild_id;
/** The partial guild this invite is for. Only filled in retrieved invites
*/
guild destination_guild;
/** Channel ID this invite is for
*/
snowflake channel_id;
/** The partial channel this invite is for. Only filled in retrieved invites
*/
channel destination_channel;
/** User ID who created this invite
* @deprecated Use the `inviter` field instead
*/
snowflake inviter_id;
/** User who created this invite
*/
user inviter;
/** The user ID whose stream to display for this voice channel stream invite
*/
snowflake target_user_id;
/** Target type
/** Target type for this voice channel invite
*/
uint8_t target_type;
invite_target_t target_type;
/** Approximate number of online users
* @note Only returned from cluster::invite_get
*/
Expand All @@ -68,7 +90,7 @@ class DPP_EXPORT invite : public json_interface<invite> {
uint32_t max_age;
/** Maximum number of uses, or 0 for unlimited. Must be between 0 and 100. Defaults to 0
*/
uint32_t max_uses;
uint8_t max_uses;
/** Whether this invite only grants temporary membership
*/
bool temporary;
Expand Down
26 changes: 13 additions & 13 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ enum component_style : uint8_t {
*/
struct DPP_EXPORT select_option : public json_interface<select_option> {
/**
* @brief Label for option
* @brief User-facing name of the option
*/
std::string label;
/**
* @brief Value for option
* @brief Dev-defined value of the option
*/
std::string value;
/**
* @brief Description of option
* @brief Additional description of the option
*/
std::string description;
/**
Expand Down Expand Up @@ -256,12 +256,12 @@ class DPP_EXPORT component : public json_interface<component> {
*/
std::string placeholder;

/** Minimum number of items that must be chosen for a select menu.
/** Minimum number of items that must be chosen for a select menu (0-25).
* Default is -1 to not set this
*/
int32_t min_values;

/** Maximum number of items that can be chosen for a select menu.
/** Maximum number of items that can be chosen for a select menu (0-25).
* Default is -1 to not set this
*/
int32_t max_values;
Expand Down Expand Up @@ -441,33 +441,33 @@ class DPP_EXPORT component : public json_interface<component> {
component& set_placeholder(const std::string &placeholder);

/**
* @brief Set the min value
* @brief Set the minimum number of items that must be chosen for a select menu
*
* @param min_values min value to set
* @param min_values min value to set (0-25)
* @return component& Reference to self
*/
component& set_min_values(uint32_t min_values);

/**
* @brief Set the max value
* @brief Set the maximum number of items that can be chosen for a select menu
*
* @param max_values max value to set (0 - 25)
* @param max_values max value to set (0-25)
* @return component& Reference to self
*/
component& set_max_values(uint32_t max_values);

/**
* @brief Set the min length of text input
* @brief Set the minimum input length for a text input
*
* @param min_l min value to set (0 - 25)
* @param min_l min length to set (0-4000)
* @return component& Reference to self
*/
component& set_min_length(uint32_t min_l);

/**
* @brief Set the max length of text input
* @brief Set the maximum input length for a text input
*
* @param max_l max value to set
* @param max_l max length to set (1-4000)
* @return component& Reference to self
*/
component& set_max_length(uint32_t max_l);
Expand Down
34 changes: 32 additions & 2 deletions src/dpp/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,42 @@ channel& channel::set_user_limit(const uint8_t user_limit) {
return *this;
}

channel& channel::add_permission_overwrite(const snowflake id, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions) {
permission_overwrite po {id, allowed_permissions, denied_permissions, type};
channel& channel::add_permission_overwrite(const snowflake target, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions) {
for (auto &o : this->permission_overwrites) {
if (o.id == target && o.type == type) {
o.allow.remove(denied_permissions);
o.allow.add(allowed_permissions);
o.deny.remove(allowed_permissions);
o.deny.add(denied_permissions);
return *this;
}
}
permission_overwrite po {target, allowed_permissions, denied_permissions, type};
this->permission_overwrites.push_back(po);
return *this;
}

channel& channel::set_permission_overwrite(const snowflake target, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions) {
this->remove_permission_overwrite(target, type);
if (allowed_permissions != 0 || denied_permissions != 0) {
permission_overwrite po{target, allowed_permissions, denied_permissions, type};
this->permission_overwrites.push_back(po);
}
return *this;
}

channel& channel::remove_permission_overwrite(const dpp::snowflake target, const dpp::overwrite_type type) {
auto it = this->permission_overwrites.begin();
while (it != this->permission_overwrites.end()) {
if (it->id == target && it->type == type) {
it = this->permission_overwrites.erase(it);
} else {
it++;
}
}
return *this;
}

bool channel::is_nsfw() const {
return flags & dpp::c_nsfw;
}
Expand Down
23 changes: 14 additions & 9 deletions src/dpp/invite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace dpp {

using json = nlohmann::json;

invite::invite() : expires_at(0), guild_id(0), channel_id(0), inviter_id(0), target_user_id(0), target_type(0), approximate_presence_count(0), approximate_member_count(0), max_age(86400), max_uses(0), temporary(false), unique(false), uses(0), created_at(0)
invite::invite() : expires_at(0), guild_id(0), channel_id(0), inviter_id(0), target_user_id(0), target_type(itt_none), approximate_presence_count(0), approximate_member_count(0), max_age(86400), max_uses(0), temporary(false), unique(false), uses(0), created_at(0)
{
}

Expand All @@ -37,22 +37,27 @@ invite& invite::fill_from_json(nlohmann::json* j) {
expires_at = (j->contains("expires_at")) ? ts_not_null(j, "expires_at") : 0;
created_at = (j->contains("created_at")) ? ts_not_null(j, "created_at") : 0;
if (j->contains("guild") && !j->at("guild").is_null()) {
guild_id = snowflake_not_null(&((*j)["guild"]), "id");
} else if (j->contains("guild_id")) { // check ID for the invite create event
destination_guild = dpp::guild().fill_from_json(&((*j)["guild"]));
guild_id = destination_guild.id;
} else if (j->contains("guild_id")) { // check ID for invite gateway events
guild_id = snowflake_not_null(j, "guild_id");
}
if (j->contains("channel") && !j->at("channel").is_null()) {
channel_id = snowflake_not_null(&((*j)["channel"]), "id");
} else if (j->contains("channel_id")) { // check ID for the invite create event
destination_channel = dpp::channel().fill_from_json(&((*j)["channel"]));
channel_id = destination_channel.id;
} else if (j->contains("channel_id")) { // check ID for invite gateway events
channel_id = snowflake_not_null(j, "channel_id");
}
inviter_id = (j->contains("inviter")) ? snowflake_not_null(&((*j)["inviter"]), "id") : 0;
if (j->contains("inviter") && !j->at("inviter").is_null()) {
inviter = dpp::user().fill_from_json(&((*j)["inviter"]));
inviter_id = inviter.id;
}
target_user_id = (j->contains("target_user")) ? snowflake_not_null(&((*j)["target_user"]), "id") : 0;
target_type = int8_not_null(j, "target_type");
target_type = static_cast<invite_target_t>(int8_not_null(j, "target_type"));
approximate_presence_count = int32_not_null(j, "approximate_presence_count");
approximate_member_count = int32_not_null(j, "approximate_member_count");
max_age = int32_not_null(j, "max_age");
max_uses = int32_not_null(j, "max_uses");
max_uses = int8_not_null(j, "max_uses");
temporary = bool_not_null(j, "temporary");
unique = bool_not_null(j, "unique");
uses = (j->contains("uses")) ? int32_not_null(j, "uses") : 0;
Expand All @@ -68,7 +73,7 @@ std::string invite::build_json(bool with_id) const {
j["max_uses"] = max_uses;
if (target_user_id > 0)
j["target_user"] = target_user_id;
if (target_type > 0)
if (target_type != itt_none)
j["target_type"] = target_type;
if (temporary)
j["temporary"] = temporary;
Expand Down
Loading