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

implemented channel::get_icon_url & small doc improvements of slashcommand.h and some intent fixes #394

Merged
merged 2 commits into from
May 25, 2022
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
12 changes: 8 additions & 4 deletions include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
snowflake application_id;

/**
* @brief Context menu type, defaults to none
*
* @brief Context menu type, defaults to dpp::ctxm_chat_input
*/
slashcommand_contextmenu_type type;

Expand Down Expand Up @@ -843,6 +842,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma

/**
* @brief command permissions
* @deprecated Discord discourage use of this value and instead you should use default_member_permissions.
*/
std::vector<command_permission> permissions;

Expand All @@ -864,6 +864,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
/**
* @brief The default permissions of this command on a guild.
* D++ defaults this to p_use_application_commands.
* @note You can set it to 0 to disable the command for everyone except admins by default
*/
uint64_t default_member_permissions;

Expand Down Expand Up @@ -916,6 +917,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
* this is a permission bitmask.
*
* @param defaults default permissions to set
* @note You can set it to 0 to disable the command for everyone except admins by default
* @return slashcommand& reference to self
*/
slashcommand& set_default_permissions(uint64_t defaults);
Expand All @@ -932,7 +934,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
* @brief Set the type of the slash command (only for context menu entries)
*
* @param _type Type of context menu entry this command represents
* @note If the type is dpp::slashcommand_contextmenu_type::ctxm_chat_input, the command name will be set to lowercase.
* @note If the type is dpp::ctxm_chat_input, the command name will be set to lowercase.
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_type(slashcommand_contextmenu_type _type);
Expand All @@ -943,7 +945,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
* @param n name of command
* @note The maximum length of a command name is 32 UTF-8 codepoints.
* If your command name is longer than this, it will be truncated.
* The command name will be set to lowercase on the default dpp::slashcommand_contextmenu_type::ctxm_chat_input type.
* The command name will be set to lowercase when the type is the default dpp::ctxm_chat_input.
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_name(const std::string &n);
Expand Down Expand Up @@ -971,6 +973,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
*
* @param p permission to add
* @return slashcommand& reference to self for chaining of calls
* @deprecated Discord discourage use of this value and instead you should use default_member_permissions.
*/
slashcommand& add_permission(const command_permission& p);

Expand All @@ -980,6 +983,7 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
* dpp::guild_command_edit_permissions
*
* @return slashcommand& reference to self for chaining of calls
* @deprecated Discord discourage use of this value and instead you should use default_member_permissions.
*/
slashcommand& disable_default_permissions();

Expand Down
9 changes: 7 additions & 2 deletions src/dpp/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <dpp/discordevents.h>
#include <dpp/stringops.h>
#include <dpp/nlohmann/json.hpp>
#include <dpp/fmt-minimal.h>

using json = nlohmann::json;

Expand Down Expand Up @@ -422,8 +423,12 @@ std::string channel::get_icon_url(uint16_t size) const {
* At some point in the future this URL *will* change!
*/
if (!this->icon.to_string().empty()) {
// TODO implement this, endpoint for that isn't finished yet https://discord.com/developers/docs/reference#image-formatting-cdn-endpoints
return std::string();
return fmt::format("{}/channel-icons/{}/{}.png{}",
utility::cdn_host,
this->id,
this->icon.to_string(),
utility::avatar_size(size)
);
} else {
return std::string();
}
Expand Down
16 changes: 8 additions & 8 deletions src/dpp/slashcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,16 @@ command_option &command_option::fill_from_json(nlohmann::json *j) {
}
}

if (j->contains("name_localizations")) {
for(auto loc = (*j)["name_localizations"].begin(); loc != (*j)["name_localizations"].end(); ++loc) {
o.name_localizations[loc.key()] = loc.value();
if (j->contains("name_localizations")) {
for(auto loc = (*j)["name_localizations"].begin(); loc != (*j)["name_localizations"].end(); ++loc) {
o.name_localizations[loc.key()] = loc.value();
}
}
}
if (j->contains("description_localizations")) {
for(auto loc = (*j)["description_localizations"].begin(); loc != (*j)["description_localizations"].end(); ++loc) {
o.description_localizations[loc.key()] = loc.value();
if (j->contains("description_localizations")) {
for(auto loc = (*j)["description_localizations"].begin(); loc != (*j)["description_localizations"].end(); ++loc) {
o.description_localizations[loc.key()] = loc.value();
}
}
}

if (j->contains("options") && i > 0) {
i--; // prevent infinite recursion call with a counter
Expand Down