diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 468ca55..adf4be9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -226,4 +226,3 @@ jobs: --amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64 \ --amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le docker manifest push ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }} - diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d34610..7df120f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ if (CLANG OR GCC) endif() endif() -set(TG_HTTP_CLIENT_SOURCE +set(TELEGRAM_BOT_API_SOURCE telegram-bot-api/telegram-bot-api.cpp telegram-bot-api/Client.cpp @@ -70,7 +70,7 @@ set(TG_HTTP_CLIENT_SOURCE telegram-bot-api/WebhookActor.h ) -add_executable(telegram-bot-api ${TG_HTTP_CLIENT_SOURCE}) +add_executable(telegram-bot-api ${TELEGRAM_BOT_API_SOURCE}) target_include_directories(telegram-bot-api PRIVATE $) target_link_libraries(telegram-bot-api PRIVATE memprof tdactor tdcore tddb tdnet tdutils) diff --git a/build.html b/build.html index 82c4c38..7c31d38 100644 --- a/build.html +++ b/build.html @@ -32,6 +32,8 @@ select.large { font-size: large; } g++ - +

@@ -174,7 +176,7 @@ function onOptionsChanged() { document.getElementById('buildCommandsDiv').style.display = 'block'; var use_clang = os_freebsd || os_openbsd; - if (os_linux && linux_distro !== 'Alpine') { + if (os_linux && linux_distro !== 'Alpine' && !linux_distro.includes('CentOS')) { document.getElementById('buildCompilerDiv').style.display = 'block'; use_clang = document.getElementById('buildCompilerRadioClang').checked; } else { @@ -250,7 +252,7 @@ function onOptionsChanged() { pre_text.push('Download and install gperf. Add the path to gperf.exe to the PATH environment variable.'); } if (os_linux && linux_distro === 'Other') { - var compiler = use_clang ? 'clang++ >= 3.4' : 'g++ >= 4.9.2'; + var compiler = use_clang ? 'clang >= 3.4' : 'g++ >= 4.9.2'; pre_text.push('Install Git, ' + compiler + ', make, CMake >= 3.0.2, OpenSSL-dev, zlib-dev, gperf using your package manager.'); } if (os_freebsd) { @@ -309,6 +311,7 @@ function onOptionsChanged() { var commands = []; + var cmake = 'cmake'; if (os_mac) { commands.push('xcode-select --install'); commands.push('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'); @@ -321,6 +324,21 @@ function onOptionsChanged() { var packages = 'alpine-sdk linux-headers git zlib-dev openssl-dev gperf cmake'; commands.push(sudo + 'apk add --update ' + packages); break; + case 'CentOS 7': + case 'CentOS 8': + commands.push(sudo + 'yum update -y'); + var packages = 'gcc-c++ make git zlib-devel openssl-devel'; + if (linux_distro === 'CentOS 7') { + commands.push(sudo + 'yum install -y centos-release-scl-rh epel-release'); + commands.push(sudo + 'yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++'); + cmake = 'cmake3'; + packages += ' gperf'; + } else { + commands.push(sudo + 'dnf --enablerepo=PowerTools install gperf'); + } + packages += ' ' + cmake; + commands.push(sudo + 'yum install -y ' + packages); + break; case 'Debian 8': case 'Debian 9': case 'Debian 10': @@ -418,34 +436,6 @@ function onOptionsChanged() { commands.push('mkdir build'); commands.push('cd build'); - if (!use_msvc) { - var c_flags = []; - var cxx_flags = []; - - if (build_32bit) { - c_flags.push('-m32'); - cxx_flags.push('-m32'); - } else if (build_64bit) { - c_flags.push('-m64'); - cxx_flags.push('-m64'); - } - - if (os_linux) { - if (use_clang) { - cxx_flags.push('-stdlib=libc++'); - } else { - cxx_flags.push(''); - } - } - - if (c_flags.length) { - commands.push('export CFLAGS="' + c_flags.join(' ') + '"'); - } - if (cxx_flags.length) { - commands.push('export CXXFLAGS="' + cxx_flags.join(' ') + '"'); - } - } - cmake_init_options = getBacicCmakeInitOptions(); if (os_mac) { cmake_init_options.push('-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'); @@ -460,22 +450,24 @@ function onOptionsChanged() { if (os_linux) { if (use_clang) { var clang_version_suffix = getClangVersionSuffix(); - prefix = 'CC=/usr/bin/clang' + clang_version_suffix + ' CXX=/usr/bin/clang++' + clang_version_suffix + ' '; + prefix = 'CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang' + clang_version_suffix + ' CXX=/usr/bin/clang++' + clang_version_suffix + ' '; } else if (linux_distro === 'Ubuntu 14') { prefix = 'CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 '; + } else if (linux_distro === 'CentOS 7') { + prefix = 'CC=/opt/rh/devtoolset-9/root/usr/bin/gcc CXX=/opt/rh/devtoolset-9/root/usr/bin/g++ '; } } - return prefix + 'cmake ' + options.join(' ') + ' ..'; + return prefix + cmake + ' ' + options.join(' ') + ' ..'; } commands.push(getCmakeInitCommand(cmake_init_options)); if (os_openbsd) { - commands.push('cmake --build . --target prepare_cross_compiling'); + commands.push(cmake + ' --build . --target prepare_cross_compiling'); commands.push('cd ../td'); commands.push('php-7.2 SplitSource.php'); commands.push('cd ../build'); } - let build_command = 'cmake --build . --target install'; + let build_command = cmake + ' --build . --target install'; if (use_msvc) { if (!is_debug_build) { commands.push(build_command + ' --config Release'); diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5d62139..4685eb1 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -42,4 +42,3 @@ COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}" echo "$COMMAND" # shellcheck disable=SC2086 exec $COMMAND - diff --git a/td b/td index d71e2c5..604df72 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit d71e2c54a892b9ada7c52b463b24fdf2984fde60 +Subproject commit 604df72790eab24ebe5ae8154e2e077f0f915951 diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 490d9d9..b6e3bca 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2556,6 +2556,44 @@ class Client::TdOnCheckChatCallback : public TdQueryCallback { OnSuccess on_success_; }; +template +class Client::TdOnDisableInternetConnectionCallback : public TdQueryCallback { + public: + TdOnDisableInternetConnectionCallback(const Client *client, PromisedQueryPtr query, OnSuccess on_success) + : client_(client) + , query_(std::move(query)) + , on_success_(std::move(on_success)) { + } + + void on_result(object_ptr result) override { + on_success_(std::move(query_)); + } + + private: + const Client *client_; + PromisedQueryPtr query_; + OnSuccess on_success_; +}; + +template +class Client::TdOnOptimizeMemoryCallback : public TdQueryCallback { + public: + TdOnOptimizeMemoryCallback(const Client *client, PromisedQueryPtr query, OnSuccess on_success) + : client_(client) + , query_(std::move(query)) + , on_success_(std::move(on_success)) { + } + + void on_result(object_ptr result) override { + on_success_(std::move(query_)); + } + + private: + const Client *client_; + PromisedQueryPtr query_; + OnSuccess on_success_; +}; + template class Client::TdOnSearchStickerSetCallback : public TdQueryCallback { public: @@ -6904,10 +6942,30 @@ td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query) } td::Status Client::process_optimize_memory_query(PromisedQueryPtr &query) { - send_request(make_object(), std::make_unique(std::move(query))); + disable_internet_connection(std::move(query), [this](PromisedQueryPtr query) { + optimize_memory(std::move(query), [this](PromisedQueryPtr query) { + enable_internet_connection(std::move(query)); + }); + }); return Status::OK(); } +template +void Client::disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success) { + send_request(make_object(make_object()), + std::make_unique>(this, std::move(query), std::move(on_success))); +} + +void Client::enable_internet_connection(PromisedQueryPtr query) { + send_request(make_object(make_object()), std::make_unique(std::move(query))); +} + +template +void Client::optimize_memory(PromisedQueryPtr query, OnSuccess on_success) { + send_request(make_object(), + std::make_unique>(this, std::move(query), std::move(on_success))); +} + td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) { auto chat_id = query->arg("chat_id"); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 174efca..22716bc 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -41,8 +41,6 @@ class Client : public WebhookActor::Callback { Client(td::ActorShared<> parent, const td::string &bot_token, bool is_test_dc, td::int64 tqueue_id, std::shared_ptr parameters, td::ActorId stat_actor); - void start_up() override; - void send(PromisedQueryPtr query) override; void close(); @@ -214,6 +212,12 @@ class Client : public WebhookActor::Callback { template class TdOnCheckChatCallback; template + class TdOnEnableInternetConnectionCallback; + template + class TdOnOptimizeMemoryCallback; + template + class TdOnDisableInternetConnectionCallback; + template class TdOnCheckMessageCallback; template class TdOnCheckRemoteFileIdCallback; @@ -241,6 +245,14 @@ class Client : public WebhookActor::Callback { template void check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success); + template + void disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success); + + template + void optimize_memory(PromisedQueryPtr query, OnSuccess on_success); + + void enable_internet_connection(PromisedQueryPtr query); + template void check_remote_file_id(td::string file_id, PromisedQueryPtr query, OnSuccess on_success); @@ -386,11 +398,11 @@ class Client : public WebhookActor::Callback { static td::Result get_required_string_arg(const Query *query, Slice field_name); - static int64 get_message_id(const Query *query, Slice field_name = "message_id"); + static int64 get_message_id(const Query *query, Slice field_name = Slice("message_id")); - static td::Result get_inline_message_id(const Query *query, Slice field_name = "inline_message_id"); + static td::Result get_inline_message_id(const Query *query, Slice field_name = Slice("inline_message_id")); - static td::Result get_user_id(const Query *query, Slice field_name = "user_id"); + static td::Result get_user_id(const Query *query, Slice field_name = Slice("user_id")); int64 extract_yet_unsent_message_query_id(int64 chat_id, int64 message_id, bool *is_reply_to_message_deleted); @@ -518,6 +530,8 @@ class Client : public WebhookActor::Callback { void long_poll_wakeup(bool force_flag); + void start_up() override; + void raw_event(const td::Event::Raw &event) override; void loop() override; diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 9cd9d13..3502e21 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -192,8 +192,8 @@ int main(int argc, char *argv[]) { std::tie(rem, mod) = td::split(rem_mod, '/'); TRY_RESULT(rem_i, td::to_integer_safe(rem)); TRY_RESULT(mod_i, td::to_integer_safe(mod)); - if (rem_i < 0 || rem_i >= mod_i) { - return td::Status::Error("Wrong argument specified: ensure that 0 <= remainder < modulo"); + if (rem_i >= mod_i) { + return td::Status::Error("Wrong argument specified: ensure that remainder < modulo"); } token_range = {rem_i, mod_i}; return td::Status::OK();