Skip to content

Commit e8a9d74

Browse files
authored
refactor(async): Modernize coroutine helpers and add follow_up functions (#1467)
1 parent 8293247 commit e8a9d74

File tree

4 files changed

+135
-70
lines changed

4 files changed

+135
-70
lines changed

include/dpp/appcommand.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,36 @@ struct DPP_EXPORT interaction_modal_response : public interaction_response, publ
605605
*/
606606
interaction_modal_response(const std::string& _custom_id, const std::string& _title, const std::vector<component> _components = {});
607607

608+
/**
609+
* @brief Copy constructor
610+
*
611+
* @param other The object to copy from
612+
*/
613+
interaction_modal_response(const interaction_modal_response& other) = default;
614+
615+
/**
616+
* @brief Copy assignment operator
617+
*
618+
* @param other The object to copy from
619+
* @return interaction_modal_response& reference to self
620+
*/
621+
interaction_modal_response& operator=(const interaction_modal_response& other) = default;
622+
623+
/**
624+
* @brief Move constructor
625+
*
626+
* @param other The object to move from
627+
*/
628+
interaction_modal_response(interaction_modal_response&& other) noexcept = default;
629+
630+
/**
631+
* @brief Move assignment operator
632+
*
633+
* @param other The object to move from
634+
* @return interaction_modal_response& reference to self
635+
*/
636+
interaction_modal_response& operator=(interaction_modal_response&& other) noexcept = default;
637+
608638
/**
609639
* @brief Set the custom id
610640
*

include/dpp/cluster.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ class DPP_EXPORT cluster {
16501650
void interaction_response_get_original(const std::string &token, command_completion_event_t callback = utility::log_error());
16511651

16521652
/**
1653-
* @brief Create a followup message to a slash command
1653+
* @brief Create a followup message for an interaction
16541654
*
16551655
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response
16561656
* @param token Token for the interaction webhook
@@ -1661,7 +1661,7 @@ class DPP_EXPORT cluster {
16611661
void interaction_followup_create(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error());
16621662

16631663
/**
1664-
* @brief Edit original followup message to a slash command
1664+
* @brief Edit original followup message for an interaction
16651665
* This is an alias for cluster::interaction_response_edit
16661666
* @see cluster::interaction_response_edit
16671667
*
@@ -1683,7 +1683,7 @@ class DPP_EXPORT cluster {
16831683
void interaction_followup_delete(const std::string &token, command_completion_event_t callback = utility::log_error());
16841684

16851685
/**
1686-
* @brief Edit followup message to a slash command
1686+
* @brief Edit followup message for an interaction
16871687
* The message ID in the message you pass should be correctly set to that of a followup message you previously sent
16881688
*
16891689
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message
@@ -1695,7 +1695,7 @@ class DPP_EXPORT cluster {
16951695
void interaction_followup_edit(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error());
16961696

16971697
/**
1698-
* @brief Get the followup message to a slash command
1698+
* @brief Get the followup message for an interaction
16991699
*
17001700
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-followup-message
17011701
* @param token Token for the interaction webhook
@@ -1706,7 +1706,7 @@ class DPP_EXPORT cluster {
17061706
void interaction_followup_get(const std::string &token, snowflake message_id, command_completion_event_t callback);
17071707

17081708
/**
1709-
* @brief Get the original followup message to a slash command
1709+
* @brief Get the original followup message for an interaction
17101710
* This is an alias for cluster::interaction_response_get_original
17111711
* @see cluster::interaction_response_get_original
17121712
*

include/dpp/dispatcher.h

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,22 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
569569
*/
570570
void reply(const std::string& mt, command_completion_event_t callback = utility::log_error()) const;
571571

572+
/**
573+
* @brief Create a follow-up message for this interaction.
574+
* @param m Message object to send. Not all fields are supported by Discord.
575+
* @param callback User function to execute when the api call completes.
576+
* On success the callback will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
577+
*/
578+
void follow_up(const message& m, command_completion_event_t callback = utility::log_error()) const;
579+
580+
/**
581+
* @brief Create a follow-up message for this interaction.
582+
* @param mt The string value to send, for simple text only messages
583+
* @param callback User function to execute when the api call completes.
584+
* On success the callback will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
585+
*/
586+
void follow_up(const std::string& mt, command_completion_event_t callback = utility::log_error()) const;
587+
572588
/**
573589
* @brief Reply to interaction with a dialog box
574590
*
@@ -652,7 +668,7 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
652668
* @param m Message object to send. Not all fields are supported by Discord.
653669
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
654670
*/
655-
dpp::async<dpp::confirmation_callback_t> co_reply(interaction_response_type t, const message& m) const;
671+
dpp::async<dpp::confirmation_callback_t> co_reply(interaction_response_type t, message m) const;
656672

657673
/**
658674
* @brief Send a reply for this interaction
@@ -661,7 +677,7 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
661677
* @param mt The string value to send, for simple text only messages
662678
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
663679
*/
664-
dpp::async<dpp::confirmation_callback_t> co_reply(interaction_response_type t, const std::string& mt) const;
680+
dpp::async<dpp::confirmation_callback_t> co_reply(interaction_response_type t, std::string mt) const;
665681

666682
/**
667683
* @brief Send a reply for this interaction.
@@ -670,7 +686,7 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
670686
* @param m Message object to send. Not all fields are supported by Discord.
671687
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
672688
*/
673-
dpp::async<dpp::confirmation_callback_t> co_reply(const message& m) const;
689+
dpp::async<dpp::confirmation_callback_t> co_reply(message m) const;
674690

675691
/**
676692
* @brief Send a reply for this interaction.
@@ -679,31 +695,47 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
679695
* @param mt The string value to send, for simple text only messages
680696
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
681697
*/
682-
dpp::async<dpp::confirmation_callback_t> co_reply(const std::string& mt) const;
698+
dpp::async<dpp::confirmation_callback_t> co_reply(std::string mt) const;
699+
700+
/**
701+
* @brief Create a follow-up message for this interaction.
702+
*
703+
* @param m Message object to send. Not all fields are supported by Discord.
704+
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
705+
*/
706+
dpp::async<dpp::confirmation_callback_t> co_follow_up(message m) const;
707+
708+
/**
709+
* @brief Create a follow-up message for this interaction.
710+
*
711+
* @param mt The string value to send, for simple text only messages
712+
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
713+
*/
714+
dpp::async<dpp::confirmation_callback_t> co_follow_up(std::string mt) const;
683715

684716
/**
685717
* @brief Reply to interaction with a dialog box
686718
*
687719
* @param mr Dialog box response to send
688720
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
689721
*/
690-
dpp::async<dpp::confirmation_callback_t> co_dialog(const interaction_modal_response& mr) const;
722+
dpp::async<dpp::confirmation_callback_t> co_dialog(interaction_modal_response mr) const;
691723

692724
/**
693725
* @brief Edit the response for this interaction
694726
*
695727
* @param m Message object to send. Not all fields are supported by Discord.
696728
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
697729
*/
698-
dpp::async<dpp::confirmation_callback_t> co_edit_response(const message& m) const;
730+
dpp::async<dpp::confirmation_callback_t> co_edit_response(message m) const;
699731

700732
/**
701733
* @brief Edit the response for this interaction
702734
*
703735
* @param mt The string value to send, for simple text only messages
704736
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
705737
*/
706-
dpp::async<dpp::confirmation_callback_t> co_edit_response(const std::string& mt) const;
738+
dpp::async<dpp::confirmation_callback_t> co_edit_response(std::string mt) const;
707739

708740
/**
709741
* @brief Set the bot to 'thinking' state where you have up to 15 minutes to respond
@@ -726,7 +758,15 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
726758
* @param m Message object to send. Not all fields are supported by Discord.
727759
* On success the result will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
728760
*/
729-
dpp::async<dpp::confirmation_callback_t> co_edit_original_response(const message& m) const;
761+
dpp::async<dpp::confirmation_callback_t> co_edit_original_response(message m) const;
762+
763+
/**
764+
* @brief Edit original response message for this interaction
765+
*
766+
* @param mt The string value to send, for simple text only messages
767+
* On success the result will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
768+
*/
769+
dpp::async<dpp::confirmation_callback_t> co_edit_original_response(std::string mt) const;
730770

731771
/**
732772
* @brief Delete original response message for this interaction. This cannot be used on an ephemeral interaction response.
@@ -1757,23 +1797,15 @@ struct DPP_EXPORT message_create_t : public event_dispatch_t {
17571797
* @param m Text to send
17581798
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
17591799
*/
1760-
dpp::async<dpp::confirmation_callback_t> co_send(const std::string& m) const;
1761-
1762-
/**
1763-
* @brief Send a message to the same channel as the channel_id in received event.
1764-
*
1765-
* @param msg Message to send
1766-
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
1767-
*/
1768-
dpp::async<dpp::confirmation_callback_t> co_send(const message& msg) const;
1800+
dpp::async<dpp::confirmation_callback_t> co_send(std::string m) const;
17691801

17701802
/**
17711803
* @brief Send a message to the same channel as the channel_id in received event.
17721804
*
17731805
* @param msg Message to send
17741806
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
17751807
*/
1776-
dpp::async<dpp::confirmation_callback_t> co_send(message&& msg) const;
1808+
dpp::async<dpp::confirmation_callback_t> co_send(message msg) const;
17771809

17781810
/**
17791811
* @brief Reply to the message received in the event.
@@ -1782,7 +1814,7 @@ struct DPP_EXPORT message_create_t : public event_dispatch_t {
17821814
* @param mention_replied_user mentions (pings) the author of message replied to, if true
17831815
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
17841816
*/
1785-
dpp::async<dpp::confirmation_callback_t> co_reply(const std::string& m, bool mention_replied_user = false) const;
1817+
dpp::async<dpp::confirmation_callback_t> co_reply(std::string m, bool mention_replied_user = false) const;
17861818

17871819
/**
17881820
* @brief Reply to the message received in the event.
@@ -1791,16 +1823,7 @@ struct DPP_EXPORT message_create_t : public event_dispatch_t {
17911823
* @param mention_replied_user mentions (pings) the author of message replied to, if true
17921824
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
17931825
*/
1794-
dpp::async<dpp::confirmation_callback_t> co_reply(const message& msg, bool mention_replied_user = false) const;
1795-
1796-
/**
1797-
* @brief Reply to the message received in the event.
1798-
*
1799-
* @param msg Message to send as a reply.
1800-
* @param mention_replied_user mentions (pings) the author of message replied to, if true
1801-
* On success the result will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
1802-
*/
1803-
dpp::async<dpp::confirmation_callback_t> co_reply(message&& msg, bool mention_replied_user = false) const;
1826+
dpp::async<dpp::confirmation_callback_t> co_reply(message msg, bool mention_replied_user = false) const;
18041827
#endif /* DPP_NO_CORO */
18051828
};
18061829

0 commit comments

Comments
 (0)