Skip to content

Commit ac31778

Browse files
committed
feat: add attachment_size_limit to dpp::interaction
1 parent 9454571 commit ac31778

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

include/dpp/appcommand.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ namespace dpp {
4444
#define AUTOCOMPLETE_MAX_CHOICES 25
4545
#endif
4646

47+
/**
48+
* @brief Discords default attachment size limit is 10MiB, and will be used in case
49+
* an interaction does not contain its attachment size limit.
50+
*/
51+
#ifndef DEFAULT_ATTACHMENT_SIZE_LIMIT
52+
#define DEFAULT_ATTACHMENT_SIZE_LIMIT 10 * 1024 * 1024
53+
#endif
54+
4755
/**
4856
* @brief Represents command option types.
4957
* These are the possible parameter value types.
@@ -1093,6 +1101,11 @@ class DPP_EXPORT interaction : public managed, public json_interface<interaction
10931101
*/
10941102
std::string guild_locale;
10951103

1104+
/**
1105+
* @brief Attachment size limit in bytes for this interaction. Will be the discord default if not provided by the interaction.
1106+
*/
1107+
uint32_t attachment_size_limit;
1108+
10961109
/**
10971110
* @brief Cache policy from cluster.
10981111
*/

src/dpp/slashcommand.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ slashcommand& slashcommand::add_option(const command_option &o)
465465
return *this;
466466
}
467467

468-
interaction::interaction() : application_id(0), type(0), guild_id(0), channel_id(0), message_id(0), version(0), cache_policy(cache_policy::cpol_default) {
468+
interaction::interaction() : application_id(0), type(0), guild_id(0), channel_id(0), message_id(0), version(0), cache_policy(cache_policy::cpol_default), attachment_size_limit(DEFAULT_ATTACHMENT_SIZE_LIMIT) {
469469
}
470470

471471
command_interaction interaction::get_command_interaction() const {
@@ -625,6 +625,11 @@ void from_json(const nlohmann::json& j, interaction& i) {
625625
i.channel_id = snowflake_not_null(&j, "channel_id");
626626
i.guild_id = snowflake_not_null(&j, "guild_id");
627627
i.app_permissions = snowflake_not_null(&j, "app_permissions");
628+
i.attachment_size_limit = int32_not_null(&j, "attachment_size_limit");
629+
630+
if (i.attachment_size_limit == 0) {
631+
i.attachment_size_limit = DEFAULT_ATTACHMENT_SIZE_LIMIT;
632+
}
628633

629634
if (j.contains("channel") && !j.at("channel").is_null()) {
630635
const json& c = j["channel"];

0 commit comments

Comments
 (0)