diff --git a/include/api.h b/include/api.hpp similarity index 75% rename from include/api.h rename to include/api.hpp index 6bc95de..c29c3e3 100644 --- a/include/api.h +++ b/include/api.hpp @@ -1,5 +1,5 @@ -#ifndef INCLUDE_API_H_ -#define INCLUDE_API_H_ +#ifndef INCLUDE_API_HPP_ +#define INCLUDE_API_HPP_ #include #include #include diff --git a/include/includes.h b/include/includes.hpp similarity index 72% rename from include/includes.h rename to include/includes.hpp index 35a0ef4..c214431 100644 --- a/include/includes.h +++ b/include/includes.hpp @@ -1,5 +1,5 @@ -#ifndef INCLUDE_INCLUDES_H_ -#define INCLUDE_INCLUDES_H_ +#ifndef INCLUDE_INCLUDES_HPP_ +#define INCLUDE_INCLUDES_HPP_ #include #include #include diff --git a/include/net.h b/include/net.hpp similarity index 53% rename from include/net.h rename to include/net.hpp index 0faeee1..127e0d0 100644 --- a/include/net.h +++ b/include/net.hpp @@ -1,5 +1,5 @@ -#ifndef INCLUDE_NET_H_ -#define INCLUDE_NET_H_ +#ifndef INCLUDE_NET_HPP_ +#define INCLUDE_NET_HPP_ #include #include #endif \ No newline at end of file diff --git a/libs/api/Author.hpp b/libs/api/Author.hpp index 1270d44..e2157df 100644 --- a/libs/api/Author.hpp +++ b/libs/api/Author.hpp @@ -1,11 +1,11 @@ #ifndef API_AUTHOR_HPP_ #define API_AUTHOR_HPP_ -#include -#include +#include +#include class Author { private: nlohmann::json data; - const nlohmann::json &d; + const nlohmann::json& d; WebSocket& web; NetworkManager& req; public: @@ -25,7 +25,8 @@ public: discriminator(d["author"]["discriminator"]), message_id(d["id"]), isPinned(d["pinned"]), - isBot(d["author"].contains("bot") ? d["author"]["bot"].get() : false) {}; + isBot(d["author"].contains("bot") ? d["author"]["bot"].get() : false) { + }; std::string send(const nlohmann::json& msg) { return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + d["channel_id"].get() + "/messages", msg.dump()); } diff --git a/libs/api/Bot.hpp b/libs/api/Bot.hpp index 5e7b56f..d1f0a06 100644 --- a/libs/api/Bot.hpp +++ b/libs/api/Bot.hpp @@ -1,6 +1,6 @@ #ifndef API_BOT_HPP_ #define API_BOT_HPP_ -#include +#include template class Discord { private: @@ -33,8 +33,7 @@ public: bool isBot() const { try { return data["d"]["bot"]; - } - catch (...) { + } catch (...) { return false; } } diff --git a/libs/api/Channel.hpp b/libs/api/Channel.hpp index 548f2b3..f46a5fa 100644 --- a/libs/api/Channel.hpp +++ b/libs/api/Channel.hpp @@ -1,7 +1,7 @@ #ifndef API_CHANNEL_HPP_ #define API_CHANNEL_HPP_ -#include -#include +#include +#include class Channel { private: nlohmann::json data; diff --git a/libs/api/Embed.hpp b/libs/api/Embed.hpp index d689e17..69b26fb 100644 --- a/libs/api/Embed.hpp +++ b/libs/api/Embed.hpp @@ -1,6 +1,6 @@ #ifndef API_EMBED_HPP_ #define API_EMBED_HPP_ -#include +#include class EmbedBuilder { private: nlohmann::json embed = { diff --git a/libs/api/Guild.hpp b/libs/api/Guild.hpp index 0b684dd..16351b2 100644 --- a/libs/api/Guild.hpp +++ b/libs/api/Guild.hpp @@ -1,7 +1,7 @@ #ifndef API_GUILD_HPP_ #define API_GUILD_HPP_ -#include -#include +#include +#include class Guild { private: nlohmann::json data; diff --git a/libs/api/Message.hpp b/libs/api/Message.hpp index 6f0c284..9de19b2 100644 --- a/libs/api/Message.hpp +++ b/libs/api/Message.hpp @@ -1,7 +1,7 @@ #ifndef API_MESSAGE_HPP_ #define API_MESSAGE_HPP_ -#include -#include +#include +#include class Message { private: nlohmann::json data; @@ -15,8 +15,7 @@ public: std::string getMessages(const std::string& id, const std::string& count, const std::string& before = "") { if (before.empty()) { return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?limit=" + count); - } - else { + } else { return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?before=" + before + "&limit=" + count); } return ""; @@ -25,7 +24,7 @@ public: return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id); } nlohmann::json pack(const nlohmann::json& key, const std::string& value) const { - return {{ key, value }}; + return { { key, value } }; } struct Api { nlohmann::json data; diff --git a/libs/api/User.hpp b/libs/api/User.hpp index c5feff3..ee4ab9e 100644 --- a/libs/api/User.hpp +++ b/libs/api/User.hpp @@ -1,7 +1,7 @@ #ifndef API_USER_HPP_ #define API_USER_HPP_ -#include -#include +#include +#include #include class User { private: @@ -10,7 +10,7 @@ private: NetworkManager& req; public: User(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {} - #ifdef DEBUG +#ifdef DEBUG nlohmann::json extract(const std::vector& keys) { std::vector d = { "d" }; d.insert(d.end(), keys.begin(), keys.end()); @@ -18,22 +18,20 @@ public: for (const auto& key : d) { if (current.contains(key)) { current = current[key]; - } - else { + } else { return "Key not found."; } } return current; } - #endif +#endif std::string me() { return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/users/@me"); } bool isBot() const { try { return data["d"]["author"]["bot"]; - } - catch (...) { + } catch (...) { return false; } } diff --git a/libs/gateway/Websocket.hpp b/libs/gateway/Websocket.hpp index 359821a..84c235f 100644 --- a/libs/gateway/Websocket.hpp +++ b/libs/gateway/Websocket.hpp @@ -1,6 +1,6 @@ #ifndef GATEWAY_WEBSOCKET_HPP_ #define GATEWAY_WEBSOCKET_HPP_ -#include +#include #include #include #include @@ -30,19 +30,19 @@ private: {"browser", "firefox"}, {"device", "firefox"} }}, - //{"compress", 1}, - {"presence", { - {"activities", nlohmann::json::array({ - { - //{"name", "asdsadsadsadsa"}, - //{"type", 2} - } - })}, - {"status", "idle"}, - {"since", 91879201}, - {"afk", false} - }} + //{"compress", 1}, + {"presence", { + {"activities", nlohmann::json::array({ + { + //{"name", "asdsadsadsadsa"}, + //{"type", 2} + } + })}, + {"status", "idle"}, + {"since", 91879201}, + {"afk", false} }} + }} }; ix::initNetSystem(); webSocket.setUrl("wss://gateway.discord.gg/?v=10&encoding=json"); @@ -53,22 +53,22 @@ private: res = nlohmann::json::parse(msg->str); Log::create(INFO, WEBSOCKET, res["op"].dump() + " " + res["t"].dump()); switch (res["op"].get()) { - case 10: - heartbeat_interval = res["d"]["heartbeat_interval"].get(); - !connected ? connected = true, webSocket.send(id.dump()) : 0; - std::thread([this, &heartbeat_interval, &connected]() { - while (connected && heartbeat_interval != -1) { - Log::create(INFO, WEBSOCKET, "Heartbeat " + std::to_string(heartbeat_interval)); - std::this_thread::sleep_for(milliseconds(heartbeat_interval)); - webSocket.send(payload.dump()); + case 10: + heartbeat_interval = res["d"]["heartbeat_interval"].get(); + !connected ? connected = true, webSocket.send(id.dump()) : 0; + std::thread([this, &heartbeat_interval, &connected]() { + while (connected && heartbeat_interval != -1) { + Log::create(INFO, WEBSOCKET, "Heartbeat " + std::to_string(heartbeat_interval)); + std::this_thread::sleep_for(milliseconds(heartbeat_interval)); + webSocket.send(payload.dump()); + } + }).detach(); + break; + case 0: + if (eventHandlers.find(res["t"].get()) != eventHandlers.end()) { + eventHandlers[res["t"].get()](res); } - }).detach(); - break; - case 0: - if (eventHandlers.find(res["t"].get()) != eventHandlers.end()) { - eventHandlers[res["t"].get()](res); - } - break; + break; } } }); diff --git a/libs/network/Network.hpp b/libs/network/Network.hpp index ae909f5..b73c878 100644 --- a/libs/network/Network.hpp +++ b/libs/network/Network.hpp @@ -1,6 +1,6 @@ #ifndef TLS_NETWORK_HPP_ #define TLS_NETWORK_HPP_ -#include +#include #include #include class NetworkManager { diff --git a/sources/main.cpp b/sources/main.cpp index 18d776f..1abca0f 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include int main(int argc, char* argv[]) { if (argc != 3) return -1; WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents); diff --git a/tests/tests.cpp b/tests/tests.cpp index 5a07259..5821b31 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include TEST(NetworkManagerTest, RequestReturnsExpectedValue) { NetworkManager& networkManager = NetworkManager::getInstance(); EXPECT_FALSE(networkManager.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/939957962972229634/messages", { "content", "test" }).empty());