Skip to content

Commit

Permalink
feat: ✨ add EmbedBuilder; update examples; add RateLimiter; add docum…
Browse files Browse the repository at this point in the history
…entation; add CreateMessage fields
  • Loading branch information
jontitorr committed Nov 3, 2023
1 parent 26d5fd4 commit 795a8e5
Show file tree
Hide file tree
Showing 27 changed files with 681 additions and 567 deletions.
2 changes: 1 addition & 1 deletion examples/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::function<void(Event)> handle_event(HttpClient &http)
const auto res =
http.create_message(
msg.channel_id)
.with_content(fmt::format(
.content(fmt::format(
"{} said: {}\nAvatar: {}",
msg.author
.username,
Expand Down
23 changes: 22 additions & 1 deletion examples/simple_with_logging.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "ekizu/embed_builder.hpp"
#include <dotenv/dotenv.h>
#include <ekizu/http_client.hpp>
#include <ekizu/shard.hpp>
Expand Down Expand Up @@ -84,10 +85,29 @@ std::function<void(Event)> handle_event(HttpClient &http)
logger->info("Message: {}",
msg.content);

const auto embed =
EmbedBuilder{}
.add_field(EmbedField{
"message",
msg.content,
false })
.set_author({
msg.author
.username,
{},
"https://thicc.mywaifulist.moe/waifus/3/f64620cfa45bcab439a9d4b1990c550801a97dc65b55cbc76c0c947a2b139443_thumb.jpg",
})
.set_footer(
{ "Generated by: ekizu with C++",
"https://thicc.mywaifulist.moe/waifus/2719/5ab850fd407af23507f85ea0b09c1dae6c9f1534ee1ef6ba4649a3dc2f603552_thumb.jpg" })
.set_image(
{ "https://avatars.githubusercontent.com/u/59069386?v=4" })
.build();

const auto res =
http.create_message(
msg.channel_id)
.with_content(fmt::format(
.content(fmt::format(
"{} said: {}\nAvatar: {}",
msg.author
.username,
Expand All @@ -96,6 +116,7 @@ std::function<void(Event)> handle_event(HttpClient &http)
*msg.author
.avatar :
"null"))
.embeds({ embed })
.send();

if (!res) {
Expand Down
16 changes: 16 additions & 0 deletions include/ekizu/attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define EKIZU_ATTACHMENT_HPP

#include <ekizu/snowflake.hpp>
#include <optional>

namespace ekizu
{
Expand Down Expand Up @@ -42,6 +43,21 @@ struct Attachment {

EKIZU_EXPORT void to_json(nlohmann::json &j, const Attachment &a);
EKIZU_EXPORT void from_json(const nlohmann::json &j, Attachment &a);

/**
* @brief Represents a partial attachment.
*/
struct PartialAttachment {
/// ID of the attachment.
std::optional<Snowflake> id;
/// Name of the file attached.
std::optional<std::string> filename;
/// Description for the file (max 1024 characters).
std::optional<std::string> description;
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const PartialAttachment &a);
EKIZU_EXPORT void from_json(const nlohmann::json &j, PartialAttachment &a);
} // namespace ekizu

#endif // EKIZU_ATTACHMENT_HPP
39 changes: 0 additions & 39 deletions include/ekizu/discord_api.hpp

This file was deleted.

72 changes: 0 additions & 72 deletions include/ekizu/discord_request_manager.hpp

This file was deleted.

126 changes: 11 additions & 115 deletions include/ekizu/embed.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef EKIZU_EMBED_HPP
#define EKIZU_EMBED_HPP

#include <nlohmann/json_fwd.hpp>
#include <ekizu/export.h>
#include <nlohmann/json_fwd.hpp>
#include <optional>
#include <string>

Expand All @@ -14,13 +14,13 @@ namespace ekizu
*/
struct EmbedImage {
/// The URL of the media.
std::optional<std::string> url;
std::optional<std::string> url{};
/// The proxy URL of the media.
std::optional<std::string> proxy_url;
std::optional<std::string> proxy_url{};
/// The height of the media.
std::optional<uint16_t> height;
std::optional<uint16_t> height{};
/// The width of the media.
std::optional<uint16_t> width;
std::optional<uint16_t> width{};
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const EmbedImage &i);
Expand All @@ -43,11 +43,11 @@ struct EmbedAuthor {
/// The name of the author.
std::string name;
/// The URL of the author.
std::optional<std::string> url;
std::optional<std::string> url{};
/// The URL of the author's icon.
std::optional<std::string> icon_url;
std::optional<std::string> icon_url{};
/// The proxied URL of the author's icon.
std::optional<std::string> proxy_icon_url;
std::optional<std::string> proxy_icon_url{};
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const EmbedAuthor &a);
Expand All @@ -57,9 +57,9 @@ struct EmbedFooter {
/// The text of the footer.
std::string text;
/// The URL of the footer icon.
std::optional<std::string> icon_url;
std::optional<std::string> icon_url{};
/// The proxied URL of the footer icon.
std::optional<std::string> proxy_icon_url;
std::optional<std::string> proxy_icon_url{};
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const EmbedFooter &f);
Expand All @@ -71,7 +71,7 @@ struct EmbedField {
/// The value of the field.
std::string value;
/// Whether or not the field is inline.
std::optional<bool> inline_;
std::optional<bool> inline_{};
};

EKIZU_EXPORT void to_json(nlohmann::json &j, const EmbedField &f);
Expand All @@ -82,110 +82,6 @@ EKIZU_EXPORT void from_json(const nlohmann::json &j, EmbedField &f);
* that can be attached to a regular message to provide rich content.
*/
struct Embed {
/**
* @brief Adds a field to the Embed.
*
* @param field The field to add.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &add_field(const EmbedField &field);

/**
* @brief Adds multiple fields to the Embed.
*
* @param fields The fields to add.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &add_fields(const std::vector<EmbedField> &fields);

/**
* @brief Sets the author of the Embed.
*
* @param author The author to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_author(const EmbedAuthor &author);

/**
* @brief Set the color of the Embed.
*
* @param color The color to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_color(uint16_t color);

/**
* @brief Set the description of the Embed.
*
* @param description The description to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_description(const std::string &description);

/**
* @brief Sets the footer of the Embed.
*
* @param footer The footer to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_footer(const EmbedFooter &footer);

/**
* @brief Sets the image of the Embed.
*
* @param image The image to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_image(const EmbedImage &image);

/**
* @brief Sets the provider of the Embed.
*
* @param provider The provider to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_provider(const EmbedProvider &provider);

/**
* @brief Sets the thumbnail of the Embed.
*
* @param thumbnail The thumbnail to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_thumbnail(const EmbedThumbnail &thumbnail);

/**
* @brief Sets the title of the Embed.
*
* @param title The title to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_title(const std::string &title);

/**
* @brief Sets the URL of the Embed.
*
* @param url The URL to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_url(const std::string &url);

/**
* @brief Sets the video of the Embed.
*
* @param video The video to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_video(const EmbedVideo &video);

/**
* @brief Sets the fields of the Embed.
*
* @param fields The fields to set.
* @return Embed& A reference to the Embed object.
*/
EKIZU_EXPORT Embed &set_fields(const std::vector<EmbedField> &fields);

/// The title of the embed.
std::optional<std::string> title;
/// The description of the embed.
Expand Down
Loading

0 comments on commit 795a8e5

Please sign in to comment.