diff --git a/libs/api/Author.hpp b/libs/api/Author.hpp index 074e40e..fd6bb70 100644 --- a/libs/api/Author.hpp +++ b/libs/api/Author.hpp @@ -9,7 +9,7 @@ private: WebSocket& web; NetworkManager& req; public: - Author(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {} + Author(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {}; string content() { try { return data["d"]["content"]; diff --git a/libs/api/Bot.hpp b/libs/api/Bot.hpp index b79a2d6..c0948fa 100644 --- a/libs/api/Bot.hpp +++ b/libs/api/Bot.hpp @@ -8,8 +8,7 @@ private: void initializeNets(const json& data) { initializeNetsImpl(data, std::index_sequence_for{}); } - template - void initializeNetsImpl(const json& data, std::index_sequence) { + templatevoid initializeNetsImpl(const json& data, std::index_sequence) { net = std::make_tuple(std::make_unique(data)...); } json data; @@ -18,6 +17,10 @@ public: Discord(const json& data) : data(data) { initializeNets(data); } + template + auto& get() const { + return *std::get(net); + } }; class Bot { private: diff --git a/libs/api/Message.hpp b/libs/api/Message.hpp index 98a1ed9..bf9c6f5 100644 --- a/libs/api/Message.hpp +++ b/libs/api/Message.hpp @@ -25,5 +25,8 @@ public: string deleteMessage(const string& channel_id, const string& message_id) { return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id); } + json pack(const json& pack) const { + return { pack }; + } }; #endif \ No newline at end of file diff --git a/libs/tls/Network.hpp b/libs/tls/Network.hpp index f278ce3..71443e6 100644 --- a/libs/tls/Network.hpp +++ b/libs/tls/Network.hpp @@ -16,7 +16,7 @@ private: curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init(); if (!curl) { - Log::create(ERROR, NETWORK, "Failed to initialize CURL"); + Log::create(CRITICAL, NETWORK, "Failed to initialize CURL"); abort(); } } diff --git a/libs/utils/enums.hpp b/libs/utils/enums.hpp index 13ecf92..95e95d4 100644 --- a/libs/utils/enums.hpp +++ b/libs/utils/enums.hpp @@ -84,23 +84,23 @@ struct HttpMethods { static constexpr const char* OPTIONS = "OPTIONS"; }; struct ApiVersion { - static inline std::string api = "/api/"; - static inline std::string v10 = "v10"; - static inline std::string v9 = "v9"; - static inline std::string v8 = "v8"; - static inline std::string v7 = "v7"; - static inline std::string v6 = "v6"; - static inline std::string current = api + v6; - static inline std::string latest = api + v10; + static const inline std::string api = "/api/"; + static const inline std::string v10 = "v10"; + static const inline std::string v9 = "v9"; + static const inline std::string v8 = "v8"; + static const inline std::string v7 = "v7"; + static const inline std::string v6 = "v6"; + static const inline std::string current = api + v6; + static const inline std::string latest = api + v10; }; struct DiscordEndpoints { - static inline std::string main_scheme = "https://"; - static inline std::string discord = main_scheme + "discord.com"; - static inline std::string images = main_scheme + "cdn.discord.com"; - static inline std::string media = main_scheme + "media.discord.com"; + static const inline std::string main_scheme = "https://"; + static const inline std::string discord = main_scheme + "discord.com"; + static const inline std::string images = main_scheme + "cdn.discord.com"; + static const inline std::string media = main_scheme + "media.discord.com"; struct details { - static inline std::string current = DiscordEndpoints::discord + ApiVersion::current; - static inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest; + static const inline std::string current = DiscordEndpoints::discord + ApiVersion::current; + static const inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest; }; }; enum GatewayIntents { diff --git a/libs/utils/log.hpp b/libs/utils/log.hpp index 5d7fb5b..b99799d 100644 --- a/libs/utils/log.hpp +++ b/libs/utils/log.hpp @@ -14,21 +14,11 @@ public: #ifdef DEBUG std::string color; switch (lvl) { - case INFO: - color = "\033[34;1m"; - break; - case WARNING: - color = "\033[33;1m"; - break; - case ERROR: - color = "\033[31;1m"; - break; - case CRITICAL: - color = "\033[31;1;2m"; - break; - default: - color = "\033[0m"; - break; + case INFO: color = "\033[34;1m"; break; + case WARNING: color = "\033[33;1m"; break; + case ERROR: color = "\033[31;1m"; break; + case CRITICAL: color = "\033[31;1;2m"; break; + default: color = "\033[0m"; break; } std::cout << color << "[" << getCurrentTime() << "][" << str(t) << "][" << str(lvl) << "] \033[0m" << message << "\033[0m" << std::endl; #endif diff --git a/libs/utils/types.hpp b/libs/utils/types.hpp index b285e18..5e84e84 100644 --- a/libs/utils/types.hpp +++ b/libs/utils/types.hpp @@ -3,6 +3,5 @@ #define j(...) {{__VA_ARGS__}} #define je(...) {__VA_ARGS__} #define g(x, y) (std::get(y)) -#define ALL_INTENTS 131071 -#define DEBUG +#define RELEASE #endif \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index 08def8d..60a025d 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -3,11 +3,11 @@ int main(int argc, char* argv[]) { if (argc != 3) return -1; WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents); - bot->on(GatewayEvents::READY, [](const Discorda) { + bot->on(GatewayEvents::READY, [](const Discord&a) { cout << DiscordEndpoints::details::latest << endl; }); - bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord msg) { - g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); + bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Discord& msg) { + msg.get<0>().send("939957962972229634", msg.get<0>().pack({ "content", msg.get<2>().content() })); }); bot->start(); return 0;