Merge branch 'master' into master

This commit is contained in:
Marco Aceti 2020-11-09 15:08:44 +01:00 committed by GitHub
commit 684152227a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 48 deletions

View File

@ -226,4 +226,3 @@ jobs:
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64 \ --amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64 \
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le --amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le
docker manifest push ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }} docker manifest push ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}

View File

@ -48,7 +48,7 @@ if (CLANG OR GCC)
endif() endif()
endif() endif()
set(TG_HTTP_CLIENT_SOURCE set(TELEGRAM_BOT_API_SOURCE
telegram-bot-api/telegram-bot-api.cpp telegram-bot-api/telegram-bot-api.cpp
telegram-bot-api/Client.cpp telegram-bot-api/Client.cpp
@ -70,7 +70,7 @@ set(TG_HTTP_CLIENT_SOURCE
telegram-bot-api/WebhookActor.h 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) target_include_directories(telegram-bot-api PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(telegram-bot-api PRIVATE memprof tdactor tdcore tddb tdnet tdutils) target_link_libraries(telegram-bot-api PRIVATE memprof tdactor tdcore tddb tdnet tdutils)

View File

@ -32,6 +32,8 @@ select.large { font-size: large; }
<select id="linuxSelect" onchange="onOsChanged(false)" class="large"> <select id="linuxSelect" onchange="onOsChanged(false)" class="large">
<option>Choose a Linux distro:</option> <option>Choose a Linux distro:</option>
<option>Alpine</option> <option>Alpine</option>
<option>CentOS 7</option>
<option>CentOS 8</option>
<option>Debian 8</option> <option>Debian 8</option>
<option>Debian 9</option> <option>Debian 9</option>
<option>Debian 10</option> <option>Debian 10</option>
@ -58,7 +60,7 @@ select.large { font-size: large; }
<div id="buildCompilerDiv" class="hide"> <div id="buildCompilerDiv" class="hide">
<span>Choose which compiler you want to use to build the Telegram Bot API server:</span><br> <span>Choose which compiler you want to use to build the Telegram Bot API server:</span><br>
<label><input type="radio" id="buildCompilerRadioGcc" name="buildCompilerRadio" onchange="onOptionsChanged()" checked/>g++</label> <label><input type="radio" id="buildCompilerRadioGcc" name="buildCompilerRadio" onchange="onOptionsChanged()" checked/>g++</label>
<label><input type="radio" id="buildCompilerRadioClang" name="buildCompilerRadio" onchange="onOptionsChanged()"/>clang++ (recommended)</label> <label><input type="radio" id="buildCompilerRadioClang" name="buildCompilerRadio" onchange="onOptionsChanged()"/>clang (recommended)</label>
<p></p> <p></p>
</div> </div>
@ -174,7 +176,7 @@ function onOptionsChanged() {
document.getElementById('buildCommandsDiv').style.display = 'block'; document.getElementById('buildCommandsDiv').style.display = 'block';
var use_clang = os_freebsd || os_openbsd; 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'; document.getElementById('buildCompilerDiv').style.display = 'block';
use_clang = document.getElementById('buildCompilerRadioClang').checked; use_clang = document.getElementById('buildCompilerRadioClang').checked;
} else { } else {
@ -250,7 +252,7 @@ function onOptionsChanged() {
pre_text.push('Download and install <a href="https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/">gperf</a>. Add the path to gperf.exe to the PATH environment variable.'); pre_text.push('Download and install <a href="https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/">gperf</a>. Add the path to gperf.exe to the PATH environment variable.');
} }
if (os_linux && linux_distro === 'Other') { 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.'); pre_text.push('Install Git, ' + compiler + ', make, CMake >= 3.0.2, OpenSSL-dev, zlib-dev, gperf using your package manager.');
} }
if (os_freebsd) { if (os_freebsd) {
@ -309,6 +311,7 @@ function onOptionsChanged() {
var commands = []; var commands = [];
var cmake = 'cmake';
if (os_mac) { if (os_mac) {
commands.push('xcode-select --install'); commands.push('xcode-select --install');
commands.push('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/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'; var packages = 'alpine-sdk linux-headers git zlib-dev openssl-dev gperf cmake';
commands.push(sudo + 'apk add --update ' + packages); commands.push(sudo + 'apk add --update ' + packages);
break; 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 8':
case 'Debian 9': case 'Debian 9':
case 'Debian 10': case 'Debian 10':
@ -418,34 +436,6 @@ function onOptionsChanged() {
commands.push('mkdir build'); commands.push('mkdir build');
commands.push('cd 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(); cmake_init_options = getBacicCmakeInitOptions();
if (os_mac) { if (os_mac) {
cmake_init_options.push('-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'); cmake_init_options.push('-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/');
@ -460,22 +450,24 @@ function onOptionsChanged() {
if (os_linux) { if (os_linux) {
if (use_clang) { if (use_clang) {
var clang_version_suffix = getClangVersionSuffix(); 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') { } else if (linux_distro === 'Ubuntu 14') {
prefix = 'CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 '; 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)); commands.push(getCmakeInitCommand(cmake_init_options));
if (os_openbsd) { 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('cd ../td');
commands.push('php-7.2 SplitSource.php'); commands.push('php-7.2 SplitSource.php');
commands.push('cd ../build'); commands.push('cd ../build');
} }
let build_command = 'cmake --build . --target install'; let build_command = cmake + ' --build . --target install';
if (use_msvc) { if (use_msvc) {
if (!is_debug_build) { if (!is_debug_build) {
commands.push(build_command + ' --config Release'); commands.push(build_command + ' --config Release');

View File

@ -42,4 +42,3 @@ COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}"
echo "$COMMAND" echo "$COMMAND"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
exec $COMMAND exec $COMMAND

2
td

@ -1 +1 @@
Subproject commit d71e2c54a892b9ada7c52b463b24fdf2984fde60 Subproject commit 604df72790eab24ebe5ae8154e2e077f0f915951

View File

@ -2556,6 +2556,44 @@ class Client::TdOnCheckChatCallback : public TdQueryCallback {
OnSuccess on_success_; OnSuccess on_success_;
}; };
template <class OnSuccess>
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<td_api::Object> result) override {
on_success_(std::move(query_));
}
private:
const Client *client_;
PromisedQueryPtr query_;
OnSuccess on_success_;
};
template <class OnSuccess>
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<td_api::Object> result) override {
on_success_(std::move(query_));
}
private:
const Client *client_;
PromisedQueryPtr query_;
OnSuccess on_success_;
};
template <class OnSuccess> template <class OnSuccess>
class Client::TdOnSearchStickerSetCallback : public TdQueryCallback { class Client::TdOnSearchStickerSetCallback : public TdQueryCallback {
public: 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) { td::Status Client::process_optimize_memory_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::optimizeMemory>(), std::make_unique<TdOnOkQueryCallback>(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(); return Status::OK();
} }
template <class OnSuccess>
void Client::disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success) {
send_request(make_object<td_api::setNetworkType>(make_object<td_api::networkTypeNone>()),
std::make_unique<TdOnDisableInternetConnectionCallback<OnSuccess>>(this, std::move(query), std::move(on_success)));
}
void Client::enable_internet_connection(PromisedQueryPtr query) {
send_request(make_object<td_api::setNetworkType>(make_object<td_api::networkTypeOther>()), std::make_unique<TdOnOkQueryCallback>(std::move(query)));
}
template <class OnSuccess>
void Client::optimize_memory(PromisedQueryPtr query, OnSuccess on_success) {
send_request(make_object<td_api::optimizeMemory>(),
std::make_unique<TdOnOptimizeMemoryCallback<OnSuccess>>(this, std::move(query), std::move(on_success)));
}
td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) { td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) {
auto chat_id = query->arg("chat_id"); auto chat_id = query->arg("chat_id");

View File

@ -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, Client(td::ActorShared<> parent, const td::string &bot_token, bool is_test_dc, td::int64 tqueue_id,
std::shared_ptr<const ClientParameters> parameters, td::ActorId<BotStatActor> stat_actor); std::shared_ptr<const ClientParameters> parameters, td::ActorId<BotStatActor> stat_actor);
void start_up() override;
void send(PromisedQueryPtr query) override; void send(PromisedQueryPtr query) override;
void close(); void close();
@ -214,6 +212,12 @@ class Client : public WebhookActor::Callback {
template <class OnSuccess> template <class OnSuccess>
class TdOnCheckChatCallback; class TdOnCheckChatCallback;
template <class OnSuccess> template <class OnSuccess>
class TdOnEnableInternetConnectionCallback;
template <class OnSuccess>
class TdOnOptimizeMemoryCallback;
template <class OnSuccess>
class TdOnDisableInternetConnectionCallback;
template <class OnSuccess>
class TdOnCheckMessageCallback; class TdOnCheckMessageCallback;
template <class OnSuccess> template <class OnSuccess>
class TdOnCheckRemoteFileIdCallback; class TdOnCheckRemoteFileIdCallback;
@ -241,6 +245,14 @@ class Client : public WebhookActor::Callback {
template <class OnSuccess> template <class OnSuccess>
void check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success); void check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success);
template <class OnSuccess>
void disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success);
template <class OnSuccess>
void optimize_memory(PromisedQueryPtr query, OnSuccess on_success);
void enable_internet_connection(PromisedQueryPtr query);
template <class OnSuccess> template <class OnSuccess>
void check_remote_file_id(td::string file_id, PromisedQueryPtr query, OnSuccess on_success); 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<td::MutableSlice> get_required_string_arg(const Query *query, Slice field_name); static td::Result<td::MutableSlice> 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<Slice> get_inline_message_id(const Query *query, Slice field_name = "inline_message_id"); static td::Result<Slice> get_inline_message_id(const Query *query, Slice field_name = Slice("inline_message_id"));
static td::Result<int32> get_user_id(const Query *query, Slice field_name = "user_id"); static td::Result<int32> 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); 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 long_poll_wakeup(bool force_flag);
void start_up() override;
void raw_event(const td::Event::Raw &event) override; void raw_event(const td::Event::Raw &event) override;
void loop() override; void loop() override;

View File

@ -192,8 +192,8 @@ int main(int argc, char *argv[]) {
std::tie(rem, mod) = td::split(rem_mod, '/'); std::tie(rem, mod) = td::split(rem_mod, '/');
TRY_RESULT(rem_i, td::to_integer_safe<td::uint64>(rem)); TRY_RESULT(rem_i, td::to_integer_safe<td::uint64>(rem));
TRY_RESULT(mod_i, td::to_integer_safe<td::uint64>(mod)); TRY_RESULT(mod_i, td::to_integer_safe<td::uint64>(mod));
if (rem_i < 0 || rem_i >= mod_i) { if (rem_i >= mod_i) {
return td::Status::Error("Wrong argument specified: ensure that 0 <= remainder < modulo"); return td::Status::Error("Wrong argument specified: ensure that remainder < modulo");
} }
token_range = {rem_i, mod_i}; token_range = {rem_i, mod_i};
return td::Status::OK(); return td::Status::OK();