diff --git a/include/dpp/httpsclient.h b/include/dpp/httpsclient.h index 09bbd8453d..0d6c5057aa 100644 --- a/include/dpp/httpsclient.h +++ b/include/dpp/httpsclient.h @@ -27,9 +27,17 @@ #include #include #include +#include +#include namespace dpp { +static inline const std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, " + + to_hex(DPP_VERSION_MAJOR) + "." + + to_hex(DPP_VERSION_MINOR) + "." + + to_hex(DPP_VERSION_PATCH) + ")"; + +static inline constexpr const char* DISCORD_HOST = "https://discord.com"; /** * @brief HTTP connection status diff --git a/src/dpp/queues.cpp b/src/dpp/queues.cpp index 2c7fed5af2..4625020a46 100644 --- a/src/dpp/queues.cpp +++ b/src/dpp/queues.cpp @@ -29,13 +29,9 @@ #include #include #include -#include namespace dpp { -static std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, " + std::to_string(DPP_VERSION_MAJOR) + "." + std::to_string(DPP_VERSION_MINOR) + "." + std::to_string(DPP_VERSION_PATCH) + ")"; -static const char* DISCORD_HOST = "https://discord.com"; - http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method _method, const std::string &audit_reason, const std::string &filename, const std::string &filecontent, const std::string &filemimetype) : complete_handler(completion), completed(false), non_discord(false), endpoint(_endpoint), parameters(_parameters), postdata(_postdata), method(_method), reason(audit_reason), mimetype("application/json"), waiting(false) { diff --git a/src/dpp/utility.cpp b/src/dpp/utility.cpp index 8a28201c33..04db275526 100644 --- a/src/dpp/utility.cpp +++ b/src/dpp/utility.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/src/dpp/wsclient.cpp b/src/dpp/wsclient.cpp index d94abca54d..d23f6742af 100644 --- a/src/dpp/wsclient.cpp +++ b/src/dpp/wsclient.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace dpp { @@ -52,7 +53,7 @@ void websocket_client::connect() "GET " + this->path + " HTTP/1.1\r\n" "Host: " + this->hostname + "\r\n" "pragma: no-cache\r\n" - "User-Agent: " + "DiscordBot (https://github.com/brainboxdotcc/DPP, 16.0.38)" + "\r\n" + "User-Agent: " + http_version + "\r\n" "Upgrade: WebSocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Key: " + this->key + "\r\n" diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index f3adb662f9..f08b300366 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -169,10 +169,16 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b set_test(READFILE, false); std::string rf_test = dpp::utility::read_file(SHARED_OBJECT); FILE* fp = fopen(SHARED_OBJECT, "rb"); - fseek(fp, 0, SEEK_END); - size_t off = (size_t)ftell(fp); - fclose(fp); - set_test(READFILE, off == rf_test.length()); + if (!fp) { + std::cout << "READFILE: Failed to open file: " << SHARED_OBJECT << "\n"; + set_test(READFILE, false); + } + else { + fseek(fp, 0, SEEK_END); + size_t off = (size_t)ftell(fp); + fclose(fp); + set_test(READFILE, off == rf_test.length()); + } set_test(TIMESTAMPTOSTRING, false); set_test(TIMESTAMPTOSTRING, dpp::ts_to_string(1642611864) == "2022-01-19T17:04:24Z");