This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
sparkle/libs/api/Embed.hpp

58 lines
1.8 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_EMBED_HPP_
#define API_EMBED_HPP_
2025-01-15 13:34:41 +05:00
#include <includes.h>
2024-12-31 02:20:56 +05:00
class EmbedBuilder {
private:
2025-01-25 11:24:56 +05:00
nlohmann::json embed = {
2024-12-31 02:20:56 +05:00
{"content", ""},
{"tts", false},
2025-01-25 11:24:56 +05:00
{"embeds", nlohmann::json::array()}
2024-12-31 02:20:56 +05:00
}, data;
public:
2025-01-25 11:24:56 +05:00
EmbedBuilder(const nlohmann::json& data) : data(data) {
2024-12-31 02:20:56 +05:00
embed = {
{"content", ""},
{"tts", false},
2025-01-25 11:24:56 +05:00
{"embeds", nlohmann::json::array()}
2024-12-31 02:20:56 +05:00
};
}
2025-01-25 11:24:56 +05:00
EmbedBuilder& addTitle(const std::string& title) {
2024-12-31 02:20:56 +05:00
if (embed["embeds"].size() == 0) {
2025-01-25 11:24:56 +05:00
embed["embeds"].emplace_back(nlohmann::json::object());
2024-12-31 02:20:56 +05:00
}
embed["embeds"].back()["title"] = title;
return *this;
}
2025-01-25 11:24:56 +05:00
EmbedBuilder& addDescription(const std::string& desc) {
2024-12-31 02:20:56 +05:00
if (embed["embeds"].size() == 0) {
2025-01-25 11:24:56 +05:00
embed["embeds"].emplace_back(nlohmann::json::object());
2024-12-31 02:20:56 +05:00
}
embed["embeds"].back()["description"] = desc;
return *this;
}
2025-01-25 11:24:56 +05:00
EmbedBuilder& addColor(const std::string& color) {
2024-12-31 02:20:56 +05:00
if (embed["embeds"].size() == 0) {
2025-01-25 11:24:56 +05:00
embed["embeds"].emplace_back(nlohmann::json::object());
2024-12-31 02:20:56 +05:00
}
embed["embeds"].back()["color"] = color;
return *this;
}
2025-01-25 11:24:56 +05:00
EmbedBuilder& addUrl(const std::string& url) {
2024-12-31 02:20:56 +05:00
if (embed["embeds"].size() == 0) {
2025-01-25 11:24:56 +05:00
embed["embeds"].emplace_back(nlohmann::json::object());
2024-12-31 02:20:56 +05:00
}
embed["embeds"].back()["url"] = url;
return *this;
}
2025-01-25 11:24:56 +05:00
EmbedBuilder& addImage(const std::string& imageurl) {
2024-12-31 02:20:56 +05:00
if (embed["embeds"].size() == 0) {
2025-01-25 11:24:56 +05:00
embed["embeds"].emplace_back(nlohmann::json::object());
2024-12-31 02:20:56 +05:00
}
embed["embeds"].back()["image"] = { {"url", imageurl} };
return *this;
}
2025-01-25 11:24:56 +05:00
nlohmann::json getEmbed() const {
2024-12-31 02:20:56 +05:00
return embed;
}
};
#endif