diff options
Diffstat (limited to 'bot/src/commands/lua.cpp')
| -rw-r--r-- | bot/src/commands/lua.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 17c5ba3..7b06082 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -24,6 +24,7 @@ #include "commands/response_error.hpp" #include "cpr/api.h" #include "cpr/cprtypes.h" +#include "cpr/multipart.h" #include "cpr/response.h" #include "schemas/user.hpp" #include "utils/chrono.hpp" @@ -242,6 +243,32 @@ namespace bot::command::lua { return t; }); + + state->set_function( + "net_post_multipart_with_headers", + [state](const std::string &url, const sol::table &body, + const sol::table &headers) { + sol::table t = state->create_table(); + + cpr::Header h{}; + + for (auto &kv : headers) { + h[kv.first.as<std::string>()] = kv.second.as<std::string>(); + } + + cpr::Multipart multipart = {}; + for (auto &kv : body) { + multipart.parts.push_back( + {kv.first.as<std::string>(), kv.second.as<std::string>()}); + } + + cpr::Response response = cpr::Post(cpr::Url{url}, multipart, h); + + t["code"] = response.status_code; + t["text"] = response.text; + + return t; + }); } void add_l10n_library(std::shared_ptr<sol::state> state) { |
