diff --git a/include/dpp/appcommand.h b/include/dpp/appcommand.h index a3a0cc30f8..74bde6c63b 100644 --- a/include/dpp/appcommand.h +++ b/include/dpp/appcommand.h @@ -292,6 +292,11 @@ struct DPP_EXPORT command_option : public json_interface { */ std::map description_localizations; + /** + * @brief File types (dpp::co_attachment) to filter for; can be "image", "video", "audio", or any dot-prefixed extension such as ".pdf" (0-10). + */ + std::vector file_types; + /** * @brief Construct a new command option object */ @@ -302,6 +307,14 @@ struct DPP_EXPORT command_option : public json_interface { */ virtual ~command_option() = default; + /** + * @brief Add a file type (dpp::co_attachment) to filter for. + * + * @param file_type The type to filter for ("image"/"video"/"audio" or the file extension (begins with ".")). + * @return command_option& Reference to self + */ + command_option& add_file_type(std::string_view file_type); + /** * @brief Add a localisation for this slash command option * @see https://discord.com/developers/docs/reference#locales diff --git a/include/dpp/message.h b/include/dpp/message.h index 37926cbd2c..a4c2756209 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -567,6 +567,11 @@ class DPP_EXPORT component : public json_interface { */ int32_t max_values; + /** + * @brief File types (dpp::cot_file_upload) to filter for; can be "image", "video", "audio", or any dot-prefixed extension such as ".pdf" (0-10). + */ + std::vector file_types; + /** * @brief Minimum length for text input (0-4000) */ @@ -897,6 +902,14 @@ class DPP_EXPORT component : public json_interface { */ component& set_max_values(uint32_t max_values); + /** + * @brief Add a file type (dpp::cot_file_upload) to filter for. + * + * @param file_type The type to filter for ("image"/"video"/"audio" or the file extension (begins with ".")). + * @return component& Reference to self + */ + component& add_file_type(std::string_view file_type); + /** * @brief Set the minimum input length for a text input * diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 8aae9a963e..a81d638ba9 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -574,6 +574,20 @@ void to_json(json& j, const component& cp) { j["default_values"].push_back(o); } } + } else if (cp.type == cot_file_upload) { + j["custom_id"] = cp.custom_id; + if (cp.min_values >= 0) { + j["min_values"] = cp.min_values; + } + if (cp.max_values >= 0) { + j["max_values"] = cp.max_values; + } + if (cp.required) { + j["required"] = cp.required; + } + if (!cp.file_types.empty()) { + j["file_types"] = cp.file_types; + } } } @@ -650,6 +664,11 @@ component& component::set_max_values(uint32_t _max_values) { return *this; } +component& component::add_file_type(std::string_view const file_type) { + this->file_types.emplace_back(file_type); + return *this; +} + component& component::add_select_option(const select_option &option) { if (options.size() <= 25) { options.emplace_back(option); diff --git a/src/dpp/slashcommand.cpp b/src/dpp/slashcommand.cpp index 509e4e0fb0..7e49b90100 100644 --- a/src/dpp/slashcommand.cpp +++ b/src/dpp/slashcommand.cpp @@ -201,6 +201,10 @@ void to_json(json& j, const command_option& opt) { j["channel_types"].push_back(ch_type); } } + + if (!opt.file_types.empty()) { + j["file_types"] = opt.file_types; + } } void to_json(nlohmann::json& j, const command_permission& cp) { @@ -512,6 +516,17 @@ json interaction::to_json_impl(bool with_id) const { return ""; } +/** + * @brief Add a file type (dpp::co_attachment) to filter for. + * + * @param file_type The type to filter for ("image"/"video"/"audio" or the file extension (begins with ".")). + * @return command_option& Reference to self +*/ +command_option& command_option::add_file_type(std::string_view const file_type) { + this->file_types.emplace_back(file_type); + return *this; +} + slashcommand& slashcommand::add_localization(const std::string& language, const std::string& _name, const std::string& _description) { name_localizations[language] = _name; if (! _description.empty()) {