-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add more message api routes; refactor; re-enable auto reconne…
…ct; fix heartbeat task not being removed
- Loading branch information
Xminent
committed
Nov 15, 2023
1 parent
b6af576
commit 756a6cd
Showing
23 changed files
with
568 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef EKIZU_REQUEST_CROSSPOST_MESSAGE_HPP | ||
#define EKIZU_REQUEST_CROSSPOST_MESSAGE_HPP | ||
|
||
#include <ekizu/snowflake.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
/** | ||
* @brief Represents the Crosspost Message REST API endpoint. | ||
*/ | ||
struct CrosspostMessage { | ||
CrosspostMessage( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, Snowflake message_id); | ||
|
||
/** | ||
* @brief Converts the CrosspostMessage to an HTTP request. | ||
* | ||
* @return The HTTP request. | ||
*/ | ||
operator net::HttpRequest() const; | ||
|
||
/** | ||
* @brief Sends the CrosspostMessage request. | ||
* | ||
* @return The result of the request as an HTTP response. | ||
*/ | ||
[[nodiscard]] Result<net::HttpResponse> send() const; | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
Snowflake m_message_id; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_CROSSPOST_MESSAGE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#ifndef EKIZU_REQUEST_EDIT_MESSAGE_HPP | ||
#define EKIZU_REQUEST_EDIT_MESSAGE_HPP | ||
|
||
#include <ekizu/message.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
struct EditMessageFields { | ||
/// Message contents (up to 2000 characters). | ||
std::optional<std::string> content; | ||
/// Up to 10 rich embeds (up to 6000 characters). | ||
std::optional<std::vector<Embed> > embeds; | ||
/// Message flags combined as a bitfield (only SUPPRESS_EMBEDS and SUPPRESS_NOTIFICATIONS can be set). | ||
std::optional<MessageFlags> flags; | ||
/// Allowed mentions for the message. | ||
std::optional<AllowedMentions> allowed_mentions; | ||
/// Components to include with the message. | ||
std::optional<std::vector<MessageComponent> > components; | ||
/// JSON-encoded body of non-file params, only for multipart/form-data requests. See Uploading Files. | ||
std::optional<std::string> payload_json; | ||
/// Attachment objects with filename and description. See Uploading Files. | ||
std::optional<std::vector<PartialAttachment> > attachments; | ||
}; | ||
|
||
EKIZU_EXPORT void to_json(nlohmann::json &j, const EditMessageFields &f); | ||
EKIZU_EXPORT void from_json(const nlohmann::json &j, EditMessageFields &f); | ||
|
||
struct EditMessage { | ||
EditMessage( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, Snowflake message_id); | ||
|
||
operator net::HttpRequest() const; | ||
|
||
EditMessage &allowed_mentions(AllowedMentions allowed_mentions) | ||
{ | ||
m_fields.allowed_mentions = allowed_mentions; | ||
return *this; | ||
} | ||
|
||
EditMessage &content(std::string_view content) | ||
{ | ||
// TODO: Validate content | ||
m_fields.content = content; | ||
return *this; | ||
} | ||
|
||
EditMessage &embeds(const std::vector<Embed> &embeds) | ||
{ | ||
// TODO: Validate embeds | ||
m_fields.embeds = embeds; | ||
return *this; | ||
} | ||
|
||
EditMessage &flags(MessageFlags flags) | ||
{ | ||
m_fields.flags = flags; | ||
return *this; | ||
} | ||
|
||
EditMessage &payload_json(std::string_view payload_json) | ||
{ | ||
m_fields.payload_json = payload_json; | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] Result<net::HttpResponse> send() const; | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
Snowflake m_message_id; | ||
EditMessageFields m_fields; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_EDIT_MESSAGE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef EKIZU_REQUEST_GET_CHANNEL_HPP | ||
#define EKIZU_REQUEST_GET_CHANNEL_HPP | ||
|
||
#include <ekizu/channel.hpp> | ||
#include <ekizu/snowflake.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
/** | ||
* @brief Represents the Get Channel REST API endpoint. | ||
*/ | ||
struct GetChannel { | ||
GetChannel( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id); | ||
|
||
/** | ||
* @brief Converts the GetChannel to an HTTP request. | ||
* | ||
* @return The HTTP request. | ||
*/ | ||
operator net::HttpRequest() const; | ||
|
||
/** | ||
* @brief Sends the GetChannel request. | ||
* | ||
* @return The result of the request as an HTTP response. | ||
*/ | ||
[[nodiscard]] Result<Channel> send() const; | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_GET_CHANNEL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef EKIZU_REQUEST_PIN_MESSAGE_HPP | ||
#define EKIZU_REQUEST_PIN_MESSAGE_HPP | ||
|
||
#include <ekizu/snowflake.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
/** | ||
* @brief Represents the Pin Message REST API endpoint. | ||
*/ | ||
struct PinMessage { | ||
PinMessage( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, Snowflake message_id); | ||
|
||
/** | ||
* @brief Converts the PinMessage to an HTTP request. | ||
* | ||
* @return The HTTP request. | ||
*/ | ||
operator net::HttpRequest() const; | ||
|
||
/** | ||
* @brief Sends the PinMessage request. | ||
* | ||
* @return The result of the request as an HTTP response. | ||
*/ | ||
[[nodiscard]] Result<net::HttpResponse> send() const; | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
Snowflake m_message_id; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_PIN_MESSAGE_HPP |
Oops, something went wrong.