Skip to content

Commit

Permalink
refactor: revert get_parameter to interaction_create_t from #641 (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis authored Apr 7, 2023
2 parents 5dfca3b + a2bd989 commit adb4de8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
35 changes: 26 additions & 9 deletions include/dpp/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
* @brief Destroy this object
*/
virtual ~interaction_create_t() = default;

/**
* @brief Get a slashcommand parameter
*
* @param name The name of the command line parameter to retrieve the value for
* @return const command_value& Returns the value of the first option that matches the given name.
* If no matches are found, an empty variant is returned.
*
* @throw dpp::logic_exception if the interaction is not for a command
*/
const virtual command_value& get_parameter(const std::string& name) const;
};

/**
Expand All @@ -494,21 +505,15 @@ struct DPP_EXPORT slashcommand_t : public interaction_create_t {
* @param raw Raw event text as JSON
*/
slashcommand_t(class discord_client* client, const std::string& raw);

/**
* @brief Get a command line parameter
*
* @param name The name of the command line parameter to retrieve the value for
* @return const command_value& Returns the value of the first option that matches the given name.
* If no matches are found, an empty variant is returned.
*/
const virtual command_value& get_parameter(const std::string& name) const;
};

/**
* @brief Click on button
*/
struct DPP_EXPORT button_click_t : public interaction_create_t {
private:
using interaction_create_t::get_parameter;
public:

/** Constructor
* @param client The shard the event originated on
Expand All @@ -527,6 +532,9 @@ struct DPP_EXPORT button_click_t : public interaction_create_t {
};

struct DPP_EXPORT form_submit_t : public interaction_create_t {
private:
using interaction_create_t::get_parameter;
public:

/** Constructor
* @param client The shard the event originated on
Expand All @@ -548,6 +556,9 @@ struct DPP_EXPORT form_submit_t : public interaction_create_t {
* @brief Discord requests that we fill a list of auto completion choices for a command option
*/
struct DPP_EXPORT autocomplete_t : public interaction_create_t {
private:
using interaction_create_t::get_parameter;
public:

/** Constructor
* @param client The shard the event originated on
Expand Down Expand Up @@ -576,6 +587,9 @@ struct DPP_EXPORT autocomplete_t : public interaction_create_t {
* user or message.
*/
struct DPP_EXPORT context_menu_t : public interaction_create_t {
private:
using interaction_create_t::get_parameter;
public:

/** Constructor
* @param client The shard the event originated on
Expand Down Expand Up @@ -653,6 +667,9 @@ struct DPP_EXPORT user_context_menu_t : public context_menu_t {
* @brief Click on select
*/
struct DPP_EXPORT select_click_t : public interaction_create_t {
private:
using interaction_create_t::get_parameter;
public:

/** Constructor
* @param client The shard the event originated on
Expand Down
20 changes: 10 additions & 10 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class DPP_EXPORT component : public json_interface<component> {
struct DPP_EXPORT embed_footer {
/** Footer text */
std::string text;
/** Footer icon url */
/** Footer icon url (only supports http(s) and attachments) */
std::string icon_url;
/** Proxied icon url */
std::string proxy_url;
Expand Down Expand Up @@ -577,9 +577,9 @@ struct DPP_EXPORT embed_provider {
struct DPP_EXPORT embed_author {
/** Author name */
std::string name;
/** Author url */
/** Author url (only supports http(s)) */
std::string url;
/** Author icon url */
/** Author icon url (only supports http(s) and attachments) */
std::string icon_url;
/** Proxied icon url */
std::string proxy_icon_url;
Expand All @@ -589,9 +589,9 @@ struct DPP_EXPORT embed_author {
* @brief A dpp::embed may contain zero or more fields
*/
struct DPP_EXPORT embed_field {
/** Name of field */
/** Name of field (max length 256) */
std::string name;
/** Value of field (max length 1000) */
/** Value of field (max length 1024) */
std::string value;
/** True if the field is to be displayed inline */
bool is_inline;
Expand Down Expand Up @@ -659,7 +659,7 @@ struct DPP_EXPORT embed {

/** Set the footer of the embed. Returns the embed itself so these method calls may be "chained"
* @param text string to set as footer text. It will be truncated to the maximum length of 2048 UTF-8 characters.
* @param icon_url an url to set as footer icon url
* @param icon_url an url to set as footer icon url (only supports http(s) and attachments)
* @return A reference to self
*/
embed& set_footer(const std::string& text, const std::string& icon_url);
Expand Down Expand Up @@ -698,8 +698,8 @@ struct DPP_EXPORT embed {

/** Set embed author. Returns the embed itself so these method calls may be "chained"
* @param name The name of the author. It will be truncated to the maximum length of 256 UTF-8 characters.
* @param url The url of the author
* @param icon_url The icon URL of the author
* @param url The url of the author (only supports http(s))
* @param icon_url The icon URL of the author (only supports http(s) and attachments)
* @return A reference to self
*/
embed& set_author(const std::string& name, const std::string& url, const std::string& icon_url);
Expand All @@ -712,7 +712,7 @@ struct DPP_EXPORT embed {
embed& set_provider(const std::string& name, const std::string& url);

/** Set embed image. Returns the embed itself so these method calls may be "chained"
* @param url The embed image URL
* @param url The embed image URL (only supports http(s) and attachments)
* @return A reference to self
*/
embed& set_image(const std::string& url);
Expand All @@ -724,7 +724,7 @@ struct DPP_EXPORT embed {
embed& set_video(const std::string& url);

/** Set embed thumbnail. Returns the embed itself so these method calls may be "chained"
* @param url The embed thumbnail url
* @param url The embed thumbnail url (only supports http(s) and attachments)
* @return A reference to self
*/
embed& set_thumbnail(const std::string& url);
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class DPP_EXPORT user : public managed, public json_interface<user> {
bool has_animated_icon() const;

/**
* @brief Format a username into user#discriminator
* @brief Format a username into user\#discriminator
*
* For example Brain#0001
*
Expand Down
4 changes: 2 additions & 2 deletions src/dpp/dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ void interaction_create_t::delete_original_response(command_completion_event_t c
});
}

const command_value& slashcommand_t::get_parameter(const std::string& name) const
const command_value& interaction_create_t::get_parameter(const std::string& name) const
{
/* Dummy STATIC return value for unknown options so we aren't returning a value off the stack */
static command_value dummy_value = {};
const command_interaction& ci = command.get_command_interaction();
const command_interaction ci = command.get_command_interaction();

for (const auto &option : ci.options) {
if (option.type != co_sub_command && option.type != co_sub_command_group && option.name == name) {
Expand Down

0 comments on commit adb4de8

Please sign in to comment.