mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-23 19:25:54 +01:00
Minor improvements.
This commit is contained in:
parent
93ccd2a145
commit
208fd70d58
@ -678,7 +678,7 @@ function onOptionsChanged() {
|
||||
document.getElementById('buildCommands').innerHTML = '<ul><li>' + commands.join('</li><li>') + '</li></ul>';
|
||||
document.getElementById('copyBuildCommandsButton').style.display = commands.includes('exit') ? 'none' : 'block';
|
||||
}
|
||||
|
||||
|
||||
function copyBuildInstructions() {
|
||||
var text = document.getElementById('buildCommands').innerText;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,6 +11,7 @@
|
||||
#include "telegram-bot-api/WebhookActor.h"
|
||||
|
||||
#include "td/telegram/ClientActor.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
@ -35,12 +36,12 @@ struct ClientParameters;
|
||||
|
||||
namespace td_api = td::td_api;
|
||||
|
||||
class Client : public WebhookActor::Callback {
|
||||
class Client final : public WebhookActor::Callback {
|
||||
public:
|
||||
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);
|
||||
|
||||
void send(PromisedQueryPtr query) override;
|
||||
void send(PromisedQueryPtr query) final;
|
||||
|
||||
void close();
|
||||
|
||||
@ -519,11 +520,11 @@ class Client : public WebhookActor::Callback {
|
||||
Status process_get_webhook_info_query(PromisedQueryPtr &query);
|
||||
Status process_get_file_query(PromisedQueryPtr &query);
|
||||
|
||||
void webhook_verified(td::string cached_ip_address) override;
|
||||
void webhook_success() override;
|
||||
void webhook_error(Status status) override;
|
||||
void webhook_closed(Status status) override;
|
||||
void hangup_shared() override;
|
||||
void webhook_verified(td::string cached_ip_address) final;
|
||||
void webhook_success() final;
|
||||
void webhook_error(Status status) final;
|
||||
void webhook_closed(Status status) final;
|
||||
void hangup_shared() final;
|
||||
int32 get_webhook_max_connections(const Query *query) const;
|
||||
static bool get_webhook_fix_ip_address(const Query *query);
|
||||
void do_set_webhook(PromisedQueryPtr query, bool was_deleted);
|
||||
@ -562,13 +563,13 @@ class Client : public WebhookActor::Callback {
|
||||
|
||||
void long_poll_wakeup(bool force_flag);
|
||||
|
||||
void start_up() override;
|
||||
void start_up() final;
|
||||
|
||||
void raw_event(const td::Event::Raw &event) override;
|
||||
void raw_event(const td::Event::Raw &event) final;
|
||||
|
||||
void loop() override;
|
||||
void loop() final;
|
||||
|
||||
void timeout_expired() override;
|
||||
void timeout_expired() final;
|
||||
|
||||
struct UserInfo {
|
||||
enum class Type { Regular, Deleted, Bot, Unknown };
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "telegram-bot-api/WebhookActor.h"
|
||||
|
||||
#include "td/telegram/ClientActor.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/db/binlog/Binlog.h"
|
||||
#include "td/db/binlog/ConcurrentBinlog.h"
|
||||
@ -104,7 +105,7 @@ void ClientManager::send(PromisedQueryPtr query) {
|
||||
flood_control.add_limit(60, 20); // 20 in a minute
|
||||
flood_control.add_limit(60 * 60, 600); // 600 in an hour
|
||||
}
|
||||
td::uint32 now = static_cast<td::uint32>(td::Time::now());
|
||||
auto now = static_cast<td::uint32>(td::Time::now());
|
||||
td::uint32 wakeup_at = flood_control.get_wakeup_at();
|
||||
if (wakeup_at > now) {
|
||||
LOG(INFO) << "Failed to create Client from IP address " << ip_address;
|
||||
|
@ -73,9 +73,9 @@ class ClientManager final : public td::Actor {
|
||||
static PromisedQueryPtr get_webhook_restore_query(td::Slice token, td::Slice webhook_info,
|
||||
std::shared_ptr<SharedData> shared_data);
|
||||
|
||||
void start_up() override;
|
||||
void raw_event(const td::Event::Raw &event) override;
|
||||
void hangup_shared() override;
|
||||
void start_up() final;
|
||||
void raw_event(const td::Event::Raw &event) final;
|
||||
void hangup_shared() final;
|
||||
void close_db();
|
||||
void finish_close();
|
||||
};
|
||||
|
@ -6,13 +6,13 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/db/KeyValueSyncInterface.h"
|
||||
#include "td/db/TQueue.h"
|
||||
|
||||
#include "td/net/GetHostByNameActor.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/List.h"
|
||||
#include "td/utils/port/IPAddress.h"
|
||||
|
@ -9,12 +9,12 @@
|
||||
#include "telegram-bot-api/ClientManager.h"
|
||||
#include "telegram-bot-api/Query.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/net/HttpInboundConnection.h"
|
||||
#include "td/net/HttpQuery.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
@ -24,15 +24,15 @@ namespace telegram_bot_api {
|
||||
|
||||
struct SharedData;
|
||||
|
||||
class HttpConnection : public td::HttpInboundConnection::Callback {
|
||||
class HttpConnection final : public td::HttpInboundConnection::Callback {
|
||||
public:
|
||||
explicit HttpConnection(td::ActorId<ClientManager> client_manager, std::shared_ptr<SharedData> shared_data)
|
||||
: client_manager_(client_manager), shared_data_(std::move(shared_data)) {
|
||||
}
|
||||
|
||||
void handle(td::unique_ptr<td::HttpQuery> http_query, td::ActorOwn<td::HttpInboundConnection> connection) override;
|
||||
void handle(td::unique_ptr<td::HttpQuery> http_query, td::ActorOwn<td::HttpInboundConnection> connection) final;
|
||||
|
||||
void wakeup() override;
|
||||
void wakeup() final;
|
||||
|
||||
private:
|
||||
td::FutureActor<td::unique_ptr<Query>> result_;
|
||||
@ -40,7 +40,7 @@ class HttpConnection : public td::HttpInboundConnection::Callback {
|
||||
td::ActorOwn<td::HttpInboundConnection> connection_;
|
||||
std::shared_ptr<SharedData> shared_data_;
|
||||
|
||||
void hangup() override {
|
||||
void hangup() final {
|
||||
connection_.release();
|
||||
stop();
|
||||
}
|
||||
|
@ -6,11 +6,11 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/net/HttpInboundConnection.h"
|
||||
#include "td/net/TcpListener.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/BufferedFd.h"
|
||||
#include "td/utils/FloodControlFast.h"
|
||||
#include "td/utils/format.h"
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
namespace telegram_bot_api {
|
||||
|
||||
class HttpServer : public td::TcpListener::Callback {
|
||||
class HttpServer final : public td::TcpListener::Callback {
|
||||
public:
|
||||
HttpServer(td::string ip_address, int port,
|
||||
std::function<td::ActorOwn<td::HttpInboundConnection::Callback>()> creator)
|
||||
@ -39,7 +39,7 @@ class HttpServer : public td::TcpListener::Callback {
|
||||
td::ActorOwn<td::TcpListener> listener_;
|
||||
td::FloodControlFast flood_control_;
|
||||
|
||||
void start_up() override {
|
||||
void start_up() final {
|
||||
auto now = td::Time::now();
|
||||
auto wakeup_at = flood_control_.get_wakeup_at();
|
||||
if (wakeup_at > now) {
|
||||
@ -53,13 +53,13 @@ class HttpServer : public td::TcpListener::Callback {
|
||||
actor_shared(this, 1), ip_address_);
|
||||
}
|
||||
|
||||
void hangup_shared() override {
|
||||
void hangup_shared() final {
|
||||
LOG(ERROR) << "TCP listener was closed";
|
||||
listener_.release();
|
||||
yield();
|
||||
}
|
||||
|
||||
void accept(td::SocketFd fd) override {
|
||||
void accept(td::SocketFd fd) final {
|
||||
auto scheduler_count = td::Scheduler::instance()->sched_count();
|
||||
auto scheduler_id = scheduler_count - 1;
|
||||
if (scheduler_id > 0) {
|
||||
@ -70,7 +70,7 @@ class HttpServer : public td::TcpListener::Callback {
|
||||
.release();
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
void loop() final {
|
||||
if (listener_.empty()) {
|
||||
start_up();
|
||||
}
|
||||
|
@ -8,30 +8,30 @@
|
||||
|
||||
#include "telegram-bot-api/ClientManager.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/net/HttpInboundConnection.h"
|
||||
#include "td/net/HttpQuery.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
|
||||
namespace telegram_bot_api {
|
||||
|
||||
class HttpStatConnection : public td::HttpInboundConnection::Callback {
|
||||
class HttpStatConnection final : public td::HttpInboundConnection::Callback {
|
||||
public:
|
||||
explicit HttpStatConnection(td::ActorId<ClientManager> client_manager) : client_manager_(client_manager) {
|
||||
}
|
||||
void handle(td::unique_ptr<td::HttpQuery> http_query, td::ActorOwn<td::HttpInboundConnection> connection) override;
|
||||
void handle(td::unique_ptr<td::HttpQuery> http_query, td::ActorOwn<td::HttpInboundConnection> connection) final;
|
||||
|
||||
void wakeup() override;
|
||||
void wakeup() final;
|
||||
|
||||
private:
|
||||
td::FutureActor<td::BufferSlice> result_;
|
||||
td::ActorId<ClientManager> client_manager_;
|
||||
td::ActorOwn<td::HttpInboundConnection> connection_;
|
||||
|
||||
void hangup() override {
|
||||
void hangup() final {
|
||||
connection_.release();
|
||||
stop();
|
||||
}
|
||||
|
@ -8,11 +8,11 @@
|
||||
|
||||
#include "telegram-bot-api/ClientParameters.h"
|
||||
|
||||
#include "td/net/HttpFile.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/net/HttpFile.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/JsonBuilder.h"
|
||||
@ -30,7 +30,7 @@ namespace telegram_bot_api {
|
||||
|
||||
class BotStatActor;
|
||||
|
||||
class Query : public td::ListNode {
|
||||
class Query final : public td::ListNode {
|
||||
public:
|
||||
enum class State : td::int8 { Query, OK, Error };
|
||||
|
||||
@ -166,7 +166,7 @@ td::StringBuilder &operator<<(td::StringBuilder &sb, const Query &query);
|
||||
// https://stackoverflow.com/questions/26947704/implicit-conversion-failure-from-initializer-list
|
||||
extern std::unordered_map<td::string, std::unique_ptr<td::VirtuallyJsonable>> empty_parameters;
|
||||
|
||||
class JsonParameters : public td::Jsonable {
|
||||
class JsonParameters final : public td::Jsonable {
|
||||
public:
|
||||
explicit JsonParameters(const std::unordered_map<td::string, std::unique_ptr<td::VirtuallyJsonable>> ¶meters)
|
||||
: parameters_(parameters) {
|
||||
@ -184,7 +184,7 @@ class JsonParameters : public td::Jsonable {
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class JsonQueryOk : public td::Jsonable {
|
||||
class JsonQueryOk final : public td::Jsonable {
|
||||
public:
|
||||
JsonQueryOk(const T &result, td::Slice description) : result_(result), description_(description) {
|
||||
}
|
||||
@ -202,7 +202,7 @@ class JsonQueryOk : public td::Jsonable {
|
||||
td::Slice description_;
|
||||
};
|
||||
|
||||
class JsonQueryError : public td::Jsonable {
|
||||
class JsonQueryError final : public td::Jsonable {
|
||||
public:
|
||||
JsonQueryError(
|
||||
int error_code, td::Slice description,
|
||||
|
@ -156,7 +156,7 @@ class BotStatActor final : public td::Actor {
|
||||
BotStatActor(const BotStatActor &) = delete;
|
||||
BotStatActor &operator=(const BotStatActor &other) = delete;
|
||||
BotStatActor(BotStatActor &&) = default;
|
||||
BotStatActor &operator=(BotStatActor &&other) {
|
||||
BotStatActor &operator=(BotStatActor &&other) noexcept {
|
||||
if (!empty()) {
|
||||
do_stop();
|
||||
}
|
||||
@ -165,7 +165,7 @@ class BotStatActor final : public td::Actor {
|
||||
parent_ = other.parent_;
|
||||
return *this;
|
||||
}
|
||||
~BotStatActor() override = default;
|
||||
~BotStatActor() final = default;
|
||||
|
||||
template <class EventT>
|
||||
void add_event(const EventT &event, double now) {
|
||||
|
@ -152,11 +152,11 @@ td::Status WebhookActor::create_connection() {
|
||||
}
|
||||
|
||||
VLOG(webhook) << "Create connection through proxy " << parameters_->webhook_proxy_ip_address_;
|
||||
class Callback : public td::TransparentProxy::Callback {
|
||||
class Callback final : public td::TransparentProxy::Callback {
|
||||
public:
|
||||
Callback(td::ActorId<WebhookActor> actor, td::int64 id) : actor_(actor), id_(id) {
|
||||
}
|
||||
void set_result(td::Result<td::BufferedFd<td::SocketFd>> result) override {
|
||||
void set_result(td::Result<td::BufferedFd<td::SocketFd>> result) final {
|
||||
send_closure(std::move(actor_), &WebhookActor::on_socket_ready_async, std::move(result), id_);
|
||||
CHECK(actor_.empty());
|
||||
}
|
||||
@ -169,7 +169,7 @@ td::Status WebhookActor::create_connection() {
|
||||
send_closure(std::move(actor_), &WebhookActor::on_socket_ready_async, td::Status::Error("Canceled"), id_);
|
||||
}
|
||||
}
|
||||
void on_connected() override {
|
||||
void on_connected() final {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace telegram_bot_api {
|
||||
|
||||
struct ClientParameters;
|
||||
|
||||
class WebhookActor : public td::HttpOutboundConnection::Callback {
|
||||
class WebhookActor final : public td::HttpOutboundConnection::Callback {
|
||||
public:
|
||||
class Callback : public td::Actor {
|
||||
public:
|
||||
@ -139,7 +139,7 @@ class WebhookActor : public td::HttpOutboundConnection::Callback {
|
||||
double next_ip_address_resolve_time_ = 0;
|
||||
td::FutureActor<td::IPAddress> future_ip_address_;
|
||||
|
||||
class Connection : public td::ListNode {
|
||||
class Connection final : public td::ListNode {
|
||||
public:
|
||||
Connection() = default;
|
||||
Connection(const Connection &) = delete;
|
||||
@ -190,26 +190,26 @@ class WebhookActor : public td::HttpOutboundConnection::Callback {
|
||||
td::Status send_update() TD_WARN_UNUSED_RESULT;
|
||||
void send_updates();
|
||||
|
||||
void loop() override;
|
||||
void handle(td::unique_ptr<td::HttpQuery> response) override;
|
||||
void loop() final;
|
||||
void handle(td::unique_ptr<td::HttpQuery> response) final;
|
||||
|
||||
void hangup_shared() override;
|
||||
void hangup_shared() final;
|
||||
|
||||
void hangup() override;
|
||||
void hangup() final;
|
||||
|
||||
void tear_down() override;
|
||||
void tear_down() final;
|
||||
|
||||
void start_up() override;
|
||||
void start_up() final;
|
||||
|
||||
bool check_ip_address(const td::IPAddress &addr) const;
|
||||
|
||||
void on_error(td::Status status);
|
||||
void on_connection_error(td::Status error) override;
|
||||
void on_connection_error(td::Status error) final;
|
||||
void on_webhook_error(td::Slice error);
|
||||
void on_webhook_verified();
|
||||
};
|
||||
|
||||
class JsonUpdate : public td::Jsonable {
|
||||
class JsonUpdate final : public td::Jsonable {
|
||||
public:
|
||||
JsonUpdate(td::int32 id, td::Slice update) : id_(id), update_(update) {
|
||||
}
|
||||
|
@ -310,16 +310,16 @@ int main(int argc, char *argv[]) {
|
||||
options.add_checked_option('c', "max-connections", "maximum number of open file descriptors",
|
||||
td::OptionParser::parse_integer(max_connections));
|
||||
|
||||
options.add_checked_option(
|
||||
'\0', "proxy", PSLICE() << "HTTP proxy server for outgoing webhook requests in the format http://host:port",
|
||||
[&](td::Slice address) {
|
||||
if (td::begins_with(address, "http://")) {
|
||||
address.remove_prefix(7);
|
||||
} else if (td::begins_with(address, "https://")) {
|
||||
address.remove_prefix(8);
|
||||
}
|
||||
return parameters->webhook_proxy_ip_address_.init_host_port(address.str());
|
||||
});
|
||||
options.add_checked_option('\0', "proxy",
|
||||
"HTTP proxy server for outgoing webhook requests in the format http://host:port",
|
||||
[&](td::Slice address) {
|
||||
if (td::begins_with(address, "http://")) {
|
||||
address.remove_prefix(7);
|
||||
} else if (td::begins_with(address, "https://")) {
|
||||
address.remove_prefix(8);
|
||||
}
|
||||
return parameters->webhook_proxy_ip_address_.init_host_port(address.str());
|
||||
});
|
||||
options.add_check([&] {
|
||||
if (parameters->api_id_ <= 0 || parameters->api_hash_.empty()) {
|
||||
return td::Status::Error("You must provide valid api-id and api-hash obtained at https://my.telegram.org");
|
||||
|
Loading…
Reference in New Issue
Block a user