Compare commits

..

No commits in common. "94f6a58f748d9d2cf566b74ab76101c44692c5ab" and "d4595305b471e0e9de523db45da42e05431fade2" have entirely different histories.

2 changed files with 9 additions and 16 deletions

View File

@ -39,7 +39,7 @@ void cmd::handle_regular_message(context *ctx, td_api::message &msg) {
nullptr /*reply_to*/, nullptr /*options*/, nullptr /*reply_to*/, nullptr /*options*/,
nullptr, // reply_markup nullptr, // reply_markup
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>( static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
std::move(td_api::make_object<td_api::formattedText>(!url.empty() ? url : "error :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))), std::move(td_api::make_object<td_api::formattedText>(url, std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
nullptr /*link_preview_options*/, false /*clear_draft*/ nullptr /*link_preview_options*/, false /*clear_draft*/
)) ))
), {}); ), {});
@ -50,7 +50,7 @@ void cmd::handle_regular_message(context *ctx, td_api::message &msg) {
nullptr /*reply_to*/, nullptr /*options*/, nullptr /*reply_to*/, nullptr /*options*/,
nullptr, // reply_markup nullptr, // reply_markup
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>( static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
std::move(td_api::make_object<td_api::formattedText>("error :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))), std::move(td_api::make_object<td_api::formattedText>("произошла какая-то ошибка :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
nullptr /*link_preview_options*/, false /*clear_draft*/ nullptr /*link_preview_options*/, false /*clear_draft*/
)) ))
), {}); ), {});
@ -137,7 +137,7 @@ void cmd::handle_callback_query(context *ctx, td_api::updateNewInlineCallbackQue
nullptr, // reply_markup nullptr, // reply_markup
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>( static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
td_api::make_object<td_api::formattedText>( td_api::make_object<td_api::formattedText>(
!url.empty() ? url : "error :(", url,
std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()) std::move(std::vector<td_api::object_ptr<td_api::textEntity>>())
), ),
td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false), td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false),
@ -171,7 +171,7 @@ void cmd::handle_chosen_inline_result(context *ctx, td_api::updateNewChosenInlin
nullptr, // reply_markup nullptr, // reply_markup
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>( static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
td_api::make_object<td_api::formattedText>( td_api::make_object<td_api::formattedText>(
!url.empty() ? url : "error :(", url,
std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()) std::move(std::vector<td_api::object_ptr<td_api::textEntity>>())
), ),
td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false), td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false),
@ -189,7 +189,7 @@ bool cmd::shorten_link(std::string link, context *ctx, std::function<void(std::s
return false; return false;
} }
char *escapedParam = curl_easy_escape(req, link.data(), link.size()); char *escapedParam = curl_easy_escape(req, link.data(), link.size());
std::string url("https://xurl.pw/create?url="); std::string url("https://slavasil.ru/create?url=");
url += escapedParam; url += escapedParam;
curl_free(escapedParam); curl_free(escapedParam);
curl_easy_setopt(req, CURLOPT_URL, url.c_str()); curl_easy_setopt(req, CURLOPT_URL, url.c_str());
@ -198,16 +198,9 @@ bool cmd::shorten_link(std::string link, context *ctx, std::function<void(std::s
curl_easy_setopt(req, CURLOPT_PRIVATE, ctx); curl_easy_setopt(req, CURLOPT_PRIVATE, ctx);
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1);
ctx->requests.emplace(req, [cb, req, ctx](active_request &r){ ctx->requests.emplace(req, [cb, req, ctx](active_request &r){
long statusCode;
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &statusCode);
if (statusCode == 200) {
std::string shortenedUrl(r.receivedData.data(), r.receivedData.size()); std::string shortenedUrl(r.receivedData.data(), r.receivedData.size());
spdlog::info("Received data from HTTP server: {}", shortenedUrl); spdlog::info("Received data from HTTP server: {}", shortenedUrl);
cb(shortenedUrl); cb(shortenedUrl);
} else {
spdlog::error("Shortener returned error: {}", statusCode);
cb("");
}
ctx->requests.erase(req); ctx->requests.erase(req);
}); });
CURLMcode r = curl_multi_add_handle(ctx->curl, req); CURLMcode r = curl_multi_add_handle(ctx->curl, req);

View File

@ -334,7 +334,7 @@ void check_curl_multi_info(context *ctx) {
} }
size_t curl_receive_cb(char *ptr, size_t size, size_t nmemb, CURL *curl) { size_t curl_receive_cb(char *ptr, size_t size, size_t nmemb, CURL *curl) {
spdlog::debug("received {} bytes from: '{}'", nmemb, nmemb <= 50 ? std::string(ptr, nmemb) : std::string(ptr, 47)+"..."); spdlog::debug("received {} bytes from server: '{}'", nmemb, std::string(ptr, nmemb));
context *ctx = nullptr; context *ctx = nullptr;
curl_easy_getinfo(curl, CURLINFO_PRIVATE, &ctx); curl_easy_getinfo(curl, CURLINFO_PRIVATE, &ctx);