Skip to content
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
13 changes: 13 additions & 0 deletions include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ struct DPP_EXPORT command_option : public json_interface<command_option> {
*/
std::map<std::string, std::string> 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<std::string> file_types;

/**
* @brief Construct a new command option object
*/
Expand All @@ -302,6 +307,14 @@ struct DPP_EXPORT command_option : public json_interface<command_option> {
*/
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
Expand Down
13 changes: 13 additions & 0 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ class DPP_EXPORT component : public json_interface<component> {
*/
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<std::string> file_types;

/**
* @brief Minimum length for text input (0-4000)
*/
Expand Down Expand Up @@ -897,6 +902,14 @@ class DPP_EXPORT component : public json_interface<component> {
*/
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
*
Expand Down
19 changes: 19 additions & 0 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/dpp/slashcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down
Loading