2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/ClientActor.h"
|
2018-01-24 16:45:57 +01:00
|
|
|
#include "td/telegram/Log.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/telegram/td_api_json.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/tl/tl_json.h" // should be included after td_api_json?
|
|
|
|
|
|
|
|
#include "memprof/memprof.h"
|
|
|
|
|
2018-04-07 01:38:28 +02:00
|
|
|
#include "td/net/HttpQuery.h"
|
2018-04-06 15:24:29 +02:00
|
|
|
#include "td/net/HttpReader.h"
|
|
|
|
|
2018-04-23 22:33:51 +02:00
|
|
|
#include "td/utils/base64.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
2019-02-12 22:26:36 +01:00
|
|
|
#include "td/utils/common.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/FileLog.h"
|
|
|
|
#include "td/utils/format.h"
|
|
|
|
#include "td/utils/JsonBuilder.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
|
|
|
#include "td/utils/port/FileFd.h"
|
2018-09-10 03:08:15 +02:00
|
|
|
#include "td/utils/port/PollFlags.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/port/signals.h"
|
|
|
|
#include "td/utils/port/Stat.h"
|
2018-08-17 15:41:51 +02:00
|
|
|
#include "td/utils/port/StdStreams.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/port/thread_local.h"
|
2018-02-09 18:02:01 +01:00
|
|
|
#include "td/utils/ScopeGuard.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/Time.h"
|
|
|
|
|
|
|
|
#ifndef USE_READLINE
|
|
|
|
#include "td/utils/find_boundary.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
2018-02-03 20:40:06 +01:00
|
|
|
#include <clocale>
|
2018-09-10 20:45:34 +02:00
|
|
|
#include <cstdio>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring> // for strcmp
|
|
|
|
#include <ctime>
|
2018-01-24 16:45:57 +01:00
|
|
|
#include <iostream>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <limits>
|
2018-02-09 18:02:01 +01:00
|
|
|
#include <locale>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <queue>
|
|
|
|
#include <tuple>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
/* Standard readline include files. */
|
|
|
|
#include <readline/history.h>
|
|
|
|
#include <readline/readline.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void dump_memory_usage() {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (is_memprof_on()) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(WARNING) << "Memory dump:";
|
2018-12-31 20:04:05 +01:00
|
|
|
clear_thread_locals();
|
|
|
|
std::vector<AllocInfo> v;
|
|
|
|
dump_alloc([&](const AllocInfo &info) { v.push_back(info); });
|
|
|
|
std::sort(v.begin(), v.end(), [](const AllocInfo &a, const AllocInfo &b) { return a.size > b.size; });
|
|
|
|
size_t total_size = 0;
|
|
|
|
size_t other_size = 0;
|
|
|
|
int cnt = 0;
|
|
|
|
for (auto &info : v) {
|
|
|
|
if (cnt++ < 50) {
|
|
|
|
LOG(WARNING) << td::format::as_size(info.size) << td::format::as_array(info.backtrace);
|
|
|
|
} else {
|
|
|
|
other_size += info.size;
|
|
|
|
}
|
|
|
|
total_size += info.size;
|
|
|
|
}
|
|
|
|
LOG(WARNING) << tag("other", td::format::as_size(other_size));
|
|
|
|
LOG(WARNING) << tag("total", td::format::as_size(total_size));
|
|
|
|
LOG(WARNING) << tag("total traces", get_ht_size());
|
|
|
|
LOG(WARNING) << tag("fast_backtrace_success_rate", get_fast_backtrace_success_rate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
const char *prompt = "td_cli> ";
|
|
|
|
static int32 saved_point;
|
|
|
|
static string saved_line;
|
|
|
|
static std::atomic_flag readline_lock = ATOMIC_FLAG_INIT;
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void deactivate_readline() {
|
2018-12-31 20:04:05 +01:00
|
|
|
while (readline_lock.test_and_set(std::memory_order_acquire)) {
|
|
|
|
// spin
|
|
|
|
}
|
|
|
|
|
|
|
|
saved_point = rl_point;
|
|
|
|
saved_line = string(rl_line_buffer, rl_end);
|
|
|
|
|
|
|
|
rl_set_prompt("");
|
|
|
|
rl_replace_line("", 0);
|
|
|
|
rl_redisplay();
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void reactivate_readline() {
|
2018-12-31 20:04:05 +01:00
|
|
|
rl_set_prompt(prompt);
|
|
|
|
rl_replace_line(saved_line.c_str(), 0);
|
|
|
|
rl_point = saved_point;
|
|
|
|
rl_redisplay();
|
|
|
|
|
|
|
|
readline_lock.clear(std::memory_order_release);
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static char *command_generator(const char *text, int state) {
|
2018-08-16 19:09:23 +02:00
|
|
|
static const vector<CSlice> commands{"GetChats",
|
2018-07-03 01:28:28 +02:00
|
|
|
"GetHistory",
|
|
|
|
"SetVerbosity",
|
|
|
|
"SendVideo",
|
|
|
|
"SearchDocument",
|
|
|
|
"GetChatMember",
|
|
|
|
"GetSupergroupAdministrators",
|
|
|
|
"GetSupergroupBanned",
|
|
|
|
"GetSupergroupMembers",
|
|
|
|
"GetFile",
|
|
|
|
"DownloadFile",
|
|
|
|
"CancelDownloadFile",
|
|
|
|
"ImportContacts",
|
|
|
|
"RemoveContacts",
|
|
|
|
"DumpNetQueries",
|
|
|
|
"CreateSecretChat",
|
|
|
|
"CreateNewSecretChat"};
|
2018-12-31 20:04:05 +01:00
|
|
|
static size_t cmd_i;
|
|
|
|
if (state == 0) {
|
|
|
|
cmd_i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cmd_i < commands.size()) {
|
|
|
|
const char *a = commands[cmd_i++].c_str();
|
|
|
|
const char *b = text;
|
|
|
|
const char *c = b;
|
|
|
|
while (*c && to_lower(*c) == *c) {
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
bool only_lowercase = !is_alpha(*c);
|
|
|
|
while (*a && *b) {
|
|
|
|
if (*a == *b || (only_lowercase && *a == to_upper(*b))) {
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
if (*b == 0) {
|
|
|
|
// TODO call to strdup is completely wrong. Readline will try to call std::free() on the returned char*,
|
|
|
|
// which may be incompatible with the std::malloc() called by strdup
|
|
|
|
// It is especially likely to happen if Readline is used as dynamic library
|
|
|
|
// Unfortunately Readline doesn't provide memory allocation functions/memory deallocation callbacks to fix this
|
|
|
|
#if TD_MSVC
|
|
|
|
return _strdup(commands[cmd_i - 1].c_str());
|
|
|
|
#else
|
|
|
|
return strdup(commands[cmd_i - 1].c_str());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static char **tg_cli_completion(const char *text, int start, int end) {
|
2018-12-31 20:04:05 +01:00
|
|
|
char **matches = nullptr;
|
|
|
|
if (start == 0) {
|
|
|
|
matches = rl_completion_matches(text, command_generator);
|
|
|
|
}
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class CliLog : public LogInterface {
|
|
|
|
public:
|
|
|
|
void append(CSlice slice, int log_level) override {
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
deactivate_readline();
|
2018-08-17 15:41:51 +02:00
|
|
|
SCOPE_EXIT {
|
|
|
|
reactivate_readline();
|
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
#endif
|
|
|
|
if (log_level == VERBOSITY_NAME(PLAIN)) {
|
|
|
|
#if TD_WINDOWS
|
|
|
|
TsCerr() << slice;
|
|
|
|
#else
|
|
|
|
TsCerr() << TC_GREEN << slice << TC_EMPTY;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
default_log_interface->append(slice, log_level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void rotate() override {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SendMessageInfo {
|
|
|
|
double start_time = 0;
|
|
|
|
double quick_ack_time = 0;
|
|
|
|
double ack_time = 0;
|
|
|
|
bool empty() const {
|
|
|
|
return quick_ack_time != 0 || ack_time != 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &sb, const SendMessageInfo &info) {
|
|
|
|
sb << format::cond(info.quick_ack_time != 0, tag("quick_ack", info.quick_ack_time - info.start_time));
|
|
|
|
sb << format::cond(info.ack_time != 0, tag("ack", info.ack_time - info.start_time));
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CliClient final : public Actor {
|
|
|
|
public:
|
2018-09-11 12:37:44 +02:00
|
|
|
CliClient(ConcurrentScheduler *scheduler, bool use_test_dc, bool get_chat_list, bool disable_network, int32 api_id,
|
|
|
|
string api_hash)
|
2018-09-11 09:31:05 +02:00
|
|
|
: scheduler_(scheduler)
|
|
|
|
, use_test_dc_(use_test_dc)
|
2018-12-31 20:04:05 +01:00
|
|
|
, get_chat_list_(get_chat_list)
|
|
|
|
, disable_network_(disable_network)
|
|
|
|
, api_id_(api_id)
|
|
|
|
, api_hash_(api_hash) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static void quit_instance() {
|
|
|
|
instance_->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void start_up() override {
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<uint64, SendMessageInfo> query_id_to_send_message_info_;
|
|
|
|
std::unordered_map<uint64, SendMessageInfo> message_id_to_send_message_info_;
|
|
|
|
|
|
|
|
struct User {
|
|
|
|
string first_name;
|
|
|
|
string last_name;
|
|
|
|
string username;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<int32, User> users_;
|
|
|
|
std::unordered_map<string, int32> username_to_user_id_;
|
|
|
|
|
|
|
|
void register_user(const td_api::user &user) {
|
|
|
|
User &new_user = users_[user.id_];
|
|
|
|
new_user.first_name = user.first_name_;
|
|
|
|
new_user.last_name = user.last_name_;
|
|
|
|
new_user.username = user.username_;
|
|
|
|
username_to_user_id_[to_lower(new_user.username)] = user.id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_user(Logger &log, int32 user_id, bool full = false) {
|
|
|
|
const User *user = &users_[user_id];
|
|
|
|
log << user->first_name << " " << user->last_name << " #" << user_id;
|
|
|
|
if (!user->username.empty()) {
|
|
|
|
log << " @" << user->username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_users(const td_api::users &users) {
|
2018-08-14 09:42:40 +02:00
|
|
|
Logger log{*log_interface, LogOptions::plain(), VERBOSITY_NAME(PLAIN)};
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto &user_id : users.user_ids_) {
|
|
|
|
if (user_id == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
print_user(log, user_id);
|
|
|
|
log << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
std::unordered_map<string, int32> username_to_supergroup_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
void register_supergroup(const td_api::supergroup &supergroup) {
|
|
|
|
if (!supergroup.username_.empty()) {
|
2018-06-01 01:12:36 +02:00
|
|
|
username_to_supergroup_id_[to_lower(supergroup.username_)] = supergroup.id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_option(const td_api::updateOption &option) {
|
|
|
|
if (option.name_ == "my_id") {
|
|
|
|
if (option.value_->get_id() == td_api::optionValueInteger::ID) {
|
|
|
|
my_id_ = static_cast<const td_api::optionValueInteger *>(option.value_.get())->value_;
|
|
|
|
LOG(INFO) << "Set my id to " << my_id_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
int64 get_history_chat_id_ = 0;
|
|
|
|
int64 search_chat_id_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_get_messages(const td_api::messages &messages) {
|
2018-06-01 01:12:36 +02:00
|
|
|
if (get_history_chat_id_ != 0) {
|
2018-12-31 20:04:05 +01:00
|
|
|
int64 last_message_id = 0;
|
|
|
|
for (auto &m : messages.messages_) {
|
|
|
|
// LOG(PLAIN) << to_string(m);
|
|
|
|
if (m->content_->get_id() == td_api::messageText::ID) {
|
2018-01-30 18:06:54 +01:00
|
|
|
LOG(PLAIN) << td::oneline(static_cast<const td_api::messageText *>(m->content_.get())->text_->text_) << "\n";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
last_message_id = m->id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_message_id > 0) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatHistory>(get_history_chat_id_, last_message_id, 0, 100, false));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2018-06-01 01:12:36 +02:00
|
|
|
get_history_chat_id_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-01 01:12:36 +02:00
|
|
|
if (search_chat_id_ != 0) {
|
2018-01-10 17:59:38 +01:00
|
|
|
if (!messages.messages_.empty()) {
|
|
|
|
auto last_message_id = messages.messages_.back()->id_;
|
|
|
|
LOG(ERROR) << (last_message_id >> 20);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
|
|
|
search_chat_id_, "", 0, last_message_id, 0, 100,
|
|
|
|
td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>()));
|
2018-01-10 17:59:38 +01:00
|
|
|
} else {
|
2018-06-01 01:12:36 +02:00
|
|
|
search_chat_id_ = 0;
|
2018-01-10 17:59:38 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_get_message(const td_api::message &message) {
|
|
|
|
if (message.sending_state_ != nullptr &&
|
|
|
|
message.sending_state_->get_id() == td_api::messageSendingStatePending::ID) {
|
2019-02-21 17:48:05 +01:00
|
|
|
// send_request(td_api::make_object<td_api::deleteMessages>(message.chat_id_, vector<int64>{message.id_}, true));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
void on_get_file(const td_api::file &file) {
|
2018-06-01 02:05:46 +02:00
|
|
|
if (being_downloaded_files_.count(file.id_) == 0 && file.local_->is_downloading_active_) {
|
|
|
|
being_downloaded_files_[file.id_] = Time::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (being_downloaded_files_.count(file.id_) != 0 && !file.local_->is_downloading_active_) {
|
2018-06-01 01:12:36 +02:00
|
|
|
double elapsed_time = Time::now() - being_downloaded_files_[file.id_];
|
|
|
|
being_downloaded_files_.erase(file.id_);
|
|
|
|
if (file.local_->is_downloading_completed_) {
|
2018-06-01 02:05:46 +02:00
|
|
|
LOG(ERROR) << "File " << file.id_ << " was downloaded in " << elapsed_time << " seconds";
|
2018-06-01 01:12:36 +02:00
|
|
|
} else {
|
2018-06-01 02:05:46 +02:00
|
|
|
LOG(ERROR) << "File " << file.id_ << " has failed to download in " << elapsed_time << " seconds";
|
2018-06-01 01:12:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
struct FileGeneration {
|
|
|
|
int64 id = 0;
|
|
|
|
string destination;
|
|
|
|
string source;
|
|
|
|
int32 part_size = 0;
|
|
|
|
int32 local_size = 0;
|
|
|
|
int32 size = 0;
|
2018-11-21 11:56:14 +01:00
|
|
|
bool test_local_size_decrease = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
vector<FileGeneration> pending_file_generations_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void on_file_generation_start(const td_api::updateFileGenerationStart &update) {
|
|
|
|
FileGeneration file_generation;
|
|
|
|
file_generation.id = update.generation_id_;
|
|
|
|
file_generation.destination = update.destination_path_;
|
2018-10-31 19:11:02 +01:00
|
|
|
if (update.conversion_ == "#url#" || update.conversion_ == "url") {
|
2018-12-31 20:04:05 +01:00
|
|
|
// TODO: actually download
|
|
|
|
file_generation.source = "test.jpg";
|
|
|
|
file_generation.part_size = 1000000;
|
2018-03-18 11:45:59 +01:00
|
|
|
} else if (update.conversion_ == "skip") {
|
|
|
|
return;
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
file_generation.source = update.original_path_;
|
|
|
|
file_generation.part_size = to_integer<int32>(update.conversion_);
|
2018-11-21 11:56:14 +01:00
|
|
|
file_generation.test_local_size_decrease = !update.conversion_.empty() && update.conversion_.back() == 't';
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto r_stat = stat(file_generation.source);
|
|
|
|
if (r_stat.is_ok()) {
|
|
|
|
auto size = r_stat.ok().size_;
|
|
|
|
if (size <= 0 || size > 1500000000) {
|
|
|
|
r_stat = Status::Error(400, size == 0 ? Slice("File is empty") : Slice("File is too big"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r_stat.is_ok()) {
|
|
|
|
file_generation.size = narrow_cast<int32>(r_stat.ok().size_);
|
|
|
|
if (file_generation.part_size <= 0) {
|
|
|
|
file_generation.part_size = file_generation.size;
|
|
|
|
}
|
2018-06-01 01:12:36 +02:00
|
|
|
pending_file_generations_.push_back(std::move(file_generation));
|
2018-12-31 20:04:05 +01:00
|
|
|
timeout_expired();
|
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::finishFileGeneration>(
|
2018-12-31 20:04:05 +01:00
|
|
|
update.generation_id_, td_api::make_object<td_api::error>(400, r_stat.error().message().str())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
void on_update_autorization_state(const td_api::AuthorizationState &state) {
|
|
|
|
switch (state.get_id()) {
|
|
|
|
case td_api::authorizationStateWaitTdlibParameters::ID: {
|
|
|
|
auto parameters = td_api::make_object<td_api::tdlibParameters>();
|
|
|
|
parameters->use_test_dc_ = use_test_dc_;
|
|
|
|
parameters->use_message_database_ = true;
|
|
|
|
parameters->use_secret_chats_ = true;
|
|
|
|
parameters->api_id_ = api_id_;
|
|
|
|
parameters->api_hash_ = api_hash_;
|
|
|
|
parameters->system_language_code_ = "en";
|
|
|
|
parameters->device_model_ = "Desktop";
|
|
|
|
parameters->system_version_ = "Unknown";
|
|
|
|
parameters->application_version_ = "tg_cli";
|
|
|
|
send_request(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::authorizationStateWaitEncryptionKey::ID:
|
|
|
|
send_request(td_api::make_object<td_api::checkDatabaseEncryptionKey>());
|
|
|
|
break;
|
|
|
|
case td_api::authorizationStateReady::ID:
|
|
|
|
LOG(INFO) << "Logged in";
|
|
|
|
break;
|
|
|
|
case td_api::authorizationStateClosed::ID:
|
|
|
|
LOG(WARNING) << "TD closed";
|
2018-10-28 18:30:47 +01:00
|
|
|
td_client_.reset();
|
2018-09-15 14:24:25 +02:00
|
|
|
if (!close_flag_) {
|
|
|
|
create_td("ClientActor3");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
int64 as_chat_id(Slice str) const {
|
|
|
|
str = trim(str);
|
|
|
|
if (str[0] == '@') {
|
|
|
|
auto it = username_to_user_id_.find(to_lower(str.substr(1)));
|
|
|
|
if (it != username_to_user_id_.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
2018-06-01 01:12:36 +02:00
|
|
|
auto it2 = username_to_supergroup_id_.find(to_lower(str.substr(1)));
|
|
|
|
if (it2 != username_to_supergroup_id_.end()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto supergroup_id = it2->second;
|
|
|
|
return static_cast<int64>(-1000'000'000'000ll) - supergroup_id;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "Can't resolve " << str;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (str == "me") {
|
|
|
|
return my_id_;
|
|
|
|
}
|
|
|
|
return to_integer<int64>(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int64> as_chat_ids(Slice chat_ids, char delimiter = ' ') const {
|
|
|
|
return transform(full_split(chat_ids, delimiter), [this](Slice str) { return as_chat_id(str); });
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64 as_message_id(Slice str) {
|
2018-02-07 00:31:38 +01:00
|
|
|
str = trim(str);
|
|
|
|
if (!str.empty() && str.back() == 's') {
|
2018-05-03 10:57:19 +02:00
|
|
|
return to_integer<int64>(str) << 20;
|
2018-02-07 00:31:38 +01:00
|
|
|
}
|
|
|
|
return to_integer<int64>(str);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 17:21:43 +01:00
|
|
|
static vector<int64> as_message_ids(Slice message_ids, char delimiter = ' ') {
|
|
|
|
return transform(full_split(message_ids, delimiter), as_message_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 as_user_id(Slice str) const {
|
|
|
|
str = trim(str);
|
|
|
|
if (str[0] == '@') {
|
|
|
|
auto it = username_to_user_id_.find(to_lower(str.substr(1)));
|
|
|
|
if (it != username_to_user_id_.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "Can't find user " << str;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (str == "me") {
|
|
|
|
return my_id_;
|
|
|
|
}
|
|
|
|
return to_integer<int32>(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int32> as_user_ids(Slice user_ids, char delimiter = ' ') const {
|
|
|
|
return transform(full_split(user_ids, delimiter), [this](Slice str) { return as_user_id(str); });
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static int32 as_basic_group_id(Slice str) {
|
2019-01-07 16:37:53 +01:00
|
|
|
str = trim(str);
|
|
|
|
auto result = to_integer<int32>(str);
|
|
|
|
if (result < 0) {
|
|
|
|
return -result;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static int32 as_supergroup_id(Slice str) {
|
2019-01-07 16:37:53 +01:00
|
|
|
str = trim(str);
|
|
|
|
auto result = to_integer<int64>(str);
|
|
|
|
int64 shift = static_cast<int64>(-1000000000000ll);
|
|
|
|
if (result <= shift) {
|
|
|
|
return static_cast<int32>(shift - result);
|
|
|
|
}
|
|
|
|
return static_cast<int32>(result);
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static int32 as_secret_chat_id(Slice str) {
|
2019-01-07 16:37:53 +01:00
|
|
|
str = trim(str);
|
|
|
|
auto result = to_integer<int64>(str);
|
|
|
|
int64 shift = static_cast<int64>(-2000000000000ll);
|
|
|
|
if (result <= shift + std::numeric_limits<int32>::max()) {
|
|
|
|
return static_cast<int32>(result - shift);
|
|
|
|
}
|
|
|
|
return static_cast<int32>(result);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static int32 as_file_id(string str) {
|
|
|
|
return to_integer<int32>(trim(std::move(str)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static td_api::object_ptr<td_api::InputFile> as_input_file_id(string str) {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputFileId>(as_file_id(str));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::InputFile> as_local_file(string path) {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputFileLocal>(trim(std::move(path)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-04-23 22:33:51 +02:00
|
|
|
static tl_object_ptr<td_api::InputFile> as_remote_file(string id) {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputFileRemote>(trim(std::move(id)));
|
2018-04-23 22:33:51 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static tl_object_ptr<td_api::InputFile> as_generated_file(string original_path, string conversion,
|
|
|
|
int32 expected_size = 0) {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputFileGenerated>(trim(original_path), trim(conversion), expected_size);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-04-23 22:33:51 +02:00
|
|
|
static tl_object_ptr<td_api::InputFile> as_input_file(string str) {
|
2019-02-08 15:54:23 +01:00
|
|
|
if ((str.size() >= 20 && is_base64url(str)) || begins_with(str, "http")) {
|
2018-04-23 22:33:51 +02:00
|
|
|
return as_remote_file(str);
|
|
|
|
}
|
|
|
|
auto r_id = to_integer_safe<int32>(trim(str));
|
|
|
|
if (r_id.is_ok()) {
|
|
|
|
return as_input_file_id(str);
|
|
|
|
}
|
|
|
|
if (str.find(';') < str.size()) {
|
|
|
|
auto res = split(str, ';');
|
|
|
|
return as_generated_file(res.first, res.second);
|
|
|
|
}
|
|
|
|
return as_local_file(str);
|
|
|
|
}
|
|
|
|
|
2018-06-01 00:22:27 +02:00
|
|
|
static tl_object_ptr<td_api::inputThumbnail> as_input_thumbnail(tl_object_ptr<td_api::InputFile> input_file,
|
|
|
|
int32 width = 0, int32 height = 0) {
|
|
|
|
return td_api::make_object<td_api::inputThumbnail>(std::move(input_file), width, height);
|
|
|
|
}
|
|
|
|
|
2018-05-14 21:00:38 +02:00
|
|
|
static int32 as_call_id(string str) {
|
|
|
|
return to_integer<int32>(trim(std::move(str)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32 as_proxy_id(string str) {
|
|
|
|
return to_integer<int32>(trim(std::move(str)));
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static tl_object_ptr<td_api::location> as_location(string latitude, string longitude) {
|
2019-02-18 01:27:35 +01:00
|
|
|
if (trim(latitude).empty() && trim(longitude).empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::location>(to_double(latitude), to_double(longitude));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool as_bool(string str) {
|
|
|
|
str = to_lower(str);
|
|
|
|
return str == "true" || str == "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static vector<T> to_integers(Slice ids_string, char delimiter = ' ') {
|
2018-12-04 00:25:29 +01:00
|
|
|
return transform(transform(full_split(ids_string, delimiter), trim<Slice>), to_integer<T>);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
void on_result(uint64 generation, uint64 id, tl_object_ptr<td_api::Object> result) {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(ERROR) << "Receive result [" << generation << "][id=" << id << "] " << to_string(result);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto as_json_str = json_encode<std::string>(ToJson(result));
|
2019-02-21 16:58:20 +01:00
|
|
|
// LOG(INFO) << "Receive result [" << generation << "][id=" << id << "] " << as_json_str;
|
2018-12-31 20:04:05 +01:00
|
|
|
auto copy_as_json_str = as_json_str;
|
|
|
|
auto as_json_value = json_decode(copy_as_json_str).move_as_ok();
|
|
|
|
td_api::object_ptr<td_api::Object> object;
|
|
|
|
from_json(object, as_json_value).ensure();
|
|
|
|
CHECK(object != nullptr);
|
|
|
|
auto as_json_str2 = json_encode<std::string>(ToJson(object));
|
2019-02-12 17:17:20 +01:00
|
|
|
LOG_CHECK(as_json_str == as_json_str2) << "\n" << tag("a", as_json_str) << "\n" << tag("b", as_json_str2);
|
2019-02-21 16:58:20 +01:00
|
|
|
// LOG(INFO) << "Receive result [" << generation << "][id=" << id << "] " << as_json_str;
|
2018-09-15 14:24:25 +02:00
|
|
|
|
|
|
|
if (generation != generation_) {
|
2019-01-17 21:12:31 +01:00
|
|
|
LOG(INFO) << "Drop received from previous Client " << to_string(result);
|
2018-09-15 14:24:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
int32 result_id = result == nullptr ? 0 : result->get_id();
|
|
|
|
|
|
|
|
[&] {
|
|
|
|
if (id != 0) {
|
|
|
|
auto it = query_id_to_send_message_info_.find(id);
|
|
|
|
if (it == query_id_to_send_message_info_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto info = it->second;
|
|
|
|
query_id_to_send_message_info_.erase(id);
|
|
|
|
|
|
|
|
if (result_id == td_api::message::ID) {
|
|
|
|
auto *message = static_cast<const td_api::message *>(result.get());
|
|
|
|
message_id_to_send_message_info_[message->id_] = info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
[&] {
|
|
|
|
if (result_id == td_api::updateMessageSendAcknowledged::ID) {
|
|
|
|
auto *message = static_cast<const td_api::updateMessageSendAcknowledged *>(result.get());
|
|
|
|
auto it = message_id_to_send_message_info_.find(message->message_id_);
|
|
|
|
if (it == message_id_to_send_message_info_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &info = it->second;
|
|
|
|
info.quick_ack_time = Time::now();
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
[&] {
|
|
|
|
if (result_id == td_api::updateMessageSendSucceeded::ID) {
|
|
|
|
auto *message = static_cast<const td_api::updateMessageSendSucceeded *>(result.get());
|
|
|
|
auto it = message_id_to_send_message_info_.find(message->old_message_id_);
|
|
|
|
if (it == message_id_to_send_message_info_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto info = it->second;
|
|
|
|
message_id_to_send_message_info_.erase(it);
|
|
|
|
info.ack_time = Time::now();
|
|
|
|
LOG(INFO) << info;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
switch (result_id) {
|
|
|
|
case td_api::updateUser::ID:
|
|
|
|
register_user(*static_cast<const td_api::updateUser *>(result.get())->user_);
|
|
|
|
break;
|
|
|
|
case td_api::updateSupergroup::ID:
|
|
|
|
register_supergroup(*static_cast<const td_api::updateSupergroup *>(result.get())->supergroup_);
|
|
|
|
break;
|
|
|
|
case td_api::users::ID:
|
|
|
|
update_users(*static_cast<const td_api::users *>(result.get()));
|
|
|
|
break;
|
|
|
|
case td_api::updateOption::ID:
|
|
|
|
update_option(*static_cast<const td_api::updateOption *>(result.get()));
|
|
|
|
break;
|
|
|
|
case td_api::message::ID:
|
|
|
|
on_get_message(*static_cast<const td_api::message *>(result.get()));
|
|
|
|
break;
|
|
|
|
case td_api::messages::ID:
|
|
|
|
on_get_messages(*static_cast<const td_api::messages *>(result.get()));
|
|
|
|
break;
|
|
|
|
case td_api::updateFileGenerationStart::ID:
|
|
|
|
on_file_generation_start(*static_cast<const td_api::updateFileGenerationStart *>(result.get()));
|
|
|
|
break;
|
2018-09-15 14:24:25 +02:00
|
|
|
case td_api::updateAuthorizationState::ID:
|
|
|
|
on_update_autorization_state(
|
|
|
|
*(static_cast<const td_api::updateAuthorizationState *>(result.get())->authorization_state_));
|
|
|
|
break;
|
2018-12-31 20:04:05 +01:00
|
|
|
case td_api::updateChatLastMessage::ID: {
|
|
|
|
auto message = static_cast<const td_api::updateChatLastMessage *>(result.get())->last_message_.get();
|
|
|
|
if (message != nullptr && message->content_->get_id() == td_api::messageText::ID) {
|
2018-01-30 18:06:54 +01:00
|
|
|
// auto text = static_cast<const td_api::messageText *>(message->content_.get())->text_->text_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-01 01:12:36 +02:00
|
|
|
case td_api::file::ID:
|
|
|
|
on_get_file(*static_cast<const td_api::file *>(result.get()));
|
|
|
|
break;
|
|
|
|
case td_api::updateFile::ID:
|
|
|
|
on_get_file(*static_cast<const td_api::updateFile *>(result.get())->file_);
|
|
|
|
break;
|
2018-11-20 10:09:52 +01:00
|
|
|
case td_api::updateConnectionState::ID:
|
|
|
|
LOG(WARNING) << to_string(result);
|
|
|
|
break;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
void on_error(uint64 generation, uint64 id, tl_object_ptr<td_api::error> error) {
|
2018-08-24 00:02:59 +02:00
|
|
|
if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(ERROR) << "Receive error [" << generation << "][id=" << id << "] " << to_string(error);
|
2018-08-24 00:02:59 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
void on_closed(uint64 generation) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(WARNING) << "Td with generation " << generation << " is closed";
|
2018-09-15 14:24:25 +02:00
|
|
|
closed_td_++;
|
|
|
|
if (closed_td_ == generation_) {
|
|
|
|
LOG(WARNING) << "Ready to stop";
|
|
|
|
ready_to_stop_ = true;
|
|
|
|
if (close_flag_) {
|
|
|
|
yield();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void quit() {
|
2018-01-24 20:47:59 +01:00
|
|
|
if (close_flag_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(WARNING) << "QUIT";
|
2018-01-05 15:45:17 +01:00
|
|
|
close_flag_ = true;
|
2018-12-31 20:04:05 +01:00
|
|
|
dump_memory_usage();
|
2018-10-28 18:30:47 +01:00
|
|
|
td_client_.reset();
|
2018-09-11 00:20:41 +02:00
|
|
|
Scheduler::unsubscribe(stdin_.get_poll_info().get_pollable_fd_ref());
|
2018-12-31 20:04:05 +01:00
|
|
|
is_stdin_reader_stopped_ = true;
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
|
2018-09-10 17:09:08 +02:00
|
|
|
BufferedStdin stdin_;
|
2018-12-31 20:04:05 +01:00
|
|
|
static CliClient *instance_;
|
|
|
|
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
/* Callback function called for each line when accept-line executed, EOF
|
|
|
|
* seen, or EOF character read. This sets a flag and returns; it could
|
|
|
|
* also call exit. */
|
2018-09-10 17:09:08 +02:00
|
|
|
static void static_add_cmd(char *line) {
|
2018-12-31 20:04:05 +01:00
|
|
|
/* Can use ^D (stty eof) to exit. */
|
|
|
|
if (line == nullptr) {
|
2019-02-21 16:58:20 +01:00
|
|
|
LOG(FATAL) << "Closed";
|
2018-12-31 20:04:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*line) {
|
|
|
|
add_history(line);
|
|
|
|
}
|
|
|
|
instance_->add_cmd(line);
|
|
|
|
rl_free(line);
|
|
|
|
}
|
2018-09-10 17:09:08 +02:00
|
|
|
static int static_getc(FILE *) {
|
|
|
|
return instance_->stdin_getc();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
#endif
|
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
uint64 generation_ = 0;
|
|
|
|
uint64 closed_td_ = 0;
|
|
|
|
void create_td(Slice name) {
|
|
|
|
if (ready_to_stop_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-08 20:18:06 +02:00
|
|
|
LOG(WARNING) << "Creating new TD " << name << " with generation " << generation_ + 1;
|
2018-12-31 20:04:05 +01:00
|
|
|
class TdCallbackImpl : public TdCallback {
|
|
|
|
public:
|
2018-09-15 14:24:25 +02:00
|
|
|
TdCallbackImpl(CliClient *client, uint64 generation) : client_(client), generation_(generation) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
void on_result(uint64 id, tl_object_ptr<td_api::Object> result) override {
|
2018-09-15 14:24:25 +02:00
|
|
|
client_->on_result(generation_, id, std::move(result));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
void on_error(uint64 id, tl_object_ptr<td_api::error> error) override {
|
2018-09-15 14:24:25 +02:00
|
|
|
client_->on_error(generation_, id, std::move(error));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-09-15 18:33:27 +02:00
|
|
|
TdCallbackImpl(const TdCallbackImpl &) = delete;
|
|
|
|
TdCallbackImpl &operator=(const TdCallbackImpl &) = delete;
|
|
|
|
TdCallbackImpl(TdCallbackImpl &&) = delete;
|
|
|
|
TdCallbackImpl &operator=(TdCallbackImpl &&) = delete;
|
2018-09-14 20:03:36 +02:00
|
|
|
~TdCallbackImpl() override {
|
2018-09-15 14:24:25 +02:00
|
|
|
client_->on_closed(generation_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CliClient *client_;
|
2018-09-15 14:24:25 +02:00
|
|
|
uint64 generation_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-09-15 14:24:25 +02:00
|
|
|
|
2018-10-28 18:30:47 +01:00
|
|
|
td_client_ = create_actor<ClientActor>(name, make_unique<TdCallbackImpl>(this, ++generation_));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_td() {
|
|
|
|
close_flag_ = false;
|
|
|
|
ready_to_stop_ = false;
|
2018-09-15 14:24:25 +02:00
|
|
|
generation_ = 0;
|
|
|
|
closed_td_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
create_td("ClientActor1");
|
2018-05-22 13:09:58 +02:00
|
|
|
|
2018-09-15 14:24:25 +02:00
|
|
|
bool test_init = false;
|
2018-05-22 13:09:58 +02:00
|
|
|
if (test_init) {
|
2018-09-15 14:24:25 +02:00
|
|
|
create_td("ClientActor2");
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2018-10-28 18:30:47 +01:00
|
|
|
send_closure_later(td_client_, &ClientActor::request, std::numeric_limits<uint64>::max(),
|
2018-05-22 13:09:58 +02:00
|
|
|
td_api::make_object<td_api::setAlarm>(0.001 + 1000 * (i / 2)));
|
|
|
|
}
|
2018-05-15 22:04:27 +02:00
|
|
|
|
2018-09-17 19:48:05 +02:00
|
|
|
send_request(td_api::make_object<td_api::getStorageStatistics>(10));
|
|
|
|
send_request(td_api::make_object<td_api::getStorageStatisticsFast>());
|
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
send_request(td_api::make_object<td_api::getTextEntities>(
|
|
|
|
"@telegram /test_command https://telegram.org telegram.me @gif @test"));
|
2018-05-15 22:04:27 +02:00
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
send_request(td_api::make_object<td_api::getOption>("use_pfs"));
|
|
|
|
send_request(td_api::make_object<td_api::setOption>(
|
|
|
|
"use_pfs", td_api::make_object<td_api::optionValueBoolean>(std::time(nullptr) / 86400 % 2 == 0)));
|
2019-01-17 21:12:31 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>("notification_group_count_max",
|
|
|
|
td_api::make_object<td_api::optionValueInteger>(1)));
|
2018-05-22 13:09:58 +02:00
|
|
|
send_request(td_api::make_object<td_api::setOption>("use_storage_optimizer",
|
|
|
|
td_api::make_object<td_api::optionValueBoolean>(false)));
|
2019-02-14 16:25:31 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>(
|
|
|
|
"use_pfs", td_api::make_object<td_api::optionValueBoolean>(std::time(nullptr) / 86400 % 2 == 0)));
|
2018-05-16 21:35:27 +02:00
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeWiFi>()));
|
|
|
|
send_request(td_api::make_object<td_api::getNetworkStatistics>());
|
|
|
|
send_request(td_api::make_object<td_api::getCountryCode>());
|
2019-01-17 21:12:31 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::addProxy>("1.1.1.1", 1111, true, td_api::make_object<td_api::proxyTypeSocks5>()));
|
|
|
|
send_request(td_api::make_object<td_api::addProxy>("1.1.1.1", 1112, false,
|
|
|
|
td_api::make_object<td_api::proxyTypeSocks5>()));
|
|
|
|
send_request(td_api::make_object<td_api::pingProxy>(0));
|
2018-05-16 21:35:27 +02:00
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
auto bad_parameters = td_api::make_object<td_api::tdlibParameters>();
|
|
|
|
bad_parameters->database_directory_ = "/..";
|
|
|
|
bad_parameters->api_id_ = api_id_;
|
|
|
|
bad_parameters->api_hash_ = api_hash_;
|
|
|
|
send_request(td_api::make_object<td_api::setTdlibParameters>(std::move(bad_parameters)));
|
|
|
|
}
|
2019-02-14 16:25:31 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>("disable_contact_registered_notifications",
|
|
|
|
td_api::make_object<td_api::optionValueBoolean>(true)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
instance_ = this;
|
|
|
|
|
|
|
|
init_td();
|
|
|
|
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
deactivate_readline();
|
2018-09-10 17:09:08 +02:00
|
|
|
rl_getc_function = static_getc;
|
|
|
|
rl_callback_handler_install(prompt, static_add_cmd);
|
2018-12-31 20:04:05 +01:00
|
|
|
rl_attempted_completion_function = tg_cli_completion;
|
|
|
|
reactivate_readline();
|
|
|
|
#endif
|
2018-09-11 00:20:41 +02:00
|
|
|
Scheduler::subscribe(stdin_.get_poll_info().extract_pollable_fd(this), PollFlags::Read());
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
if (get_chat_list_) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChats>(std::numeric_limits<int64>::max(), 0, 100));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (disable_network_) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeNone>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef USE_READLINE
|
|
|
|
size_t buffer_pos_ = 0;
|
|
|
|
Result<BufferSlice> process_stdin(ChainBufferReader *buffer) {
|
|
|
|
auto found = find_boundary(buffer->clone(), "\n", buffer_pos_);
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
return Status::Error("End of line not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data = buffer->cut_head(buffer_pos_).move_as_buffer_slice();
|
|
|
|
if (!data.empty() && data[data.size() - 1] == '\r') {
|
|
|
|
data.truncate(data.size() - 1);
|
|
|
|
}
|
2018-10-26 16:11:20 +02:00
|
|
|
buffer->advance(1);
|
2018-12-31 20:04:05 +01:00
|
|
|
buffer_pos_ = 0;
|
|
|
|
return std::move(data);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-19 01:31:34 +02:00
|
|
|
static tl_object_ptr<td_api::formattedText> as_formatted_text(
|
|
|
|
string text, vector<td_api::object_ptr<td_api::textEntity>> entities = {}) {
|
2019-02-08 15:54:23 +01:00
|
|
|
if (entities.empty() && !text.empty()) {
|
2019-02-21 17:48:05 +01:00
|
|
|
auto parsed_text = execute(
|
|
|
|
td_api::make_object<td_api::parseTextEntities>(text, td_api::make_object<td_api::textParseModeMarkdown>()));
|
2018-06-19 01:31:34 +02:00
|
|
|
if (parsed_text->get_id() == td_api::formattedText::ID) {
|
|
|
|
return td_api::move_object_as<td_api::formattedText>(parsed_text);
|
2018-01-30 18:06:54 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::formattedText>(text, std::move(entities));
|
2018-06-19 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::formattedText> as_caption(string caption,
|
|
|
|
vector<td_api::object_ptr<td_api::textEntity>> entities = {}) {
|
|
|
|
return as_formatted_text(caption, std::move(entities));
|
2018-01-30 18:06:54 +01:00
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static tl_object_ptr<td_api::NotificationSettingsScope> get_notification_settings_scope(Slice scope) {
|
2019-02-14 19:44:20 +01:00
|
|
|
if (scope.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-01-29 12:40:56 +01:00
|
|
|
if (scope == "channels" || scope == "ch") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::notificationSettingsScopeChannelChats>();
|
2019-01-29 12:40:56 +01:00
|
|
|
}
|
|
|
|
if (scope == "chats" || scope == "groups" || as_bool(scope.str())) {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::notificationSettingsScopeGroupChats>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::notificationSettingsScopePrivateChats>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::UserPrivacySetting> get_user_privacy_setting(MutableSlice setting) {
|
|
|
|
setting = trim(setting);
|
|
|
|
to_lower_inplace(setting);
|
|
|
|
if (setting == "invite") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::userPrivacySettingAllowChatInvites>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (setting == "status") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::userPrivacySettingShowStatus>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (setting == "call") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::userPrivacySettingAllowCalls>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-07 19:53:54 +01:00
|
|
|
if (setting == "p2p") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::userPrivacySettingAllowPeerToPeerCalls>();
|
2019-02-07 19:53:54 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::SearchMessagesFilter> get_search_messages_filter(MutableSlice filter) {
|
|
|
|
filter = trim(filter);
|
|
|
|
to_lower_inplace(filter);
|
|
|
|
if (filter == "an" || filter == "animation") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterAnimation>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "au" || filter == "audio") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterAudio>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "d" || filter == "document") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterDocument>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "p" || filter == "photo") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterPhoto>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "vi" || filter == "video") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterVideo>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "vo" || filter == "voice") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterVoiceNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-07-19 15:58:09 +02:00
|
|
|
if (filter == "pvi") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "u" || filter == "url") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterUrl>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "cp" || filter == "chatphoto") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterChatPhoto>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-07-19 15:58:09 +02:00
|
|
|
if (filter == "c" || filter == "call") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterCall>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-07-19 15:58:09 +02:00
|
|
|
if (filter == "mc" || filter == "missedcall") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterMissedCall>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "vn" || filter == "videonote") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterVideoNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "vvn" || filter == "voicevideonote") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterVoiceAndVideoNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "m" || filter == "mention") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterMention>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (filter == "um" || filter == "umention") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::searchMessagesFilterUnreadMention>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (!filter.empty()) {
|
|
|
|
LOG(ERROR) << "Unsupported message filter " << filter;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-20 02:00:17 +02:00
|
|
|
static tl_object_ptr<td_api::ChatMembersFilter> get_chat_members_filter(MutableSlice filter) {
|
|
|
|
filter = trim(filter);
|
|
|
|
to_lower_inplace(filter);
|
|
|
|
if (filter == "a" || filter == "admin" || filter == "administrators") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatMembersFilterAdministrators>();
|
2018-07-20 02:00:17 +02:00
|
|
|
}
|
|
|
|
if (filter == "b" || filter == "banned") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatMembersFilterBanned>();
|
2018-07-20 02:00:17 +02:00
|
|
|
}
|
|
|
|
if (filter == "bot" || filter == "bots") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatMembersFilterBots>();
|
2018-07-20 02:00:17 +02:00
|
|
|
}
|
|
|
|
if (filter == "m" || filter == "members") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatMembersFilterMembers>();
|
2018-07-20 02:00:17 +02:00
|
|
|
}
|
|
|
|
if (filter == "r" || filter == "rest" || filter == "restricted") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatMembersFilterRestricted>();
|
2018-07-20 02:00:17 +02:00
|
|
|
}
|
|
|
|
if (!filter.empty()) {
|
|
|
|
LOG(ERROR) << "Unsupported chat member filter " << filter;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static tl_object_ptr<td_api::TopChatCategory> get_top_chat_category(MutableSlice category) {
|
2018-12-31 20:04:05 +01:00
|
|
|
category = trim(category);
|
|
|
|
to_lower_inplace(category);
|
|
|
|
if (!category.empty() && category.back() == 's') {
|
|
|
|
category.remove_suffix(1);
|
|
|
|
}
|
|
|
|
if (category == "bot") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryBots>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (category == "group") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryGroups>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (category == "channel") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryChannels>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (category == "inline") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryInlineBots>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (category == "call") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryCalls>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::topChatCategoryUsers>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::ChatAction> get_chat_action(MutableSlice action) {
|
|
|
|
action = trim(action);
|
|
|
|
to_lower_inplace(action);
|
|
|
|
if (action == "c" || action == "cancel") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionCancel>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "rvi" || action == "record_video") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionRecordingVideo>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "uvi" || action == "upload_video") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionUploadingVideo>(50);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "rvo" || action == "record_voice") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionRecordingVoiceNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "uvo" || action == "upload_voice") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionUploadingVoiceNote>(50);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "up" || action == "upload_photo") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionUploadingPhoto>(50);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "ud" || action == "upload_document") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionUploadingDocument>(50);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "fl" || action == "find_location") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionChoosingLocation>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "cc" || action == "choose_contact") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionChoosingContact>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "spg" || action == "start_play_game") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionStartPlayingGame>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "rvn" || action == "record_video_note") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionRecordingVideoNote>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (action == "uvn" || action == "upload_video_note") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionUploadingVideoNote>(50);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::chatActionTyping>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::NetworkType> get_network_type(MutableSlice type) {
|
|
|
|
type = trim(type);
|
|
|
|
to_lower_inplace(type);
|
|
|
|
if (type == "none") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::networkTypeNone>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (type == "mobile") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::networkTypeMobile>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (type == "roaming") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::networkTypeMobileRoaming>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (type == "wifi") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::networkTypeWiFi>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (type == "other") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::networkTypeOther>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
static tl_object_ptr<td_api::PassportElementType> as_passport_element_type(Slice passport_element_type) {
|
|
|
|
if (passport_element_type == "address" || passport_element_type == "a") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeAddress>();
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "email" || passport_element_type == "e") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeEmailAddress>();
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "phone" || passport_element_type == "p") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypePhoneNumber>();
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "pd") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypePersonalDetails>();
|
2018-04-06 15:24:29 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "dl") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeDriverLicense>();
|
2018-04-23 22:33:51 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "ip") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeInternalPassport>();
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "ic") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeIdentityCard>();
|
2018-04-23 22:33:51 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "ra") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeRentalAgreement>();
|
2018-04-23 22:33:51 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "pr") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypePassportRegistration>();
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "tr") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypeTemporaryRegistration>();
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::passportElementTypePassport>();
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-04-06 15:24:29 +02:00
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
static auto as_passport_element_types(Slice types, char delimiter = ',') {
|
|
|
|
return transform(full_split(types, delimiter), [](Slice str) { return as_passport_element_type(str); });
|
2018-04-06 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
static tl_object_ptr<td_api::InputPassportElement> as_input_passport_element(string passport_element_type, string arg,
|
|
|
|
bool with_selfie) {
|
2018-04-23 22:33:51 +02:00
|
|
|
vector<td_api::object_ptr<td_api::InputFile>> input_files;
|
|
|
|
td_api::object_ptr<td_api::InputFile> selfie;
|
2018-04-11 16:21:24 +02:00
|
|
|
if (!arg.empty()) {
|
2018-04-23 22:33:51 +02:00
|
|
|
auto files = full_split(arg);
|
|
|
|
CHECK(!files.empty());
|
|
|
|
if (with_selfie) {
|
|
|
|
selfie = as_input_file(files.back());
|
|
|
|
files.pop_back();
|
|
|
|
}
|
|
|
|
for (auto file : files) {
|
|
|
|
input_files.push_back(as_input_file(file));
|
|
|
|
}
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
if (passport_element_type == "address" || passport_element_type == "a") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementAddress>(
|
|
|
|
td_api::make_object<td_api::address>("US", "CA", "Los Angeles", "Washington", "", "90001"));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "email" || passport_element_type == "e") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementEmailAddress>(arg);
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "phone" || passport_element_type == "p") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementPhoneNumber>(arg);
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "pd") {
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementPersonalDetails>(
|
|
|
|
td_api::make_object<td_api::personalDetails>("Mike", "Jr", "Towers", u8"Mike\u2708", u8"Jr\u26fd",
|
|
|
|
u8"Towers\u2757", td_api::make_object<td_api::date>(29, 2, 2000),
|
|
|
|
"male", "US", "GB"));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "driver_license" || passport_element_type == "dl") {
|
2018-08-10 18:39:48 +02:00
|
|
|
if (input_files.size() >= 2) {
|
|
|
|
auto front_side = std::move(input_files[0]);
|
|
|
|
input_files.erase(input_files.begin());
|
|
|
|
auto reverse_side = std::move(input_files[0]);
|
|
|
|
input_files.erase(input_files.begin());
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementDriverLicense>(
|
|
|
|
td_api::make_object<td_api::inputIdentityDocument>(
|
|
|
|
"1234567890", td_api::make_object<td_api::date>(1, 3, 2029), std::move(front_side),
|
|
|
|
std::move(reverse_side), std::move(selfie), std::move(input_files)));
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "identity_card" || passport_element_type == "ic") {
|
2018-08-10 18:39:48 +02:00
|
|
|
if (input_files.size() >= 2) {
|
|
|
|
auto front_side = std::move(input_files[0]);
|
|
|
|
input_files.erase(input_files.begin());
|
|
|
|
auto reverse_side = std::move(input_files[0]);
|
|
|
|
input_files.erase(input_files.begin());
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementIdentityCard>(
|
|
|
|
td_api::make_object<td_api::inputIdentityDocument>("1234567890", nullptr, std::move(front_side),
|
|
|
|
std::move(reverse_side), std::move(selfie),
|
|
|
|
std::move(input_files)));
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (passport_element_type == "internal_passport" || passport_element_type == "ip") {
|
2018-08-10 18:39:48 +02:00
|
|
|
if (input_files.size() >= 1) {
|
|
|
|
auto front_side = std::move(input_files[0]);
|
|
|
|
input_files.erase(input_files.begin());
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementInternalPassport>(
|
|
|
|
td_api::make_object<td_api::inputIdentityDocument>("1234567890", nullptr, std::move(front_side), nullptr,
|
|
|
|
std::move(selfie), std::move(input_files)));
|
2018-04-27 14:38:02 +02:00
|
|
|
}
|
2018-08-14 15:17:47 +02:00
|
|
|
} else if (passport_element_type == "rental_agreement" || passport_element_type == "ra") {
|
|
|
|
vector<td_api::object_ptr<td_api::InputFile>> translation;
|
|
|
|
if (selfie != nullptr) {
|
|
|
|
translation.push_back(std::move(selfie));
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
return td_api::make_object<td_api::inputPassportElementRentalAgreement>(
|
|
|
|
td_api::make_object<td_api::inputPersonalDocument>(std::move(input_files), std::move(translation)));
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
2018-04-11 16:21:24 +02:00
|
|
|
|
2018-08-01 15:52:07 +02:00
|
|
|
LOG(ERROR) << "Unsupported passport element type " << passport_element_type;
|
2018-04-11 16:21:24 +02:00
|
|
|
return nullptr;
|
2018-03-27 15:11:15 +02:00
|
|
|
}
|
|
|
|
|
2019-02-11 18:57:35 +01:00
|
|
|
static td_api::object_ptr<td_api::languagePackInfo> as_language_pack_info(const string &language_code,
|
|
|
|
const string &name,
|
|
|
|
const string &native_name) {
|
|
|
|
return td_api::make_object<td_api::languagePackInfo>(language_code, "test", name, native_name, "en", true, true,
|
2019-02-23 16:29:04 +01:00
|
|
|
true, true, -1, 5, 3, "abacaba");
|
2019-02-11 18:57:35 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 18:06:54 +01:00
|
|
|
static td_api::object_ptr<td_api::Object> execute(tl_object_ptr<td_api::Function> f) {
|
2018-10-24 17:42:40 +02:00
|
|
|
if (GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) {
|
|
|
|
LOG(ERROR) << "Execute request: " << to_string(f);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
auto res = ClientActor::execute(std::move(f));
|
2018-10-24 17:42:40 +02:00
|
|
|
if (GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) {
|
|
|
|
LOG(ERROR) << "Execute response: " << to_string(res);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 send_request(tl_object_ptr<td_api::Function> f) {
|
|
|
|
static uint64 query_num = 1;
|
2018-10-28 18:30:47 +01:00
|
|
|
if (!td_client_.empty()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto id = query_num++;
|
2018-10-28 18:30:47 +01:00
|
|
|
send_closure_later(td_client_, &ClientActor::request, id, std::move(f));
|
2018-12-31 20:04:05 +01:00
|
|
|
return id;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Failed to send: " << to_string(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_message(const string &chat_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
2018-01-30 18:06:54 +01:00
|
|
|
bool disable_notification = false, bool from_background = false, int64 reply_to_message_id = 0) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto chat = as_chat_id(chat_id);
|
2019-02-21 17:48:05 +01:00
|
|
|
auto id = send_request(td_api::make_object<td_api::sendMessage>(
|
2018-01-30 18:06:54 +01:00
|
|
|
chat, reply_to_message_id, disable_notification, from_background, nullptr, std::move(input_message_content)));
|
2018-12-31 20:04:05 +01:00
|
|
|
query_id_to_send_message_info_[id].start_time = Time::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_cmd(string cmd) {
|
|
|
|
// TODO: need to remove https://en.wikipedia.org/wiki/ANSI_escape_code from cmd
|
2019-02-12 02:35:30 +01:00
|
|
|
cmd.erase(std::remove_if(cmd.begin(), cmd.end(), [](unsigned char c) { return c < 32; }), cmd.end());
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(INFO) << "CMD:[" << cmd << "]";
|
|
|
|
|
|
|
|
string op;
|
|
|
|
string args;
|
|
|
|
std::tie(op, args) = split(cmd);
|
|
|
|
|
|
|
|
const int32 OP_BLOCK_COUNT = 5;
|
|
|
|
int32 op_not_found_count = 0;
|
|
|
|
|
|
|
|
if (op == "gas") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getAuthorizationState>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sap") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setAuthenticationPhoneNumber>(args, false, false));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rac") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendAuthenticationCode>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cdek" || op == "CheckDatabaseEncryptionKey") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkDatabaseEncryptionKey>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sdek" || op == "SetDatabaseEncryptionKey") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setDatabaseEncryptionKey>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cac") {
|
|
|
|
string code;
|
|
|
|
string first_name;
|
|
|
|
string last_name;
|
|
|
|
|
|
|
|
std::tie(code, args) = split(args);
|
|
|
|
std::tie(first_name, last_name) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkAuthenticationCode>(code, first_name, last_name));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cap") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkAuthenticationPassword>(args));
|
2018-07-19 00:33:04 +02:00
|
|
|
} else if (op == "cab" || op == "cabt") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkAuthenticationBotToken>(args));
|
2018-09-20 18:33:41 +02:00
|
|
|
} else if (op == "gcs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getCurrentState>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rapr") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::requestAuthenticationPasswordRecovery>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rap") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::recoverAuthenticationPassword>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "lo" || op == "LogOut" || op == "logout") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::logOut>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ra" || op == "destroy") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::destroy>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "reset") {
|
2018-11-06 22:09:05 +01:00
|
|
|
td_client_.reset();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "close_td") {
|
2019-02-21 17:48:05 +01:00
|
|
|
// send_request(td_api::make_object<td_api::getCurrentState>());
|
|
|
|
send_request(td_api::make_object<td_api::close>());
|
|
|
|
// send_request(td_api::make_object<td_api::getCurrentState>());
|
|
|
|
// send_request(td_api::make_object<td_api::close>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "DeleteAccountYesIReallyWantToDeleteMyAccount") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteAccount>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gps" || op == "GetPasswordState") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPasswordState>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spass" || op == "SetPassword") {
|
|
|
|
string password;
|
|
|
|
string new_password;
|
|
|
|
string new_hint;
|
|
|
|
string recovery_email_address;
|
|
|
|
std::tie(password, args) = split(args);
|
|
|
|
if (password == "#") {
|
|
|
|
password = "";
|
|
|
|
}
|
|
|
|
std::tie(new_password, args) = split(args);
|
|
|
|
if (new_password == "#") {
|
|
|
|
new_password = "";
|
|
|
|
}
|
|
|
|
std::tie(new_hint, args) = split(args);
|
|
|
|
if (new_hint == "#") {
|
|
|
|
new_hint = "";
|
|
|
|
}
|
|
|
|
recovery_email_address = args;
|
|
|
|
if (recovery_email_address == "#") {
|
|
|
|
recovery_email_address = "";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::setPassword>(password, new_password, new_hint, true, recovery_email_address));
|
2018-04-28 00:54:45 +02:00
|
|
|
} else if (op == "gpafhttp") {
|
2018-04-06 15:24:29 +02:00
|
|
|
ChainBufferWriter writer;
|
|
|
|
writer.append(PSLICE() << "GET " << args << " HTTP/1.1\r\n\r\n\r\n");
|
|
|
|
ChainBufferReader reader = writer.extract_reader();
|
|
|
|
HttpReader http_reader;
|
|
|
|
http_reader.init(&reader);
|
|
|
|
HttpQuery query;
|
|
|
|
auto status = http_reader.read_next(&query);
|
|
|
|
if (status.is_error()) {
|
|
|
|
LOG(ERROR) << status.error();
|
|
|
|
return;
|
|
|
|
}
|
2018-04-19 14:23:54 +02:00
|
|
|
string bot_id = query.get_arg("bot_id").str();
|
|
|
|
string scope = query.get_arg("scope").str();
|
|
|
|
string public_key = query.get_arg("public_key").str();
|
|
|
|
string payload = query.get_arg("payload").str();
|
2018-04-23 17:05:02 +02:00
|
|
|
LOG(INFO) << "Callback URL:" << query.get_arg("callback_url");
|
2018-09-25 04:12:41 +02:00
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::getPassportAuthorizationForm>(as_user_id(bot_id), scope, public_key, payload));
|
2018-04-28 00:54:45 +02:00
|
|
|
} else if (op == "gpaf") {
|
|
|
|
string bot_id;
|
|
|
|
string scope;
|
|
|
|
string public_key =
|
|
|
|
"-----BEGIN PUBLIC KEY-----\n"
|
|
|
|
"MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzmgKr0fPP4rB/TsNEweC\n"
|
|
|
|
"hoG3ntUxuBTmHsFBW6CpABGdaTmKZSjAI/cTofhBgtRQIOdX0YRGHHHhwyLf49Wv\n"
|
|
|
|
"9l+XexbJOa0lTsJSNMj8Y/9sZbqUl5ur8ZOTM0sxbXC0XKexu1tM9YavH+Lbrobk\n"
|
|
|
|
"jt0+cmo/zEYZWNtLVihnR2IDv+7tSgiDoFWi/koAUdfJ1VMw+hReUaLg3vE9CmPK\n"
|
|
|
|
"tQiTy+NvmrYaBPb75I0Jz3Lrz1+mZSjLKO25iT84RIsxarBDd8iYh2avWkCmvtiR\n"
|
|
|
|
"Lcif8wLxi2QWC1rZoCA3Ip+Hg9J9vxHlzl6xT01WjUStMhfwrUW6QBpur7FJ+aKM\n"
|
|
|
|
"oaMoHieFNCG4qIkWVEHHSsUpLum4SYuEnyNH3tkjbrdldZanCvanGq+TZyX0buRt\n"
|
|
|
|
"4zk7FGcu8iulUkAP/o/WZM0HKinFN/vuzNVA8iqcO/BBhewhzpqmmTMnWmAO8WPP\n"
|
|
|
|
"DJMABRtXJnVuPh1CI5pValzomLJM4/YvnJGppzI1QiHHNA9JtxVmj2xf8jaXa1LJ\n"
|
|
|
|
"WUNJK+RvUWkRUxpWiKQQO9FAyTPLRtDQGN9eUeDR1U0jqRk/gNT8smHGN6I4H+NR\n"
|
|
|
|
"3X3/1lMfcm1dvk654ql8mxjCA54IpTPr/icUMc7cSzyIiQ7Tp9PZTl1gHh281ZWf\n"
|
|
|
|
"P7d2+fuJMlkjtM7oAwf+tI8CAwEAAQ==\n"
|
|
|
|
"-----END PUBLIC KEY-----";
|
|
|
|
string payload;
|
|
|
|
|
|
|
|
std::tie(bot_id, args) = split(args);
|
|
|
|
std::tie(scope, payload) = split(args);
|
2018-09-25 04:12:41 +02:00
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::getPassportAuthorizationForm>(as_user_id(bot_id), scope, public_key, payload));
|
2018-09-25 04:12:41 +02:00
|
|
|
} else if (op == "gpafae") {
|
2019-01-07 16:37:53 +01:00
|
|
|
string form_id;
|
2018-09-25 04:12:41 +02:00
|
|
|
string password;
|
2019-01-07 16:37:53 +01:00
|
|
|
std::tie(form_id, password) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPassportAuthorizationFormAvailableElements>(
|
|
|
|
to_integer<int32>(form_id), password));
|
2018-04-06 15:24:29 +02:00
|
|
|
} else if (op == "spaf") {
|
2019-01-07 16:37:53 +01:00
|
|
|
string form_id;
|
2018-04-06 21:37:30 +02:00
|
|
|
string types;
|
2019-01-07 16:37:53 +01:00
|
|
|
std::tie(form_id, types) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendPassportAuthorizationForm>(to_integer<int32>(form_id),
|
|
|
|
as_passport_element_types(types)));
|
2018-08-24 00:02:59 +02:00
|
|
|
} else if (op == "gpcl") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPreferredCountryLanguage>(args));
|
2018-04-09 16:20:12 +02:00
|
|
|
} else if (op == "spnvc" || op == "SendPhoneNumberVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
|
2018-04-09 16:20:12 +02:00
|
|
|
} else if (op == "cpnvc" || op == "CheckPhoneNumberVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkPhoneNumberVerificationCode>(args));
|
2018-04-09 18:04:21 +02:00
|
|
|
} else if (op == "rpnvc" || op == "ResendPhoneNumberVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendPhoneNumberVerificationCode>());
|
2018-04-09 18:04:21 +02:00
|
|
|
} else if (op == "seavc" || op == "SendEmailAddressVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendEmailAddressVerificationCode>(args));
|
2018-04-09 18:04:21 +02:00
|
|
|
} else if (op == "ceavc" || op == "CheckEmailAddressVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkEmailAddressVerificationCode>(args));
|
2018-04-09 18:04:21 +02:00
|
|
|
} else if (op == "reavc" || op == "ResendEmailAddressVerificationCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendEmailAddressVerificationCode>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "srea" || op == "SetRecoveryEmailAddress") {
|
|
|
|
string password;
|
|
|
|
string recovery_email_address;
|
|
|
|
std::tie(password, recovery_email_address) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setRecoveryEmailAddress>(password, recovery_email_address));
|
2019-02-10 21:16:52 +01:00
|
|
|
} else if (op == "grea" || op == "GetRecoveryEmailAddress") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRecoveryEmailAddress>(args));
|
2019-02-10 21:16:52 +01:00
|
|
|
} else if (op == "creac") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkRecoveryEmailAddressCode>(args));
|
2019-02-10 21:32:49 +01:00
|
|
|
} else if (op == "rreac") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendRecoveryEmailAddressCode>());
|
2018-06-27 20:26:52 +02:00
|
|
|
} else if (op == "spncc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendPhoneNumberVerificationCode>(args, false, false));
|
2018-06-27 20:26:52 +02:00
|
|
|
} else if (op == "cpncc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkPhoneNumberVerificationCode>(args));
|
2018-06-27 20:26:52 +02:00
|
|
|
} else if (op == "rpncc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendPhoneNumberVerificationCode>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rpr" || op == "RequestPasswordRecovery") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::requestPasswordRecovery>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rp" || op == "RecoverPassword") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::recoverPassword>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gtp" || op == "GetTemporaryPassword") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getTemporaryPasswordState>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ctp" || op == "CreateTemporaryPassword") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createTemporaryPassword>(args, 60 * 6));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (op == "gpe") {
|
2018-03-27 15:11:15 +02:00
|
|
|
string password;
|
2018-08-01 15:52:07 +02:00
|
|
|
string passport_element_type;
|
|
|
|
std::tie(password, passport_element_type) = split(args);
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::getPassportElement>(as_passport_element_type(passport_element_type), password));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (op == "gape") {
|
2018-04-07 00:29:36 +02:00
|
|
|
string password = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getAllPassportElements>(password));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (op == "spe" || op == "spes") {
|
2018-03-27 15:11:15 +02:00
|
|
|
string password;
|
2018-08-01 15:52:07 +02:00
|
|
|
string passport_element_type;
|
2018-04-11 16:21:24 +02:00
|
|
|
string arg;
|
2018-04-03 19:49:07 +02:00
|
|
|
std::tie(password, args) = split(args);
|
2018-08-01 15:52:07 +02:00
|
|
|
std::tie(passport_element_type, arg) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setPassportElement>(
|
2018-08-04 08:55:49 +02:00
|
|
|
as_input_passport_element(passport_element_type, arg, op == "spes"), password));
|
2018-08-01 15:52:07 +02:00
|
|
|
} else if (op == "dpe") {
|
|
|
|
string passport_element_type = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deletePassportElement>(as_passport_element_type(passport_element_type)));
|
2018-12-24 01:12:59 +01:00
|
|
|
} else if (op == "ppn") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::processPushNotification>(args));
|
2018-12-28 23:48:32 +01:00
|
|
|
} else if (op == "gpri") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPushReceiverId>(args));
|
2018-01-10 13:11:35 +01:00
|
|
|
} else if (op == "rda") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(
|
|
|
|
td_api::make_object<td_api::deviceTokenApplePush>(args, true), as_user_ids("")));
|
2018-01-10 13:11:35 +01:00
|
|
|
} else if (op == "rdb") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(
|
|
|
|
td_api::make_object<td_api::deviceTokenBlackBerryPush>(args), as_user_ids("")));
|
2018-12-24 16:33:39 +01:00
|
|
|
} else if (op == "rdg") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(
|
|
|
|
td_api::make_object<td_api::deviceTokenGoogleCloudMessaging>(args, true), as_user_ids("")));
|
2018-01-19 16:04:16 +01:00
|
|
|
} else if (op == "rdt") {
|
|
|
|
string token;
|
|
|
|
string other_user_ids_str;
|
|
|
|
|
|
|
|
std::tie(token, other_user_ids_str) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(td_api::make_object<td_api::deviceTokenTizenPush>(token),
|
|
|
|
as_user_ids(other_user_ids_str)));
|
2018-01-10 13:11:35 +01:00
|
|
|
} else if (op == "rdu") {
|
2018-01-10 01:18:03 +01:00
|
|
|
string token;
|
|
|
|
string other_user_ids_str;
|
|
|
|
|
|
|
|
std::tie(token, other_user_ids_str) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(
|
|
|
|
td_api::make_object<td_api::deviceTokenUbuntuPush>(token), as_user_ids(other_user_ids_str)));
|
2018-01-19 16:04:16 +01:00
|
|
|
} else if (op == "rdw") {
|
|
|
|
string endpoint;
|
|
|
|
string key;
|
|
|
|
string secret;
|
|
|
|
string other_user_ids_str;
|
|
|
|
|
|
|
|
std::tie(endpoint, args) = split(args);
|
|
|
|
std::tie(key, args) = split(args);
|
|
|
|
std::tie(secret, other_user_ids_str) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::registerDevice>(
|
|
|
|
td_api::make_object<td_api::deviceTokenWebPush>(endpoint, key, secret), as_user_ids(other_user_ids_str)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gpf") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPaymentForm>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "voi") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string allow_save;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, allow_save) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::validateOrderInfo>(as_chat_id(chat_id), as_message_id(message_id),
|
|
|
|
nullptr, as_bool(allow_save)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spfs") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string order_info_id;
|
|
|
|
string shipping_option_id;
|
|
|
|
string saved_credentials_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, args) = split(args);
|
|
|
|
std::tie(order_info_id, args) = split(args);
|
|
|
|
std::tie(shipping_option_id, saved_credentials_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendPaymentForm>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), order_info_id, shipping_option_id,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputCredentialsSaved>(saved_credentials_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spfn") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string order_info_id;
|
|
|
|
string shipping_option_id;
|
|
|
|
string data;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, args) = split(args);
|
|
|
|
std::tie(order_info_id, args) = split(args);
|
|
|
|
std::tie(shipping_option_id, data) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendPaymentForm>(
|
|
|
|
as_chat_id(chat_id), as_message_id(message_id), order_info_id, shipping_option_id,
|
|
|
|
td_api::make_object<td_api::inputCredentialsNew>(data, true)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gpre") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPaymentReceipt>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gsoi") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSavedOrderInfo>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dsoi") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteSavedOrderInfo>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dsc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteSavedCredentials>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gpr") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getUserPrivacySettingRules>(get_user_privacy_setting(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spr") {
|
|
|
|
string setting;
|
|
|
|
string allow;
|
|
|
|
std::tie(setting, allow) = split(args);
|
|
|
|
|
|
|
|
std::vector<tl_object_ptr<td_api::UserPrivacySettingRule>> rules;
|
|
|
|
if (as_bool(allow)) {
|
2019-02-21 17:48:05 +01:00
|
|
|
rules.push_back(td_api::make_object<td_api::userPrivacySettingRuleAllowAll>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
rules.push_back(td_api::make_object<td_api::userPrivacySettingRuleRestrictAll>());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setUserPrivacySettingRules>(
|
|
|
|
get_user_privacy_setting(setting), td_api::make_object<td_api::userPrivacySettingRules>(std::move(rules))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cp" || op == "ChangePhone") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::changePhoneNumber>(args, false, false));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ccpc" || op == "CheckChangePhoneCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkChangePhoneNumberCode>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rcpc" || op == "ResendChangePhoneCode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resendChangePhoneNumberCode>());
|
2018-08-16 19:09:23 +02:00
|
|
|
} else if (op == "gco") {
|
|
|
|
if (args.empty()) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getContacts>());
|
2018-08-16 19:09:23 +02:00
|
|
|
} else {
|
2019-01-07 16:37:53 +01:00
|
|
|
auto limit = to_integer<int32>(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchContacts>("", limit));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-06-25 23:10:53 +02:00
|
|
|
} else if (op == "ImportContacts" || op == "cic") {
|
2018-12-31 20:04:05 +01:00
|
|
|
vector<string> contacts_str = full_split(args, ';');
|
|
|
|
vector<tl_object_ptr<td_api::contact>> contacts;
|
|
|
|
for (auto c : contacts_str) {
|
|
|
|
string phone_number;
|
|
|
|
string first_name;
|
|
|
|
string last_name;
|
|
|
|
std::tie(phone_number, c) = split(c, ',');
|
|
|
|
std::tie(first_name, last_name) = split(c, ',');
|
2019-02-21 17:48:05 +01:00
|
|
|
contacts.push_back(td_api::make_object<td_api::contact>(phone_number, first_name, last_name, string(), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-06-25 23:10:53 +02:00
|
|
|
if (op == "cic") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::changeImportedContacts>(std::move(contacts)));
|
2018-06-25 23:10:53 +02:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::importContacts>(std::move(contacts)));
|
2018-06-25 23:10:53 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "RemoveContacts") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeContacts>(as_user_ids(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gicc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getImportedContactCount>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ClearImportedContacts") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::clearImportedContacts>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
op_not_found_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op == "gc" || op == "GetChats") {
|
|
|
|
string offset_order_string;
|
|
|
|
string offset_chat_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
std::tie(offset_order_string, offset_chat_id) = split(args);
|
|
|
|
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10000";
|
|
|
|
}
|
|
|
|
int64 offset_order;
|
|
|
|
if (offset_order_string.empty()) {
|
|
|
|
offset_order = std::numeric_limits<int64>::max();
|
|
|
|
} else {
|
|
|
|
offset_order = to_integer<int64>(offset_order_string);
|
|
|
|
}
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::getChats>(offset_order, as_chat_id(offset_chat_id), to_integer<int32>(limit)));
|
2018-12-15 17:27:06 +01:00
|
|
|
} else if (op == "gctest") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChats>(std::numeric_limits<int64>::max(), 0, 1));
|
|
|
|
send_request(td_api::make_object<td_api::getChats>(std::numeric_limits<int64>::max(), 0, 10));
|
|
|
|
send_request(td_api::make_object<td_api::getChats>(std::numeric_limits<int64>::max(), 0, 5));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcc" || op == "GetCommonChats") {
|
|
|
|
string user_id;
|
|
|
|
string offset_chat_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(user_id, args) = split(args);
|
|
|
|
std::tie(offset_chat_id, limit) = split(args);
|
|
|
|
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "100";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getGroupsInCommon>(as_user_id(user_id), as_chat_id(offset_chat_id),
|
|
|
|
to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gh" || op == "GetHistory" || op == "ghl") {
|
|
|
|
string chat_id;
|
|
|
|
string from_message_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(from_message_id, args) = split(args);
|
|
|
|
if (from_message_id.empty()) {
|
|
|
|
from_message_id = "0";
|
|
|
|
}
|
|
|
|
std::tie(offset, args) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
if (!args.empty()) {
|
|
|
|
LOG(ERROR) << "Wrong parameters to function getChatHistory specified";
|
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatHistory>(as_chat_id(chat_id), as_message_id(from_message_id),
|
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit),
|
|
|
|
op == "ghl"));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
} else if (op == "ghf") {
|
2018-06-01 01:12:36 +02:00
|
|
|
get_history_chat_id_ = as_chat_id(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatHistory>(get_history_chat_id_, std::numeric_limits<int64>::max(),
|
|
|
|
0, 100, false));
|
2018-01-10 17:59:38 +01:00
|
|
|
} else if (op == "spvf") {
|
2018-06-01 01:12:36 +02:00
|
|
|
search_chat_id_ = as_chat_id(args);
|
2018-01-10 17:59:38 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
|
|
|
search_chat_id_, "", 0, 0, 0, 100, td_api::make_object<td_api::searchMessagesFilterPhotoAndVideo>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "Search") {
|
|
|
|
string from_date;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(query, args) = split(args);
|
|
|
|
std::tie(limit, from_date) = split(args);
|
|
|
|
if (from_date.empty()) {
|
|
|
|
from_date = "0";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchMessages>(query, to_integer<int32>(from_date), 2147482647, 0,
|
|
|
|
to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SCM") {
|
|
|
|
string chat_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(limit, query) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), query, 0, 0, 0,
|
|
|
|
to_integer<int32>(limit), nullptr));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SMME") {
|
|
|
|
string chat_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(chat_id, limit) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(as_chat_id(chat_id), "", my_id_, 0, 0,
|
|
|
|
to_integer<int32>(limit), nullptr));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SM") {
|
|
|
|
string chat_id;
|
|
|
|
string offset_message_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
string filter;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(filter, args) = split(args);
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
std::tie(offset_message_id, offset) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "0";
|
|
|
|
}
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), "", 0, as_message_id(offset_message_id), to_integer<int32>(offset),
|
|
|
|
to_integer<int32>(limit), get_search_messages_filter(filter)));
|
|
|
|
} else if (op == "SC") {
|
|
|
|
string limit;
|
|
|
|
string offset_message_id;
|
|
|
|
string only_missed;
|
|
|
|
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
std::tie(offset_message_id, only_missed) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "0";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchCallMessages>(as_message_id(offset_message_id),
|
|
|
|
to_integer<int32>(limit), as_bool(only_missed)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SCRLM") {
|
|
|
|
string chat_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(chat_id, limit) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::searchChatRecentLocationMessages>(as_chat_id(chat_id), to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SearchAudio") {
|
|
|
|
string chat_id;
|
|
|
|
string offset_message_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(offset_message_id, args) = split(args);
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "0";
|
|
|
|
}
|
|
|
|
std::tie(limit, query) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::searchMessagesFilterAudio>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SearchDocument") {
|
|
|
|
string chat_id;
|
|
|
|
string offset_message_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(offset_message_id, args) = split(args);
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "0";
|
|
|
|
}
|
|
|
|
std::tie(limit, query) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), query, 0, to_integer<int64>(offset_message_id), 0, to_integer<int32>(limit),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::searchMessagesFilterDocument>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SearchPhoto") {
|
|
|
|
string chat_id;
|
|
|
|
string offset_message_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(offset_message_id, args) = split(args);
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "2000000000000000000";
|
|
|
|
}
|
|
|
|
std::tie(limit, query) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::searchMessagesFilterPhoto>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SearchChatPhoto") {
|
|
|
|
string chat_id;
|
|
|
|
string offset_message_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(offset_message_id, args) = split(args);
|
|
|
|
if (offset_message_id.empty()) {
|
|
|
|
offset_message_id = "2000000000000000000";
|
|
|
|
}
|
|
|
|
std::tie(limit, query) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMessages>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), query, 0, as_message_id(offset_message_id), 0, to_integer<int32>(limit),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::searchMessagesFilterChatPhoto>()));
|
2018-07-19 15:58:09 +02:00
|
|
|
} else if (op == "gcmc") {
|
|
|
|
string chat_id;
|
|
|
|
string filter;
|
|
|
|
string return_local;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(filter, return_local) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatMessageCount>(
|
|
|
|
as_chat_id(chat_id), get_search_messages_filter(filter), as_bool(return_local)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gup" || op == "GetUserPhotos") {
|
|
|
|
string user_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(user_id, args) = split(args);
|
|
|
|
std::tie(offset, args) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
|
|
|
if (!args.empty()) {
|
|
|
|
LOG(ERROR) << "Wrong parameters to function getUserProfilePhotos specified";
|
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getUserProfilePhotos>(as_user_id(user_id), to_integer<int32>(offset),
|
|
|
|
to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
} else if (op == "dcrm") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteChatReplyMarkup>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-09-04 03:29:26 +02:00
|
|
|
} else if (op == "glti") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getLocalizationTargetInfo>(as_bool(args)));
|
2019-02-12 02:15:45 +01:00
|
|
|
} else if (op == "glpi") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getLanguagePackInfo>(args));
|
2018-07-03 19:28:00 +02:00
|
|
|
} else if (op == "glps") {
|
|
|
|
string language_code;
|
|
|
|
string keys;
|
|
|
|
|
|
|
|
std::tie(language_code, keys) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getLanguagePackStrings>(language_code, full_split(keys)));
|
2018-07-23 19:29:14 +02:00
|
|
|
} else if (op == "glpss") {
|
|
|
|
string language_database_path;
|
|
|
|
string language_pack;
|
|
|
|
string language_code;
|
|
|
|
string key;
|
|
|
|
|
|
|
|
std::tie(language_database_path, args) = split(args);
|
|
|
|
std::tie(language_pack, args) = split(args);
|
|
|
|
std::tie(language_code, key) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getLanguagePackString>(language_database_path, language_pack,
|
|
|
|
language_code, key));
|
2019-02-23 18:27:14 +01:00
|
|
|
} else if (op == "synclp") {
|
|
|
|
string language_code = args;
|
|
|
|
send_request(td_api::make_object<td_api::synchronizeLanguagePack>(language_code));
|
2019-02-11 19:53:10 +01:00
|
|
|
} else if (op == "acslp") {
|
|
|
|
string language_code = args;
|
|
|
|
send_request(td_api::make_object<td_api::addCustomServerLanguagePack>(language_code));
|
2018-09-04 03:29:26 +02:00
|
|
|
} else if (op == "sclp") {
|
2018-08-06 16:22:22 +02:00
|
|
|
string language_code;
|
|
|
|
string name;
|
|
|
|
string native_name;
|
|
|
|
string key;
|
|
|
|
|
|
|
|
std::tie(language_code, args) = split(args);
|
|
|
|
std::tie(name, args) = split(args);
|
|
|
|
std::tie(native_name, key) = split(args);
|
|
|
|
|
2018-08-22 23:29:26 +02:00
|
|
|
vector<tl_object_ptr<td_api::languagePackString>> strings;
|
2019-02-21 17:48:05 +01:00
|
|
|
strings.push_back(td_api::make_object<td_api::languagePackString>(
|
|
|
|
key, td_api::make_object<td_api::languagePackStringValueOrdinary>("Ordinary value")));
|
|
|
|
strings.push_back(td_api::make_object<td_api::languagePackString>(
|
|
|
|
"Plu", td_api::make_object<td_api::languagePackStringValuePluralized>("Zero", string("One\0One", 7), "Two",
|
|
|
|
"Few", "Many", "Other")));
|
|
|
|
strings.push_back(td_api::make_object<td_api::languagePackString>(
|
|
|
|
"DELETED", td_api::make_object<td_api::languagePackStringValueDeleted>()));
|
|
|
|
|
|
|
|
send_request(td_api::make_object<td_api::setCustomLanguagePack>(
|
2019-02-11 18:57:35 +01:00
|
|
|
as_language_pack_info(language_code, name, native_name), std::move(strings)));
|
2018-09-04 03:29:26 +02:00
|
|
|
} else if (op == "eclpi") {
|
2018-08-31 19:18:12 +02:00
|
|
|
string language_code;
|
|
|
|
string name;
|
|
|
|
string native_name;
|
|
|
|
|
|
|
|
std::tie(language_code, args) = split(args);
|
|
|
|
std::tie(name, native_name) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editCustomLanguagePackInfo>(
|
|
|
|
as_language_pack_info(language_code, name, native_name)));
|
2018-09-04 03:29:26 +02:00
|
|
|
} else if (op == "sclpsv" || op == "sclpsp" || op == "sclpsd") {
|
2018-08-22 22:11:54 +02:00
|
|
|
string language_code;
|
|
|
|
string key;
|
|
|
|
string value;
|
|
|
|
|
|
|
|
std::tie(language_code, args) = split(args);
|
|
|
|
std::tie(key, value) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
tl_object_ptr<td_api::languagePackString> str = td_api::make_object<td_api::languagePackString>(key, nullptr);
|
2018-08-22 22:11:54 +02:00
|
|
|
if (op == "sclsv") {
|
2019-02-21 17:48:05 +01:00
|
|
|
str->value_ = td_api::make_object<td_api::languagePackStringValueOrdinary>(value);
|
2018-08-22 22:11:54 +02:00
|
|
|
} else if (op == "sclsp") {
|
2019-02-21 17:48:05 +01:00
|
|
|
str->value_ = td_api::make_object<td_api::languagePackStringValuePluralized>(value, string("One\0One", 7),
|
|
|
|
"Two", "Few", "Many", "Other");
|
2018-08-22 22:11:54 +02:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
str->value_ = td_api::make_object<td_api::languagePackStringValueDeleted>();
|
2018-08-22 22:11:54 +02:00
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setCustomLanguagePackString>(language_code, std::move(str)));
|
2018-09-04 03:29:26 +02:00
|
|
|
} else if (op == "dlp") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteLanguagePack>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "go") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getOption>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sob") {
|
|
|
|
string name;
|
|
|
|
string value;
|
|
|
|
|
|
|
|
std::tie(name, value) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>(
|
|
|
|
name, td_api::make_object<td_api::optionValueBoolean>(as_bool(value))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "soe") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>(args, td_api::make_object<td_api::optionValueEmpty>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "soi") {
|
|
|
|
string name;
|
|
|
|
string value;
|
|
|
|
|
|
|
|
std::tie(name, value) = split(args);
|
|
|
|
int32 value_int = to_integer<int32>(value);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::setOption>(name, td_api::make_object<td_api::optionValueInteger>(value_int)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sos") {
|
|
|
|
string name;
|
|
|
|
string value;
|
|
|
|
|
|
|
|
std::tie(name, value) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setOption>(name, td_api::make_object<td_api::optionValueString>(value)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "me") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMe>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sattl") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::setAccountTtl>(td_api::make_object<td_api::accountTtl>(to_integer<int32>(args))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gattl") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getAccountTtl>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "GetActiveSessions") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getActiveSessions>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "TerminateSession") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::terminateSession>(to_integer<int64>(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "TerminateAllOtherSessions") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::terminateAllOtherSessions>());
|
2018-02-07 00:31:38 +01:00
|
|
|
} else if (op == "gcw") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getConnectedWebsites>());
|
2018-02-07 00:31:38 +01:00
|
|
|
} else if (op == "dw") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::disconnectWebsite>(to_integer<int64>(args)));
|
2018-02-07 00:31:38 +01:00
|
|
|
} else if (op == "daw") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::disconnectAllWebsites>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gw") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getWallpapers>());
|
2018-03-04 22:36:16 +01:00
|
|
|
} else if (op == "gccode") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getCountryCode>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "git") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getInviteText>());
|
2018-06-07 20:42:17 +02:00
|
|
|
} else if (op == "atos") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
|
2018-04-12 22:51:42 +02:00
|
|
|
} else if (op == "gdli") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getDeepLinkInfo>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "tme") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRecentlyVisitedTMeUrls>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "bu") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::blockUser>(as_user_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ubu") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::unblockUser>(as_user_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gbu") {
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getBlockedUsers>(to_integer<int32>(offset), to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gu") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getUser>(as_user_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gsu") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupportUser>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gs") {
|
|
|
|
string limit;
|
|
|
|
string emoji;
|
|
|
|
std::tie(limit, emoji) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getStickers>(emoji, to_integer<int32>(limit)));
|
2018-03-09 18:04:44 +01:00
|
|
|
} else if (op == "sst") {
|
|
|
|
string limit;
|
|
|
|
string emoji;
|
|
|
|
std::tie(limit, emoji) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchStickers>(emoji, to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getStickerSet>(to_integer<int64>(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "giss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getInstalledStickerSets>(as_bool(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gass") {
|
|
|
|
string is_masks;
|
|
|
|
string offset_sticker_set_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(is_masks, args) = split(args);
|
|
|
|
std::tie(offset_sticker_set_id, limit) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getArchivedStickerSets>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_bool(is_masks), to_integer<int64>(offset_sticker_set_id), to_integer<int32>(limit)));
|
|
|
|
} else if (op == "gtss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getTrendingStickerSets>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gatss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getAttachedStickerSets>(as_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "storage") {
|
2019-01-07 16:37:53 +01:00
|
|
|
auto chat_limit = to_integer<int32>(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getStorageStatistics>(chat_limit));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "storage_fast") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getStorageStatisticsFast>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "optimize_storage") {
|
|
|
|
string chat_ids;
|
|
|
|
string exclude_chat_ids;
|
|
|
|
string chat_ids_limit;
|
|
|
|
std::tie(chat_ids, args) = split(args);
|
|
|
|
std::tie(exclude_chat_ids, chat_ids_limit) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::optimizeStorage>(
|
2018-12-31 20:04:05 +01:00
|
|
|
10000000, -1, -1, 0, std::vector<tl_object_ptr<td_api::FileType>>(), as_chat_ids(chat_ids, ','),
|
|
|
|
as_chat_ids(exclude_chat_ids, ','), to_integer<int32>(chat_ids_limit)));
|
2018-01-26 14:01:40 +01:00
|
|
|
} else if (op == "clean_storage_default") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::optimizeStorage>());
|
2018-05-30 21:45:42 +02:00
|
|
|
} else if (op == "clean_photos") {
|
|
|
|
std::vector<tl_object_ptr<td_api::FileType>> types;
|
2019-02-21 17:48:05 +01:00
|
|
|
types.push_back(td_api::make_object<td_api::fileTypePhoto>());
|
|
|
|
send_request(td_api::make_object<td_api::optimizeStorage>(0, 0, 0, 0, std::move(types), as_chat_ids(""),
|
|
|
|
as_chat_ids(""), 20));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "clean_storage") {
|
|
|
|
std::vector<tl_object_ptr<td_api::FileType>> types;
|
2019-02-21 17:48:05 +01:00
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeThumbnail>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeProfilePhoto>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypePhoto>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeVoiceNote>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeVideo>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeDocument>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeSecret>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeUnknown>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeSticker>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeAudio>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeAnimation>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeVideoNote>());
|
|
|
|
types.push_back(td_api::make_object<td_api::fileTypeSecure>());
|
|
|
|
send_request(td_api::make_object<td_api::optimizeStorage>(0, -1, -1, 0, std::move(types), as_chat_ids(args, ','),
|
|
|
|
as_chat_ids(""), 20));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "network") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getNetworkStatistics>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "current_network") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getNetworkStatistics>(true));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "reset_network") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resetNetworkStatistics>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "snt") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setNetworkType>(get_network_type(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ansc") {
|
|
|
|
string sent_bytes;
|
|
|
|
string received_bytes;
|
|
|
|
string duration;
|
|
|
|
string network_type;
|
|
|
|
std::tie(sent_bytes, args) = split(args);
|
|
|
|
std::tie(received_bytes, args) = split(args);
|
|
|
|
std::tie(duration, network_type) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::addNetworkStatistics>(td_api::make_object<td_api::networkStatisticsEntryCall>(
|
|
|
|
get_network_type(network_type), to_integer<int32>(sent_bytes), to_integer<int32>(received_bytes),
|
|
|
|
to_double(duration))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ans") {
|
|
|
|
string sent_bytes;
|
|
|
|
string received_bytes;
|
|
|
|
string network_type;
|
|
|
|
std::tie(sent_bytes, args) = split(args);
|
|
|
|
std::tie(received_bytes, network_type) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::addNetworkStatistics>(td_api::make_object<td_api::networkStatisticsEntryFile>(
|
|
|
|
td_api::make_object<td_api::fileTypeDocument>(), get_network_type(network_type),
|
|
|
|
to_integer<int32>(sent_bytes), to_integer<int32>(received_bytes))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "top_chats") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getTopChats>(get_top_chat_category(args), 50));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rtc") {
|
|
|
|
string chat_id;
|
|
|
|
string category;
|
|
|
|
std::tie(chat_id, category) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeTopChat>(get_top_chat_category(category), as_chat_id(chat_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchStickerSet>(args));
|
2018-03-05 23:44:11 +01:00
|
|
|
} else if (op == "siss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchInstalledStickerSets>(false, args, 2));
|
2018-03-05 23:44:11 +01:00
|
|
|
} else if (op == "ssss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchStickerSets>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "css") {
|
|
|
|
string set_id;
|
|
|
|
string is_installed;
|
|
|
|
string is_archived;
|
|
|
|
|
|
|
|
std::tie(set_id, args) = split(args);
|
|
|
|
std::tie(is_installed, is_archived) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::changeStickerSet>(to_integer<int64>(set_id), as_bool(is_installed),
|
|
|
|
as_bool(is_archived)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "vtss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::viewTrendingStickerSets>(to_integers<int64>(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "riss") {
|
|
|
|
string is_masks;
|
|
|
|
string new_order;
|
|
|
|
|
|
|
|
std::tie(is_masks, new_order) = split(args);
|
|
|
|
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::reorderInstalledStickerSets>(as_bool(is_masks), to_integers<int64>(new_order)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "grs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRecentStickers>(as_bool(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ars") {
|
|
|
|
string is_attached;
|
|
|
|
string sticker_id;
|
|
|
|
|
|
|
|
std::tie(is_attached, sticker_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addRecentSticker>(as_bool(is_attached), as_input_file_id(sticker_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rrs") {
|
|
|
|
string is_attached;
|
|
|
|
string sticker_id;
|
|
|
|
|
|
|
|
std::tie(is_attached, sticker_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::removeRecentSticker>(as_bool(is_attached), as_input_file_id(sticker_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gfs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getFavoriteStickers>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "afs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addFavoriteSticker>(as_input_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rfs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeFavoriteSticker>(as_input_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "crs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::clearRecentStickers>(as_bool(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gse") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getStickerEmojis>(as_input_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
op_not_found_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op == "gsan") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSavedAnimations>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "asan") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addSavedAnimation>(as_input_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rsan") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeSavedAnimation>(as_input_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "guf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getUserFullInfo>(as_user_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gbg") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getBasicGroup>(as_basic_group_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gbgf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getBasicGroupFullInfo>(as_basic_group_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gsg" || op == "gch") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroup>(as_supergroup_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gsgf" || op == "gchf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupFullInfo>(as_supergroup_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gsc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSecretChat>(as_secret_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scm") {
|
|
|
|
string chat_id;
|
|
|
|
string limit;
|
|
|
|
string query;
|
2018-07-20 02:00:17 +02:00
|
|
|
string filter;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
2018-07-20 02:00:17 +02:00
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
std::tie(query, filter) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatMembers>(as_chat_id(chat_id), query, to_integer<int32>(limit),
|
|
|
|
get_chat_members_filter(filter)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcm") {
|
|
|
|
string chat_id;
|
|
|
|
string user_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, user_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatMember>(as_chat_id(chat_id), as_user_id(user_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "GetSupergroupAdministrators") {
|
|
|
|
string supergroup_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterAdministrators>(),
|
2018-12-31 20:04:05 +01:00
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
|
|
|
} else if (op == "GetChatAdministrators") {
|
|
|
|
string chat_id = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatAdministrators>(as_chat_id(chat_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "GetSupergroupBanned") {
|
|
|
|
string supergroup_id;
|
|
|
|
string query;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(query, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterBanned>(query),
|
2018-12-31 20:04:05 +01:00
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
|
|
|
} else if (op == "GetSupergroupBots") {
|
|
|
|
string supergroup_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterBots>(),
|
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "GetSupergroupMembers") {
|
|
|
|
string supergroup_id;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterRecent>(),
|
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SearchSupergroupMembers") {
|
|
|
|
string supergroup_id;
|
|
|
|
string query;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(query, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterSearch>(query),
|
2018-12-31 20:04:05 +01:00
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
|
|
|
} else if (op == "GetSupergroupRestricted") {
|
|
|
|
string supergroup_id;
|
|
|
|
string query;
|
|
|
|
string offset;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, args) = split(args);
|
|
|
|
std::tie(query, args) = split(args);
|
|
|
|
std::tie(offset, limit) = split(args);
|
|
|
|
if (offset.empty()) {
|
|
|
|
offset = "0";
|
|
|
|
}
|
|
|
|
if (limit.empty()) {
|
|
|
|
limit = "10";
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getSupergroupMembers>(
|
|
|
|
as_supergroup_id(supergroup_id), td_api::make_object<td_api::supergroupMembersFilterRestricted>(query),
|
2018-12-31 20:04:05 +01:00
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
|
|
|
} else if (op == "gdialog" || op == "gd") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "open") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::openChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "close") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::closeChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gm") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMessage>(as_chat_id(chat_id), as_message_id(message_id)));
|
2019-03-05 00:06:48 +01:00
|
|
|
} else if (op == "gmf") {
|
|
|
|
string chat_id;
|
|
|
|
string from_message_id_str;
|
|
|
|
string to_message_id_str;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(from_message_id_str, to_message_id_str) = split(args);
|
2019-03-05 04:45:14 +01:00
|
|
|
auto to_message_id = to_integer<int64>(to_message_id_str);
|
|
|
|
for (auto message_id = to_integer<int64>(from_message_id_str); message_id <= to_message_id; message_id++) {
|
2019-03-05 00:06:48 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMessage>(as_chat_id(chat_id), message_id << 20));
|
|
|
|
}
|
2019-01-09 03:57:43 +01:00
|
|
|
} else if (op == "gml") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMessageLocally>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-02-07 00:31:38 +01:00
|
|
|
} else if (op == "grm") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRepliedMessage>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-02-07 00:31:38 +01:00
|
|
|
} else if (op == "gcpm") {
|
|
|
|
string chat_id = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatPinnedMessage>(as_chat_id(chat_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gms") {
|
|
|
|
string chat_id;
|
|
|
|
string message_ids;
|
|
|
|
std::tie(chat_id, message_ids) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMessages>(as_chat_id(chat_id), as_message_ids(message_ids)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gpml") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
2018-01-16 22:27:16 +01:00
|
|
|
string for_album;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, for_album) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getPublicMessageLink>(as_chat_id(chat_id), as_message_id(message_id),
|
|
|
|
as_bool(for_album)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcmbd") {
|
|
|
|
string chat_id;
|
|
|
|
string date;
|
|
|
|
std::tie(chat_id, date) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatMessageByDate>(as_chat_id(chat_id), to_integer<int32>(date)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gf" || op == "GetFile") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getFile>(as_file_id(args)));
|
2018-12-26 17:11:15 +01:00
|
|
|
} else if (op == "gfdps") {
|
2018-11-11 12:38:04 +01:00
|
|
|
string file_id;
|
|
|
|
string offset;
|
|
|
|
std::tie(file_id, offset) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::getFileDownloadedPrefixSize>(as_file_id(file_id), to_integer<int32>(offset)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "grf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRemoteFile>(args, nullptr));
|
2018-08-13 22:18:27 +02:00
|
|
|
} else if (op == "gmtf") {
|
|
|
|
string latitude;
|
|
|
|
string longitude;
|
|
|
|
string zoom;
|
|
|
|
string width;
|
|
|
|
string height;
|
|
|
|
string scale;
|
|
|
|
string chat_id;
|
|
|
|
std::tie(latitude, args) = split(args);
|
|
|
|
std::tie(longitude, args) = split(args);
|
|
|
|
std::tie(zoom, args) = split(args);
|
|
|
|
std::tie(width, args) = split(args);
|
|
|
|
std::tie(height, args) = split(args);
|
|
|
|
std::tie(scale, chat_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getMapThumbnailFile>(
|
2018-08-13 22:18:27 +02:00
|
|
|
as_location(latitude, longitude), to_integer<int32>(zoom), to_integer<int32>(width),
|
|
|
|
to_integer<int32>(height), to_integer<int32>(scale), as_chat_id(chat_id)));
|
2019-02-21 17:45:42 +01:00
|
|
|
} else if (op == "df" || op == "DownloadFile" || op == "dff") {
|
2018-12-26 17:11:15 +01:00
|
|
|
string file_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
string priority;
|
2018-11-11 12:38:04 +01:00
|
|
|
string offset;
|
2019-02-18 20:08:05 +01:00
|
|
|
string limit;
|
2018-12-26 17:11:15 +01:00
|
|
|
std::tie(file_id, args) = split(args);
|
2019-02-18 20:08:05 +01:00
|
|
|
std::tie(offset, args) = split(args);
|
|
|
|
std::tie(limit, priority) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
if (priority.empty()) {
|
|
|
|
priority = "1";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:45:42 +01:00
|
|
|
int32 max_file_id = as_file_id(file_id);
|
|
|
|
int32 min_file_id = (op == "dff" ? 1 : max_file_id);
|
|
|
|
for (int32 i = min_file_id; i <= max_file_id; i++) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::downloadFile>(i, to_integer<int32>(priority),
|
|
|
|
to_integer<int32>(offset), to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
} else if (op == "cdf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::cancelDownloadFile>(as_file_id(args), false));
|
2018-04-27 10:00:56 +02:00
|
|
|
} else if (op == "uf" || op == "ufs" || op == "ufse") {
|
2018-12-31 20:04:05 +01:00
|
|
|
string file_path;
|
|
|
|
string priority;
|
|
|
|
std::tie(file_path, priority) = split(args);
|
|
|
|
if (priority.empty()) {
|
|
|
|
priority = "1";
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::object_ptr<td_api::FileType> type = td_api::make_object<td_api::fileTypePhoto>();
|
2018-04-26 22:41:34 +02:00
|
|
|
if (op == "ufs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
type = td_api::make_object<td_api::fileTypeSecret>();
|
2018-04-26 22:41:34 +02:00
|
|
|
}
|
|
|
|
if (op == "ufse") {
|
2019-02-21 17:48:05 +01:00
|
|
|
type = td_api::make_object<td_api::fileTypeSecure>();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::uploadFile>(as_input_file(file_path), std::move(type),
|
|
|
|
to_integer<int32>(priority)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ufg") {
|
|
|
|
string file_path;
|
|
|
|
string conversion;
|
|
|
|
std::tie(file_path, conversion) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::uploadFile>(as_generated_file(file_path, conversion),
|
|
|
|
td_api::make_object<td_api::fileTypePhoto>(), 1));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cuf") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::cancelUploadFile>(as_file_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "delf" || op == "DeleteFile") {
|
|
|
|
string file_id = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteFile>(as_file_id(file_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dm") {
|
|
|
|
string chat_id;
|
2018-03-02 17:21:43 +01:00
|
|
|
string message_ids;
|
2018-12-31 20:04:05 +01:00
|
|
|
string revoke;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
2018-03-02 17:21:43 +01:00
|
|
|
std::tie(message_ids, revoke) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteMessages>(as_chat_id(chat_id), as_message_ids(message_ids, ','),
|
|
|
|
as_bool(revoke)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "fm" || op == "fmg") {
|
|
|
|
string chat_id;
|
|
|
|
string from_chat_id;
|
2018-03-02 17:21:43 +01:00
|
|
|
string message_ids;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::tie(chat_id, args) = split(args);
|
2018-03-02 17:21:43 +01:00
|
|
|
std::tie(from_chat_id, message_ids) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
auto chat = as_chat_id(chat_id);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::forwardMessages>(
|
|
|
|
chat, as_chat_id(from_chat_id), as_message_ids(message_ids), false, false, op == "fmg"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "csc" || op == "CreateSecretChat") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createSecretChat>(as_secret_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cnsc" || op == "CreateNewSecretChat") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createNewSecretChat>(as_user_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scstn") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendChatScreenshotTakenNotification>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sscttl" || op == "setSecretChatTtl") {
|
|
|
|
string chat_id;
|
|
|
|
string ttl;
|
|
|
|
std::tie(chat_id, ttl) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendChatSetTtlMessage>(as_chat_id(chat_id), to_integer<int32>(ttl)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "closeSC" || op == "cancelSC") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::closeSecretChat>(as_secret_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cc" || op == "CreateCall") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createCall>(
|
|
|
|
as_user_id(args), td_api::make_object<td_api::callProtocol>(true, true, 65, 65)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dc" || op == "DiscardCall") {
|
|
|
|
string call_id;
|
|
|
|
string is_disconnected;
|
|
|
|
std::tie(call_id, is_disconnected) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::discardCall>(as_call_id(call_id), as_bool(is_disconnected), 0, 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ac" || op == "AcceptCall") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::acceptCall>(
|
|
|
|
as_call_id(args), td_api::make_object<td_api::callProtocol>(true, true, 65, 65)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scr" || op == "SendCallRating") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::sendCallRating>(as_call_id(args), 5, "Wow, such good call! (TDLib test)"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scdi" || op == "SendCallDebugInformation") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendCallDebugInformation>(as_call_id(args), "{}"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcil") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::generateChatInviteLink>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ccil") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkChatInviteLink>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "jcbil") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::joinChatByInviteLink>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gte") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getTextEntities>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gtes") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(td_api::make_object<td_api::getTextEntities>(args));
|
2018-01-30 18:06:54 +01:00
|
|
|
} else if (op == "pte") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>()));
|
2018-10-09 15:27:40 +02:00
|
|
|
} else if (op == "pteh") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
|
2018-01-30 18:06:54 +01:00
|
|
|
} else if (op == "ptes") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(
|
|
|
|
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>()));
|
2018-10-09 15:27:40 +02:00
|
|
|
} else if (op == "ptehs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gfmt") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(td_api::make_object<td_api::getFileMimeType>(trim(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gfe") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(td_api::make_object<td_api::getFileExtension>(trim(args)));
|
2018-04-30 14:50:54 +02:00
|
|
|
} else if (op == "cfn") {
|
2019-02-21 17:48:05 +01:00
|
|
|
execute(td_api::make_object<td_api::cleanFileName>(args));
|
2018-12-10 02:01:02 +01:00
|
|
|
} else if (op == "gjv") {
|
|
|
|
execute(td_api::make_object<td_api::getJsonValue>(args));
|
2018-12-10 20:08:58 +01:00
|
|
|
} else if (op == "gjvtest") {
|
|
|
|
execute(td_api::make_object<td_api::getJsonValue>("\"aba\200caba\""));
|
|
|
|
execute(td_api::make_object<td_api::getJsonValue>("\"\\u0080\""));
|
|
|
|
execute(td_api::make_object<td_api::getJsonValue>("\"\\uD800\""));
|
2018-12-10 02:01:02 +01:00
|
|
|
} else if (op == "gjs") {
|
2018-12-10 20:08:58 +01:00
|
|
|
auto test_get_json_string = [&](auto &&json_value) {
|
|
|
|
execute(td_api::make_object<td_api::getJsonString>(std::move(json_value)));
|
|
|
|
};
|
|
|
|
|
|
|
|
test_get_json_string(nullptr);
|
|
|
|
test_get_json_string(td_api::make_object<td_api::jsonValueNull>());
|
|
|
|
test_get_json_string(td_api::make_object<td_api::jsonValueBoolean>(true));
|
|
|
|
test_get_json_string(td_api::make_object<td_api::jsonValueNumber>(123456789123.0));
|
|
|
|
test_get_json_string(td_api::make_object<td_api::jsonValueString>(string("aba\0caba", 8)));
|
|
|
|
test_get_json_string(td_api::make_object<td_api::jsonValueString>("aba\200caba"));
|
2018-12-10 02:01:02 +01:00
|
|
|
|
|
|
|
auto inner_array = td_api::make_object<td_api::jsonValueArray>();
|
|
|
|
inner_array->values_.push_back(td_api::make_object<td_api::jsonValueBoolean>(false));
|
|
|
|
auto array = td_api::make_object<td_api::jsonValueArray>();
|
|
|
|
array->values_.push_back(nullptr);
|
|
|
|
array->values_.push_back(std::move(inner_array));
|
|
|
|
array->values_.push_back(td_api::make_object<td_api::jsonValueNull>());
|
|
|
|
array->values_.push_back(td_api::make_object<td_api::jsonValueNumber>(-1));
|
2018-12-10 20:08:58 +01:00
|
|
|
test_get_json_string(std::move(array));
|
2018-12-10 02:01:02 +01:00
|
|
|
|
|
|
|
auto object = td_api::make_object<td_api::jsonValueObject>();
|
|
|
|
object->members_.push_back(
|
|
|
|
td_api::make_object<td_api::jsonObjectMember>("", td_api::make_object<td_api::jsonValueString>("test")));
|
|
|
|
object->members_.push_back(td_api::make_object<td_api::jsonObjectMember>("a", nullptr));
|
2018-12-10 20:08:58 +01:00
|
|
|
object->members_.push_back(td_api::make_object<td_api::jsonObjectMember>("\x80", nullptr));
|
2018-12-10 02:01:02 +01:00
|
|
|
object->members_.push_back(nullptr);
|
|
|
|
object->members_.push_back(
|
|
|
|
td_api::make_object<td_api::jsonObjectMember>("a", td_api::make_object<td_api::jsonValueNull>()));
|
2018-12-10 20:08:58 +01:00
|
|
|
test_get_json_string(std::move(object));
|
|
|
|
} else if (op == "gac") {
|
|
|
|
send_request(td_api::make_object<td_api::getApplicationConfig>());
|
|
|
|
} else if (op == "sale") {
|
|
|
|
string type;
|
|
|
|
string chat_id;
|
|
|
|
string json;
|
|
|
|
std::tie(type, args) = split(args);
|
|
|
|
std::tie(chat_id, json) = split(args);
|
|
|
|
|
|
|
|
auto result = execute(td_api::make_object<td_api::getJsonValue>(json));
|
|
|
|
if (result->get_id() == td_api::error::ID) {
|
|
|
|
LOG(ERROR) << to_string(result);
|
|
|
|
} else {
|
|
|
|
send_request(td_api::make_object<td_api::saveApplicationLogEvent>(
|
|
|
|
type, as_chat_id(chat_id), move_tl_object_as<td_api::JsonValue>(result)));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
op_not_found_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op == "scdm") {
|
|
|
|
string chat_id;
|
|
|
|
string reply_to_message_id;
|
|
|
|
string message;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(reply_to_message_id, message) = split(args);
|
|
|
|
tl_object_ptr<td_api::draftMessage> draft_message;
|
|
|
|
if (!reply_to_message_id.empty() || !message.empty()) {
|
|
|
|
vector<tl_object_ptr<td_api::textEntity>> entities;
|
2019-02-21 17:48:05 +01:00
|
|
|
entities.push_back(
|
|
|
|
td_api::make_object<td_api::textEntity>(0, 1, td_api::make_object<td_api::textEntityTypePre>()));
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
draft_message = td_api::make_object<td_api::draftMessage>(
|
|
|
|
as_message_id(reply_to_message_id), td_api::make_object<td_api::inputMessageText>(
|
|
|
|
as_formatted_text(message, std::move(entities)), true, false));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatDraftMessage>(as_chat_id(chat_id), std::move(draft_message)));
|
2018-07-17 05:46:27 +02:00
|
|
|
} else if (op == "cadm") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::clearAllDraftMessages>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "tcip") {
|
|
|
|
string chat_id;
|
|
|
|
string is_pinned;
|
|
|
|
std::tie(chat_id, is_pinned) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleChatIsPinned>(as_chat_id(chat_id), as_bool(is_pinned)));
|
2018-06-27 23:08:44 +02:00
|
|
|
} else if (op == "tcimar") {
|
|
|
|
string chat_id;
|
|
|
|
string is_marked_as_read;
|
|
|
|
std::tie(chat_id, is_marked_as_read) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::toggleChatIsMarkedAsUnread>(as_chat_id(chat_id), as_bool(is_marked_as_read)));
|
2018-04-28 20:05:04 +02:00
|
|
|
} else if (op == "tcddn") {
|
|
|
|
string chat_id;
|
|
|
|
string default_disable_notification;
|
|
|
|
std::tie(chat_id, default_disable_notification) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleChatDefaultDisableNotification>(
|
|
|
|
as_chat_id(chat_id), as_bool(default_disable_notification)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spchats") {
|
|
|
|
vector<string> chat_ids_str = full_split(args, ' ');
|
|
|
|
vector<int64> chat_ids;
|
|
|
|
for (auto &chat_id_str : chat_ids_str) {
|
|
|
|
chat_ids.push_back(as_chat_id(chat_id_str));
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setPinnedChats>(std::move(chat_ids)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sca") {
|
|
|
|
string chat_id;
|
|
|
|
string action;
|
|
|
|
std::tie(chat_id, action) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendChatAction>(as_chat_id(chat_id), get_chat_action(action)));
|
2018-02-13 15:01:30 +01:00
|
|
|
} else if (op == "smt" || op == "smtp" || op == "smtf" || op == "smtpf") {
|
2018-12-31 20:04:05 +01:00
|
|
|
const string &chat_id = args;
|
|
|
|
for (int i = 1; i <= 200; i++) {
|
|
|
|
string message = PSTRING() << "#" << i;
|
2018-02-13 15:01:30 +01:00
|
|
|
if (i == 6 || (op.back() == 'f' && i % 2 == 0)) {
|
|
|
|
message = string(4097, 'a');
|
|
|
|
}
|
|
|
|
if (op[3] == 'p') {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(as_local_file("rgb.jpg"), nullptr,
|
|
|
|
Auto(), 0, 0, as_caption(message), 0));
|
2018-01-30 18:06:54 +01:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), false, true));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (op == "ssm") {
|
|
|
|
string chat_id;
|
|
|
|
string from_search_id;
|
|
|
|
string limit;
|
|
|
|
string filter;
|
|
|
|
string query;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(from_search_id, args) = split(args);
|
|
|
|
std::tie(limit, args) = split(args);
|
|
|
|
std::tie(filter, query) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchSecretMessages>(
|
|
|
|
as_chat_id(chat_id), query, to_integer<int64>(from_search_id), to_integer<int32>(limit),
|
|
|
|
get_search_messages_filter(filter)));
|
2018-01-30 18:06:54 +01:00
|
|
|
} else if (op == "sm" || op == "sms" || op == "smr" || op == "smf") {
|
2018-12-31 20:04:05 +01:00
|
|
|
string chat_id;
|
2018-01-30 18:06:54 +01:00
|
|
|
string reply_to_message_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
string message;
|
2018-01-30 18:06:54 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
std::tie(chat_id, message) = split(args);
|
2018-01-30 18:06:54 +01:00
|
|
|
if (op == "smr") {
|
|
|
|
std::tie(reply_to_message_id, message) = split(message);
|
|
|
|
}
|
|
|
|
if (op == "smf") {
|
2018-04-04 21:30:10 +02:00
|
|
|
message = string(5097, 'a');
|
2018-01-30 18:06:54 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), false, true),
|
2018-06-19 01:31:34 +02:00
|
|
|
op == "sms", false, as_message_id(reply_to_message_id));
|
2018-03-26 22:20:56 +02:00
|
|
|
} else if (op == "alm" || op == "almr") {
|
|
|
|
string chat_id;
|
2018-03-27 16:55:33 +02:00
|
|
|
string user_id;
|
2018-03-26 22:20:56 +02:00
|
|
|
string reply_to_message_id;
|
|
|
|
string message;
|
|
|
|
|
2018-03-27 16:55:33 +02:00
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(user_id, message) = split(args);
|
2018-04-27 18:51:11 +02:00
|
|
|
if (op == "almr") {
|
2018-03-26 22:20:56 +02:00
|
|
|
std::tie(reply_to_message_id, message) = split(message);
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addLocalMessage>(
|
2018-03-27 16:55:33 +02:00
|
|
|
as_chat_id(chat_id), as_user_id(user_id), as_message_id(reply_to_message_id), false,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), false, true)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "smap" || op == "smapr") {
|
|
|
|
string chat_id;
|
|
|
|
string reply_to_message_id;
|
|
|
|
vector<string> photos;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
if (op == "smapr") {
|
|
|
|
std::tie(reply_to_message_id, args) = split(args);
|
|
|
|
}
|
|
|
|
photos = full_split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendMessageAlbum>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), as_message_id(reply_to_message_id), false, false,
|
|
|
|
transform(photos, [](const string &photo_path) {
|
2019-02-21 17:48:05 +01:00
|
|
|
tl_object_ptr<td_api::InputMessageContent> content = td_api::make_object<td_api::inputMessagePhoto>(
|
2019-02-08 15:54:23 +01:00
|
|
|
as_input_file(photo_path), nullptr, Auto(), 0, 0, as_caption(""), 0);
|
2018-12-31 20:04:05 +01:00
|
|
|
return content;
|
|
|
|
})));
|
|
|
|
} else if (op == "em") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string message;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, message) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageText>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), true, true)));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "eman") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string animation;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, animation) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageMedia>(
|
2018-06-19 01:31:34 +02:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageAnimation>(as_input_file(animation), nullptr, 0, 0, 0,
|
|
|
|
as_caption("animation"))));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "emc") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string caption;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, caption) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageCaption>(as_chat_id(chat_id), as_message_id(message_id),
|
|
|
|
nullptr, as_caption(caption)));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "emd") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string document;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, document) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageMedia>(
|
2018-06-19 01:31:34 +02:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageDocument>(as_input_file(document), nullptr, as_caption(""))));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "emp") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string photo;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, photo) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageMedia>(
|
2018-06-19 01:31:34 +02:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessagePhoto>(as_input_file(photo), as_input_thumbnail(as_input_file(photo)),
|
|
|
|
Auto(), 0, 0, as_caption(""), 0)));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "empttl") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string photo;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, photo) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageMedia>(
|
2018-06-19 01:31:34 +02:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessagePhoto>(as_input_file(photo), as_input_thumbnail(as_input_file(photo)),
|
|
|
|
Auto(), 0, 0, as_caption(""), 10)));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op == "emvt") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string video;
|
|
|
|
string thumbnail;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, args) = split(args);
|
|
|
|
std::tie(video, thumbnail) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageMedia>(
|
2018-06-19 01:31:34 +02:00
|
|
|
as_chat_id(chat_id), as_message_id(message_id), nullptr,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageVideo>(as_input_file(video),
|
|
|
|
as_input_thumbnail(as_input_file(thumbnail)), Auto(), 1, 2, 3,
|
|
|
|
true, as_caption(""), 0)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "emll") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string latitude;
|
|
|
|
string longitude;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, args) = split(args);
|
|
|
|
std::tie(latitude, longitude) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editMessageLiveLocation>(as_chat_id(chat_id), as_message_id(message_id),
|
|
|
|
nullptr, as_location(latitude, longitude)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gallm") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getActiveLiveLocationMessages>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sbsm") {
|
|
|
|
string bot_id;
|
|
|
|
string chat_id;
|
|
|
|
string parameter;
|
|
|
|
std::tie(bot_id, args) = split(args);
|
|
|
|
std::tie(chat_id, parameter) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::sendBotStartMessage>(as_user_id(bot_id), as_chat_id(chat_id), parameter));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "giqr") {
|
|
|
|
string bot_id;
|
|
|
|
string query;
|
|
|
|
std::tie(bot_id, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getInlineQueryResults>(as_user_id(bot_id), 0, nullptr, query, ""));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "giqro") {
|
|
|
|
string bot_id;
|
|
|
|
string offset;
|
|
|
|
string query;
|
|
|
|
std::tie(bot_id, args) = split(args);
|
|
|
|
std::tie(offset, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getInlineQueryResults>(as_user_id(bot_id), 0, nullptr, query, offset));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "giqrl") {
|
|
|
|
string bot_id;
|
|
|
|
string query;
|
|
|
|
std::tie(bot_id, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getInlineQueryResults>(as_user_id(bot_id), 0, as_location("1.1", "2.2"),
|
|
|
|
query, ""));
|
2019-01-02 22:05:47 +01:00
|
|
|
} else if (op == "siqr" || op == "siqrh") {
|
2018-12-31 20:04:05 +01:00
|
|
|
string chat_id;
|
|
|
|
string query_id;
|
|
|
|
string result_id;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(query_id, result_id) = split(args);
|
|
|
|
|
|
|
|
auto chat = as_chat_id(chat_id);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::sendInlineQueryResultMessage>(
|
2019-01-02 22:05:47 +01:00
|
|
|
chat, 0, false, false, to_integer<int64>(query_id), result_id, op == "siqrh"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcqr") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string data;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, data) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getCallbackQueryAnswer>(
|
|
|
|
as_chat_id(chat_id), as_message_id(message_id), td_api::make_object<td_api::callbackQueryPayloadData>(data)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcgqr") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getCallbackQueryAnswer>(
|
|
|
|
as_chat_id(chat_id), as_message_id(message_id), td_api::make_object<td_api::callbackQueryPayloadGame>("")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "san") {
|
|
|
|
string chat_id;
|
|
|
|
string animation_path;
|
|
|
|
string width;
|
|
|
|
string height;
|
|
|
|
string caption;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(animation_path, args) = split(args);
|
|
|
|
std::tie(width, args) = split(args);
|
|
|
|
std::tie(height, caption) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(animation_path), nullptr, 60, to_integer<int32>(width),
|
2018-01-30 18:06:54 +01:00
|
|
|
to_integer<int32>(height), as_caption(caption)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sang") {
|
|
|
|
string chat_id;
|
|
|
|
string animation_path;
|
|
|
|
string animation_conversion;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(animation_path, animation_conversion) = split(args);
|
2018-01-30 18:06:54 +01:00
|
|
|
send_message(chat_id,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageAnimation>(
|
2018-01-30 18:06:54 +01:00
|
|
|
as_generated_file(animation_path, animation_conversion), nullptr, 60, 0, 0, as_caption("")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sanid") {
|
|
|
|
string chat_id;
|
|
|
|
string file_id;
|
|
|
|
std::tie(chat_id, file_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_input_file_id(file_id), nullptr, 0, 0,
|
|
|
|
0, as_caption("")));
|
2018-01-05 11:33:08 +01:00
|
|
|
} else if (op == "sanurl") {
|
|
|
|
string chat_id;
|
|
|
|
string url;
|
|
|
|
std::tie(chat_id, url) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_generated_file(url, "#url#"), nullptr,
|
|
|
|
0, 0, 0, as_caption("")));
|
2018-01-05 11:33:08 +01:00
|
|
|
} else if (op == "sanurl2") {
|
|
|
|
string chat_id;
|
|
|
|
string url;
|
|
|
|
std::tie(chat_id, url) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_remote_file(url), nullptr, 0, 0, 0,
|
|
|
|
as_caption("")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sau") {
|
|
|
|
string chat_id;
|
|
|
|
string audio_path;
|
|
|
|
string duration;
|
|
|
|
string title;
|
|
|
|
string performer;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(audio_path, args) = split(args);
|
|
|
|
std::tie(duration, args) = split(args);
|
|
|
|
std::tie(title, performer) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageAudio>(as_input_file(audio_path), nullptr,
|
|
|
|
to_integer<int32>(duration), title,
|
|
|
|
performer, as_caption("audio caption")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "svoice") {
|
|
|
|
string chat_id;
|
|
|
|
string voice_path;
|
|
|
|
std::tie(chat_id, voice_path) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageVoiceNote>(as_input_file(voice_path), 0, "abacaba",
|
|
|
|
as_caption("voice caption")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "SendContact" || op == "scontact") {
|
|
|
|
string chat_id;
|
|
|
|
string phone_number;
|
|
|
|
string first_name;
|
|
|
|
string last_name;
|
|
|
|
string user_id;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(phone_number, args) = split(args);
|
|
|
|
std::tie(first_name, args) = split(args);
|
|
|
|
std::tie(last_name, user_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageContact>(td_api::make_object<td_api::contact>(
|
2018-06-25 23:10:53 +02:00
|
|
|
phone_number, first_name, last_name, string(), as_user_id(user_id))));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sf") {
|
|
|
|
string chat_id;
|
|
|
|
string from_chat_id;
|
|
|
|
string from_message_id;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(from_chat_id, from_message_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageForwarded>(as_chat_id(from_chat_id),
|
|
|
|
as_message_id(from_message_id), true));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sd") {
|
|
|
|
string chat_id;
|
|
|
|
string document_path;
|
|
|
|
std::tie(chat_id, document_path) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageDocument>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(document_path), nullptr,
|
2018-03-13 17:10:26 +01:00
|
|
|
as_caption(u8"\u1680\u180Etest \u180E\n\u180E\n\u180E\n cap\ttion\u180E\u180E")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sdt") {
|
|
|
|
string chat_id;
|
|
|
|
string document_path;
|
|
|
|
string thumbnail_path;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(document_path, thumbnail_path) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageDocument>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(document_path), as_input_thumbnail(as_local_file(thumbnail_path)),
|
2018-01-30 18:06:54 +01:00
|
|
|
as_caption("test caption")));
|
2019-01-19 20:35:28 +01:00
|
|
|
} else if (op == "sdg" || op == "sdgu") {
|
2018-12-31 20:04:05 +01:00
|
|
|
string chat_id;
|
|
|
|
string document_path;
|
|
|
|
string document_conversion;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(document_path, document_conversion) = split(args);
|
2019-01-19 20:35:28 +01:00
|
|
|
if (op == "sdgu") {
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::uploadFile>(as_generated_file(document_path, document_conversion), nullptr, 1));
|
2019-01-19 20:35:28 +01:00
|
|
|
}
|
2018-01-30 18:06:54 +01:00
|
|
|
send_message(chat_id,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessageDocument>(
|
|
|
|
as_generated_file(document_path, document_conversion), nullptr, as_caption("test caption")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sdtg") {
|
|
|
|
string chat_id;
|
|
|
|
string document_path;
|
|
|
|
string thumbnail_path;
|
|
|
|
string thumbnail_conversion;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(document_path, args) = split(args);
|
|
|
|
std::tie(thumbnail_path, thumbnail_conversion) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageDocument>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(document_path),
|
2018-06-01 00:22:27 +02:00
|
|
|
as_input_thumbnail(as_generated_file(thumbnail_path, thumbnail_conversion)),
|
2018-01-30 18:06:54 +01:00
|
|
|
as_caption("test caption")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sdgtg") {
|
|
|
|
string chat_id;
|
|
|
|
string document_path;
|
|
|
|
string document_conversion;
|
|
|
|
string thumbnail_path;
|
|
|
|
string thumbnail_conversion;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(document_path, args) = split(args);
|
|
|
|
std::tie(document_conversion, args) = split(args);
|
|
|
|
std::tie(thumbnail_path, thumbnail_conversion) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageDocument>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_generated_file(document_path, document_conversion),
|
2018-06-01 00:22:27 +02:00
|
|
|
as_input_thumbnail(as_generated_file(thumbnail_path, thumbnail_conversion)),
|
2018-01-30 18:06:54 +01:00
|
|
|
as_caption("test caption")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sdid") {
|
|
|
|
string chat_id;
|
|
|
|
string file_id;
|
|
|
|
std::tie(chat_id, file_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageDocument>(as_input_file_id(file_id), nullptr,
|
|
|
|
as_caption("")));
|
2018-06-01 02:05:46 +02:00
|
|
|
} else if (op == "sdurl") {
|
|
|
|
string chat_id;
|
|
|
|
string url;
|
|
|
|
std::tie(chat_id, url) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id,
|
|
|
|
td_api::make_object<td_api::inputMessageDocument>(as_remote_file(url), nullptr, as_caption("")));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sg") {
|
|
|
|
string chat_id;
|
|
|
|
string bot_user_id;
|
|
|
|
string game_short_name;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(bot_user_id, game_short_name) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageGame>(as_user_id(bot_user_id), game_short_name));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sl") {
|
|
|
|
string chat_id;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
|
|
|
|
string latitude;
|
|
|
|
string longitude;
|
|
|
|
std::tie(latitude, longitude) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageLocation>(as_location(latitude, longitude), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sll") {
|
|
|
|
string chat_id;
|
|
|
|
string period;
|
|
|
|
string latitude;
|
|
|
|
string longitude;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(period, args) = split(args);
|
|
|
|
std::tie(latitude, longitude) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageLocation>(as_location(latitude, longitude),
|
|
|
|
to_integer<int32>(period)));
|
2019-02-19 14:45:32 +01:00
|
|
|
} else if (op == "spoll") {
|
|
|
|
string chat_id;
|
|
|
|
string question;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(question, args) = split(args);
|
|
|
|
auto answers = full_split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePoll>(question, std::move(answers)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sp") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
string sticker_file_ids_str;
|
|
|
|
vector<int32> sticker_file_ids;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(sticker_file_ids_str, photo_path) = split(args);
|
|
|
|
if (trim(photo_path).empty()) {
|
|
|
|
photo_path = sticker_file_ids_str;
|
|
|
|
} else {
|
|
|
|
sticker_file_ids = to_integers<int32>(sticker_file_ids_str, ',');
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:06:54 +01:00
|
|
|
send_message(chat_id,
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::inputMessagePhoto>(
|
|
|
|
as_input_file(photo_path), nullptr, std::move(sticker_file_ids), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spttl") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
std::tie(chat_id, photo_path) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(as_input_file(photo_path), nullptr, Auto(),
|
|
|
|
0, 0, as_caption(""), 10));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spg") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
string conversion;
|
2019-01-01 17:26:36 +01:00
|
|
|
string expected_size;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::tie(chat_id, args) = split(args);
|
2019-01-01 17:26:36 +01:00
|
|
|
std::tie(photo_path, args) = split(args);
|
|
|
|
std::tie(conversion, expected_size) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
|
2019-01-01 17:26:36 +01:00
|
|
|
as_generated_file(photo_path, conversion, to_integer<int32>(expected_size)), nullptr,
|
|
|
|
vector<int32>(), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spt") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
string thumbnail_path;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(photo_path, thumbnail_path) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(photo_path), as_input_thumbnail(as_local_file(thumbnail_path), 90, 89),
|
2018-01-30 18:06:54 +01:00
|
|
|
vector<int32>(), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sptg") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
string thumbnail_path;
|
|
|
|
string thumbnail_conversion;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(photo_path, args) = split(args);
|
|
|
|
std::tie(thumbnail_path, thumbnail_conversion) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(photo_path),
|
2018-06-01 00:22:27 +02:00
|
|
|
as_input_thumbnail(as_generated_file(thumbnail_path, thumbnail_conversion), 90, 89),
|
2018-01-30 18:06:54 +01:00
|
|
|
vector<int32>(), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spgtg") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
string conversion;
|
|
|
|
string thumbnail_path;
|
|
|
|
string thumbnail_conversion;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(photo_path, args) = split(args);
|
|
|
|
std::tie(conversion, args) = split(args);
|
|
|
|
std::tie(thumbnail_path, thumbnail_conversion) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
|
2018-12-31 20:04:05 +01:00
|
|
|
as_generated_file(photo_path, conversion),
|
2018-06-01 00:22:27 +02:00
|
|
|
as_input_thumbnail(as_generated_file(thumbnail_path, thumbnail_conversion), 90, 89),
|
2018-01-30 18:06:54 +01:00
|
|
|
vector<int32>(), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spid") {
|
|
|
|
string chat_id;
|
|
|
|
string file_id;
|
|
|
|
std::tie(chat_id, file_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(as_input_file_id(file_id), nullptr,
|
|
|
|
vector<int32>(), 0, 0, as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ss") {
|
|
|
|
string chat_id;
|
|
|
|
string sticker_path;
|
|
|
|
std::tie(chat_id, sticker_path) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id,
|
|
|
|
td_api::make_object<td_api::inputMessageSticker>(as_input_file(sticker_path), nullptr, 0, 0));
|
2018-06-01 00:22:27 +02:00
|
|
|
} else if (op == "sstt") {
|
|
|
|
string chat_id;
|
|
|
|
string sticker_path;
|
|
|
|
string thumbnail_path;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(sticker_path, thumbnail_path) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(
|
2019-02-10 01:03:54 +01:00
|
|
|
as_input_file(sticker_path), as_input_thumbnail(as_local_file(thumbnail_path)), 0, 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ssid") {
|
|
|
|
string chat_id;
|
|
|
|
string file_id;
|
|
|
|
std::tie(chat_id, file_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(as_input_file_id(file_id), nullptr, 0, 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sv") {
|
|
|
|
string chat_id;
|
|
|
|
string video_path;
|
|
|
|
string sticker_file_ids_str;
|
|
|
|
vector<int32> sticker_file_ids;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(sticker_file_ids_str, video_path) = split(args);
|
|
|
|
if (trim(video_path).empty()) {
|
|
|
|
video_path = sticker_file_ids_str;
|
|
|
|
} else {
|
|
|
|
sticker_file_ids = to_integers<int32>(sticker_file_ids_str, ',');
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageVideo>(as_input_file(video_path), nullptr,
|
|
|
|
std::move(sticker_file_ids), 1, 2, 3, true,
|
|
|
|
as_caption(""), 0));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "svn") {
|
|
|
|
string chat_id;
|
|
|
|
string video_path;
|
|
|
|
std::tie(chat_id, video_path) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id,
|
|
|
|
td_api::make_object<td_api::inputMessageVideoNote>(as_input_file(video_path), nullptr, 1, 5));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "svenue") {
|
|
|
|
string chat_id;
|
|
|
|
|
|
|
|
string latitude;
|
|
|
|
string longitude;
|
|
|
|
string title;
|
|
|
|
string address;
|
|
|
|
string provider;
|
|
|
|
string venue_id;
|
2018-04-09 20:06:37 +02:00
|
|
|
string venue_type;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(latitude, args) = split(args);
|
|
|
|
std::tie(longitude, args) = split(args);
|
|
|
|
std::tie(title, args) = split(args);
|
|
|
|
std::tie(address, args) = split(args);
|
2018-04-09 20:06:37 +02:00
|
|
|
std::tie(provider, args) = split(args);
|
|
|
|
std::tie(venue_id, venue_type) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_message(chat_id, td_api::make_object<td_api::inputMessageVenue>(td_api::make_object<td_api::venue>(
|
2018-04-09 20:06:37 +02:00
|
|
|
as_location(latitude, longitude), title, address, provider, venue_id, venue_type)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "test") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::testNetwork>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "alarm") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setAlarm>(to_double(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "delete") {
|
|
|
|
string chat_id;
|
|
|
|
string remove_from_the_chat_list;
|
|
|
|
std::tie(chat_id, remove_from_the_chat_list) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::deleteChatHistory>(as_chat_id(chat_id), as_bool(remove_from_the_chat_list)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dmfu") {
|
|
|
|
string chat_id;
|
|
|
|
string user_id;
|
|
|
|
std::tie(chat_id, user_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteChatMessagesFromUser>(as_chat_id(chat_id), as_user_id(user_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cnbgc") {
|
|
|
|
string user_ids_string;
|
|
|
|
string title;
|
|
|
|
std::tie(user_ids_string, title) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createNewBasicGroupChat>(as_user_ids(user_ids_string, ','), title));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cnch") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, true, "Description"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cnsg") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createNewSupergroupChat>(args, false, "Description"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "UpgradeBasicGroupChatToSupergroupChat") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::upgradeBasicGroupChatToSupergroupChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "DeleteSupergroup") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteSupergroup>(as_supergroup_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcpc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getCreatedPublicChats>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cpc") {
|
2018-01-23 22:45:26 +01:00
|
|
|
string user_id;
|
|
|
|
string force;
|
|
|
|
|
|
|
|
std::tie(user_id, force) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createPrivateChat>(as_user_id(user_id), as_bool(force)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "cbgc") {
|
2018-01-23 22:45:26 +01:00
|
|
|
string basic_group_id;
|
|
|
|
string force;
|
|
|
|
|
|
|
|
std::tie(basic_group_id, force) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(
|
|
|
|
td_api::make_object<td_api::createBasicGroupChat>(as_basic_group_id(basic_group_id), as_bool(force)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "csgc" || op == "cchc") {
|
2018-01-23 22:45:26 +01:00
|
|
|
string supergroup_id;
|
|
|
|
string force;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, force) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::createSupergroupChat>(as_supergroup_id(supergroup_id), as_bool(force)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sct") {
|
|
|
|
string chat_id;
|
|
|
|
string title;
|
|
|
|
|
|
|
|
std::tie(chat_id, title) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatTitle>(as_chat_id(chat_id), title));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scp") {
|
|
|
|
string chat_id;
|
|
|
|
string photo_path;
|
|
|
|
|
|
|
|
std::tie(chat_id, photo_path) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatPhoto>(as_chat_id(chat_id), as_input_file(photo_path)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "scpid") {
|
|
|
|
string chat_id;
|
|
|
|
string file_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, file_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatPhoto>(as_chat_id(chat_id), as_input_file_id(file_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sccd") {
|
|
|
|
string chat_id;
|
|
|
|
string client_data;
|
|
|
|
|
|
|
|
std::tie(chat_id, client_data) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatClientData>(as_chat_id(chat_id), client_data));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "acm") {
|
|
|
|
string chat_id;
|
|
|
|
string user_id;
|
|
|
|
string forward_limit;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(user_id, forward_limit) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addChatMember>(as_chat_id(chat_id), as_user_id(user_id),
|
|
|
|
to_integer<int32>(forward_limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "acms") {
|
|
|
|
string chat_id;
|
|
|
|
string user_ids;
|
|
|
|
|
|
|
|
std::tie(chat_id, user_ids) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addChatMembers>(as_chat_id(chat_id), as_user_ids(user_ids, ',')));
|
2019-02-21 13:23:05 +01:00
|
|
|
} else if (op == "spolla") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
string option_ids;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(message_id, option_ids) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setPollAnswer>(as_chat_id(chat_id), as_message_id(message_id),
|
|
|
|
to_integers<int32>(option_ids)));
|
2019-02-22 16:09:55 +01:00
|
|
|
} else if (op == "stoppoll") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
|
|
|
send_request(td_api::make_object<td_api::stopPoll>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
op_not_found_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op == "scms") {
|
|
|
|
string chat_id;
|
|
|
|
string user_id;
|
|
|
|
string status_str;
|
|
|
|
tl_object_ptr<td_api::ChatMemberStatus> status;
|
|
|
|
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(user_id, status_str) = split(args);
|
2018-03-20 13:18:16 +01:00
|
|
|
if (status_str == "member") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusMember>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "left") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusLeft>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "banned") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusBanned>(std::numeric_limits<int32>::max());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "creator") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusCreator>(true);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "uncreator") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusCreator>(false);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "admin") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(true, true, true, true, true, true, true,
|
|
|
|
true, true);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "unadmin") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(true, false, false, false, false, false,
|
|
|
|
false, false, false);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "rest") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
|
|
|
|
true, static_cast<int32>(120 + std::time(nullptr)), false, false, false, false);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "restkick") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
|
|
|
|
false, static_cast<int32>(120 + std::time(nullptr)), true, false, false, false);
|
2019-01-01 22:14:03 +01:00
|
|
|
} else if (status_str == "restunkick") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
|
|
|
|
true, static_cast<int32>(120 + std::time(nullptr)), true, false, false, false);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (status_str == "unrest") {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusRestricted>(true, 0, true, true, true, true);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
if (status != nullptr) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), as_user_id(user_id),
|
|
|
|
std::move(status)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknown status \"" << status_str << "\"";
|
|
|
|
}
|
|
|
|
} else if (op == "log") {
|
|
|
|
string chat_id;
|
|
|
|
string limit;
|
|
|
|
|
|
|
|
std::tie(chat_id, limit) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatEventLog>(as_chat_id(chat_id), "", 0, to_integer<int32>(limit),
|
|
|
|
nullptr, vector<int32>()));
|
2018-08-16 19:09:23 +02:00
|
|
|
} else if (op == "join") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::joinChat>(as_chat_id(args)));
|
2018-08-16 19:09:23 +02:00
|
|
|
} else if (op == "leave") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::leaveChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dcm") {
|
|
|
|
string chat_id;
|
2018-06-15 21:52:52 +02:00
|
|
|
string user_id_str;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-06-15 21:52:52 +02:00
|
|
|
std::tie(chat_id, user_id_str) = split(args);
|
|
|
|
auto user_id = as_user_id(user_id_str);
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::object_ptr<td_api::ChatMemberStatus> status = td_api::make_object<td_api::chatMemberStatusBanned>();
|
2018-06-15 21:52:52 +02:00
|
|
|
if (user_id == my_id_) {
|
2019-02-21 17:48:05 +01:00
|
|
|
status = td_api::make_object<td_api::chatMemberStatusLeft>();
|
2018-06-15 21:52:52 +02:00
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatMemberStatus>(as_chat_id(chat_id), user_id, std::move(status)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sn") {
|
|
|
|
string first_name;
|
|
|
|
string last_name;
|
|
|
|
std::tie(first_name, last_name) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setName>(first_name, last_name));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sb") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setBio>("\n" + args + "\n" + args + "\n"));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sun") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setUsername>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "tbga") {
|
|
|
|
string group_id;
|
|
|
|
string everyone_is_administrator;
|
|
|
|
|
|
|
|
std::tie(group_id, everyone_is_administrator) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleBasicGroupAdministrators>(as_basic_group_id(group_id),
|
|
|
|
as_bool(everyone_is_administrator)));
|
2018-03-02 00:19:00 +01:00
|
|
|
} else if (op == "ccun") {
|
|
|
|
string chat_id;
|
|
|
|
string username;
|
|
|
|
|
|
|
|
std::tie(chat_id, username) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::checkChatUsername>(as_chat_id(chat_id), username));
|
2018-03-02 00:19:00 +01:00
|
|
|
} else if (op == "ssgun" || op == "schun") {
|
2018-12-31 20:04:05 +01:00
|
|
|
string supergroup_id;
|
|
|
|
string username;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, username) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setSupergroupUsername>(as_supergroup_id(supergroup_id), username));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ssgss") {
|
|
|
|
string supergroup_id;
|
|
|
|
string sticker_set_id;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, sticker_set_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setSupergroupStickerSet>(as_supergroup_id(supergroup_id),
|
|
|
|
to_integer<int64>(sticker_set_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "tsgi") {
|
|
|
|
string supergroup_id;
|
|
|
|
string anyone_can_invite;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, anyone_can_invite) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleSupergroupInvites>(as_supergroup_id(supergroup_id),
|
|
|
|
as_bool(anyone_can_invite)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "tsgp") {
|
|
|
|
string supergroup_id;
|
|
|
|
string is_all_history_available;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, is_all_history_available) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleSupergroupIsAllHistoryAvailable>(
|
|
|
|
as_supergroup_id(supergroup_id), as_bool(is_all_history_available)));
|
2018-03-27 16:55:33 +02:00
|
|
|
} else if (op == "tsgsm") {
|
|
|
|
string supergroup_id;
|
|
|
|
string sign_messages;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, sign_messages) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::toggleSupergroupSignMessages>(as_supergroup_id(supergroup_id),
|
|
|
|
as_bool(sign_messages)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "csgd" || op == "cchd") {
|
|
|
|
string supergroup_id;
|
|
|
|
string description;
|
|
|
|
|
|
|
|
std::tie(supergroup_id, description) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setSupergroupDescription>(as_supergroup_id(supergroup_id), description));
|
2019-02-01 13:19:32 +01:00
|
|
|
} else if (op == "pcm" || op == "pcms") {
|
|
|
|
string chat_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
string message_id;
|
|
|
|
|
2019-02-01 13:19:32 +01:00
|
|
|
std::tie(chat_id, message_id) = split(args);
|
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::pinChatMessage>(as_chat_id(chat_id), as_message_id(message_id), op == "pcms"));
|
2019-02-01 13:19:32 +01:00
|
|
|
} else if (op == "upcm") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::unpinChatMessage>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "grib") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getRecentInlineBots>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spc" || op == "su" || op == "sch") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchPublicChat>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spcs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchPublicChats>(args));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sc") {
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
std::tie(limit, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChats>(query, to_integer<int32>(limit)));
|
2018-01-16 19:56:59 +01:00
|
|
|
} else if (op == "scos") {
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
std::tie(limit, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchChatsOnServer>(query, to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sco") {
|
|
|
|
string limit;
|
|
|
|
string query;
|
|
|
|
std::tie(limit, query) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchContacts>(query, to_integer<int32>(limit)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "arfc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addRecentlyFoundChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rrfc") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeRecentlyFoundChat>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "crfcs") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::clearRecentlyFoundChats>());
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gwpp") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getWebPagePreview>(as_caption(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gwpiv") {
|
|
|
|
string url;
|
|
|
|
string force_full;
|
|
|
|
std::tie(url, force_full) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getWebPageInstantView>(url, as_bool(force_full)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "spp") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setProfilePhoto>(as_input_file(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sppg") {
|
|
|
|
string path;
|
|
|
|
string conversion;
|
|
|
|
std::tie(path, conversion) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setProfilePhoto>(as_generated_file(path, conversion)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "sh") {
|
|
|
|
auto prefix = std::move(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::searchHashtags>(prefix, 10));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rrh") {
|
|
|
|
auto hashtag = std::move(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeRecentHashtag>(hashtag));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "view") {
|
|
|
|
string chat_id;
|
2018-03-02 17:21:43 +01:00
|
|
|
string message_ids;
|
|
|
|
std::tie(chat_id, message_ids) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::viewMessages>(as_chat_id(chat_id), as_message_ids(message_ids), true));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "omc") {
|
|
|
|
string chat_id;
|
|
|
|
string message_id;
|
|
|
|
std::tie(chat_id, message_id) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::openMessageContent>(as_chat_id(chat_id), as_message_id(message_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "racm") {
|
|
|
|
string chat_id = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::readAllChatMentions>(as_chat_id(chat_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "dpp") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::deleteProfilePhoto>(to_integer<int64>(args)));
|
2019-02-14 19:44:20 +01:00
|
|
|
} else if (op == "gcnse" || op == "gcnses") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatNotificationSettingsExceptions>(
|
|
|
|
get_notification_settings_scope(args), op == "gcnses"));
|
2018-04-09 18:30:27 +02:00
|
|
|
} else if (op == "gsns") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getScopeNotificationSettings>(get_notification_settings_scope(args)));
|
2019-01-10 18:54:46 +01:00
|
|
|
} else if (op == "scns" || op == "ssns") {
|
|
|
|
string chat_id_or_scope;
|
2018-12-31 20:04:05 +01:00
|
|
|
string settings;
|
|
|
|
|
2019-01-10 18:54:46 +01:00
|
|
|
std::tie(chat_id_or_scope, settings) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
string mute_for;
|
|
|
|
string sound;
|
2019-01-08 20:48:43 +01:00
|
|
|
string show_preview;
|
2019-01-10 18:54:46 +01:00
|
|
|
string disable_pinned_message_notifications;
|
|
|
|
string disable_mention_notifications;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
std::tie(mute_for, settings) = split(settings, ',');
|
2019-01-10 01:47:33 +01:00
|
|
|
std::tie(sound, settings) = split(settings, ',');
|
2019-01-10 18:54:46 +01:00
|
|
|
std::tie(show_preview, settings) = split(settings, ',');
|
|
|
|
std::tie(disable_pinned_message_notifications, disable_mention_notifications) = split(settings, ',');
|
|
|
|
|
|
|
|
if (op == "scns") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setChatNotificationSettings>(
|
2019-01-10 18:54:46 +01:00
|
|
|
as_chat_id(chat_id_or_scope),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::chatNotificationSettings>(
|
2019-01-10 18:54:46 +01:00
|
|
|
mute_for.empty(), to_integer<int32>(mute_for), sound.empty(), sound, show_preview.empty(),
|
|
|
|
as_bool(show_preview), disable_pinned_message_notifications.empty(),
|
|
|
|
as_bool(disable_pinned_message_notifications), disable_mention_notifications.empty(),
|
|
|
|
as_bool(disable_mention_notifications))));
|
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setScopeNotificationSettings>(
|
2019-01-10 18:54:46 +01:00
|
|
|
get_notification_settings_scope(chat_id_or_scope),
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::scopeNotificationSettings>(
|
|
|
|
to_integer<int32>(mute_for), sound, as_bool(show_preview),
|
|
|
|
as_bool(disable_pinned_message_notifications), as_bool(disable_mention_notifications))));
|
2019-01-10 18:54:46 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rans") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::resetAllNotificationSettings>());
|
2018-11-09 15:14:02 +01:00
|
|
|
} else if (op == "rn") {
|
2018-11-16 16:00:46 +01:00
|
|
|
string group_id;
|
2018-12-04 00:25:29 +01:00
|
|
|
string notification_ids;
|
|
|
|
std::tie(group_id, notification_ids) = split(args);
|
|
|
|
char delimiter = notification_ids.find(',') != string::npos ? ',' : ' ';
|
|
|
|
for (auto notification_id : to_integers<int32>(notification_ids, delimiter)) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeNotification>(to_integer<int32>(group_id), notification_id));
|
2018-12-04 00:25:29 +01:00
|
|
|
}
|
2018-11-09 23:56:00 +01:00
|
|
|
} else if (op == "rng") {
|
2018-11-09 15:14:02 +01:00
|
|
|
string group_id;
|
|
|
|
string max_notification_id;
|
|
|
|
std::tie(group_id, max_notification_id) = split(args);
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeNotificationGroup>(to_integer<int32>(group_id),
|
|
|
|
to_integer<int32>(max_notification_id)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gcrss") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getChatReportSpamState>(as_chat_id(args)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "ccrss") {
|
|
|
|
string chat_id;
|
|
|
|
string is_spam_chat;
|
|
|
|
std::tie(chat_id, is_spam_chat) = split(args);
|
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::changeChatReportSpamState>(as_chat_id(chat_id), as_bool(is_spam_chat)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rc") {
|
|
|
|
string chat_id;
|
|
|
|
string reason_str;
|
2018-03-02 17:21:43 +01:00
|
|
|
string message_ids;
|
|
|
|
std::tie(chat_id, args) = split(args);
|
|
|
|
std::tie(reason_str, message_ids) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
tl_object_ptr<td_api::ChatReportReason> reason;
|
|
|
|
if (reason_str == "spam") {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonSpam>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (reason_str == "violence") {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonViolence>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (reason_str == "porno") {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonPornography>();
|
2018-12-07 15:20:44 +01:00
|
|
|
} else if (reason_str == "ca") {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonChildAbuse>();
|
2018-07-17 05:46:27 +02:00
|
|
|
} else if (reason_str == "copyright") {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonCopyright>();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
reason = td_api::make_object<td_api::chatReportReasonCustom>(reason_str);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 17:21:43 +01:00
|
|
|
send_request(
|
2019-02-21 17:48:05 +01:00
|
|
|
td_api::make_object<td_api::reportChat>(as_chat_id(chat_id), std::move(reason), as_message_ids(message_ids)));
|
2019-02-26 21:37:59 +01:00
|
|
|
} else if (op == "gcsu") {
|
|
|
|
string chat_id;
|
|
|
|
string parameters;
|
|
|
|
std::tie(chat_id, parameters) = split(args);
|
|
|
|
|
|
|
|
send_request(td_api::make_object<td_api::getChatStatisticsUrl>(as_chat_id(args), parameters));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "rsgs" || op == "rchs") {
|
|
|
|
string supergroup_id;
|
|
|
|
string user_id;
|
2018-03-02 17:21:43 +01:00
|
|
|
string message_ids;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::tie(supergroup_id, args) = split(args);
|
2018-03-02 17:21:43 +01:00
|
|
|
std::tie(user_id, message_ids) = split(args);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::reportSupergroupSpam>(as_supergroup_id(supergroup_id),
|
|
|
|
as_user_id(user_id), as_message_ids(message_ids)));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "gdiff") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::testGetDifference>());
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "dproxy") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::disableProxy>());
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "eproxy") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::enableProxy>(as_proxy_id(args)));
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "rproxy") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::removeProxy>(as_proxy_id(args)));
|
2018-07-27 17:10:45 +02:00
|
|
|
} else if (op == "aproxy" || op == "aeproxy" || op == "aeproxytcp" || op == "editproxy" || op == "editeproxy" ||
|
|
|
|
op == "editeproxytcp") {
|
|
|
|
string proxy_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
string server;
|
|
|
|
string port;
|
2018-02-28 21:25:42 +01:00
|
|
|
string user;
|
|
|
|
string password;
|
2018-07-27 17:10:45 +02:00
|
|
|
if (op[0] == 'e') {
|
|
|
|
std::tie(proxy_id, args) = split(args);
|
|
|
|
}
|
2018-02-28 21:25:42 +01:00
|
|
|
std::tie(server, args) = split(args);
|
|
|
|
std::tie(port, args) = split(args);
|
|
|
|
std::tie(user, password) = split(args);
|
2018-07-27 17:10:45 +02:00
|
|
|
bool enable = op != "aproxy" && op != "editproxy";
|
2018-05-14 21:00:38 +02:00
|
|
|
td_api::object_ptr<td_api::ProxyType> type;
|
2018-05-08 16:48:30 +02:00
|
|
|
if (!user.empty() && password.empty()) {
|
2019-02-21 17:48:05 +01:00
|
|
|
type = td_api::make_object<td_api::proxyTypeMtproto>(user);
|
2018-05-08 16:48:30 +02:00
|
|
|
} else {
|
2018-09-26 02:54:37 +02:00
|
|
|
if (port == "80" || port == "8080") {
|
2019-02-21 17:48:05 +01:00
|
|
|
type = td_api::make_object<td_api::proxyTypeHttp>(user, password, op.back() != 'p');
|
2018-07-26 15:49:18 +02:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
type = td_api::make_object<td_api::proxyTypeSocks5>(user, password);
|
2018-07-26 15:49:18 +02:00
|
|
|
}
|
2018-05-08 16:48:30 +02:00
|
|
|
}
|
2018-07-27 17:10:45 +02:00
|
|
|
if (op[0] == 'e') {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), server, to_integer<int32>(port),
|
|
|
|
enable, std::move(type)));
|
2018-07-27 17:10:45 +02:00
|
|
|
} else {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::addProxy>(server, to_integer<int32>(port), enable, std::move(type)));
|
2018-07-27 17:10:45 +02:00
|
|
|
}
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "gproxy" || op == "gproxies") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getProxies>());
|
2018-05-17 20:08:51 +02:00
|
|
|
} else if (op == "gproxyl" || op == "gpl") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::getProxyLink>(as_proxy_id(args)));
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "pproxy") {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::pingProxy>(as_proxy_id(args)));
|
2018-04-27 19:41:10 +02:00
|
|
|
} else if (op == "touch") {
|
|
|
|
auto r_fd = FileFd::open(args, FileFd::Read | FileFd::Write);
|
|
|
|
if (r_fd.is_error()) {
|
|
|
|
LOG(ERROR) << r_fd.error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fd = r_fd.move_as_ok();
|
|
|
|
auto size = fd.get_size();
|
2018-05-15 12:01:15 +02:00
|
|
|
fd.seek(size).ignore();
|
2018-04-27 19:41:10 +02:00
|
|
|
fd.write("a").ignore();
|
|
|
|
fd.seek(size).ignore();
|
|
|
|
fd.truncate_to_current_position(size).ignore();
|
2018-05-14 21:00:38 +02:00
|
|
|
} else if (op == "SetVerbosity" || op == "SV") {
|
2018-03-09 01:27:39 +01:00
|
|
|
td::Log::set_verbosity_level(to_integer<int>(args));
|
2018-06-19 01:31:34 +02:00
|
|
|
} else if (op[0] == 'v' && op[1] == 'v') {
|
|
|
|
td::Log::set_verbosity_level(static_cast<int>(op.size()));
|
|
|
|
} else if (op[0] == 'v' && ('0' <= op[1] && op[1] <= '9')) {
|
|
|
|
td::Log::set_verbosity_level(to_integer<int>(op.substr(1)));
|
2018-10-24 17:42:40 +02:00
|
|
|
} else if (op == "slse") {
|
|
|
|
execute(td_api::make_object<td_api::setLogStream>(td_api::make_object<td_api::logStreamEmpty>()));
|
|
|
|
} else if (op == "slsd") {
|
|
|
|
execute(td_api::make_object<td_api::setLogStream>(td_api::make_object<td_api::logStreamDefault>()));
|
|
|
|
} else if (op == "gls") {
|
|
|
|
execute(td_api::make_object<td_api::getLogStream>());
|
|
|
|
} else if (op == "slvl") {
|
|
|
|
execute(td_api::make_object<td_api::setLogVerbosityLevel>(to_integer<int32>(args)));
|
|
|
|
} else if (op == "glvl") {
|
|
|
|
execute(td_api::make_object<td_api::getLogVerbosityLevel>());
|
|
|
|
} else if (op == "gtags" || op == "glt") {
|
|
|
|
execute(td_api::make_object<td_api::getLogTags>());
|
2018-09-26 02:54:37 +02:00
|
|
|
} else if (op == "sltvl" || op == "sltvle" || op == "tag") {
|
2018-09-26 01:59:29 +02:00
|
|
|
string tag;
|
|
|
|
string level;
|
|
|
|
std::tie(tag, level) = split(args);
|
2018-10-24 17:42:40 +02:00
|
|
|
auto request = td_api::make_object<td_api::setLogTagVerbosityLevel>(tag, to_integer<int32>(level));
|
2018-09-26 01:59:29 +02:00
|
|
|
if (op == "sltvl") {
|
|
|
|
send_request(std::move(request));
|
|
|
|
} else {
|
|
|
|
execute(std::move(request));
|
|
|
|
}
|
2018-10-24 17:42:40 +02:00
|
|
|
} else if (op == "gltvl" || op == "gltvle" || op == "gtag") {
|
|
|
|
string tag = args;
|
2019-02-21 17:48:05 +01:00
|
|
|
auto request = td_api::make_object<td_api::getLogTagVerbosityLevel>(tag);
|
2018-10-24 17:42:40 +02:00
|
|
|
if (op == "gltvl") {
|
|
|
|
send_request(std::move(request));
|
|
|
|
} else {
|
|
|
|
execute(std::move(request));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (op == "q" || op == "Quit") {
|
|
|
|
quit();
|
|
|
|
} else if (op == "dnq" || op == "DumpNetQueries") {
|
|
|
|
dump_pending_network_queries();
|
2018-01-24 16:45:57 +01:00
|
|
|
} else if (op == "fatal") {
|
|
|
|
LOG(FATAL) << "Fatal!";
|
|
|
|
} else if (op == "unreachable") {
|
|
|
|
UNREACHABLE();
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
op_not_found_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op_not_found_count == OP_BLOCK_COUNT && !cmd.empty()) {
|
|
|
|
LOG(ERROR) << "Unknown command \"" << cmd << "\" of length " << cmd.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inited_ = false;
|
|
|
|
void loop() override {
|
|
|
|
if (!inited_) {
|
|
|
|
inited_ = true;
|
|
|
|
init();
|
|
|
|
}
|
2018-09-10 17:09:08 +02:00
|
|
|
stdin_.flush_read().ensure();
|
2018-12-31 20:04:05 +01:00
|
|
|
#ifdef USE_READLINE
|
2018-09-10 17:09:08 +02:00
|
|
|
while (!stdin_.input_buffer().empty()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
rl_callback_read_char();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
while (true) {
|
|
|
|
auto cmd = process_stdin(&stdin_.input_buffer());
|
|
|
|
if (cmd.is_error()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
add_cmd(cmd.ok().as_slice().str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (!cmd_queue_.empty() && !close_flag_) {
|
|
|
|
auto cmd = std::move(cmd_queue_.front());
|
|
|
|
cmd_queue_.pop();
|
|
|
|
on_cmd(std::move(cmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ready_to_stop_ && close_flag_ && is_stdin_reader_stopped_) {
|
|
|
|
#ifdef USE_READLINE
|
|
|
|
rl_callback_handler_remove();
|
|
|
|
#endif
|
|
|
|
Scheduler::instance()->finish();
|
|
|
|
LOG(WARNING) << "STOP";
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void timeout_expired() override {
|
2018-01-05 15:45:17 +01:00
|
|
|
if (close_flag_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
for (auto it = pending_file_generations_.begin(); it != pending_file_generations_.end();) {
|
2018-12-31 20:04:05 +01:00
|
|
|
auto left_size = it->size - it->local_size;
|
|
|
|
CHECK(left_size > 0);
|
|
|
|
if (it->part_size > left_size) {
|
|
|
|
it->part_size = left_size;
|
|
|
|
}
|
|
|
|
BufferSlice block(it->part_size);
|
|
|
|
FileFd::open(it->source, FileFd::Flags::Read).move_as_ok().pread(block.as_slice(), it->local_size).ensure();
|
|
|
|
auto open_flags = FileFd::Flags::Write | (it->local_size ? 1 : FileFd::Flags::Truncate | FileFd::Flags::Create);
|
|
|
|
FileFd::open(it->destination, open_flags).move_as_ok().pwrite(block.as_slice(), it->local_size).ensure();
|
|
|
|
it->local_size += it->part_size;
|
|
|
|
if (it->local_size == it->size) {
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setFileGenerationProgress>(it->id, it->size, it->size));
|
|
|
|
send_request(td_api::make_object<td_api::finishFileGeneration>(it->id, nullptr));
|
2018-06-01 01:12:36 +02:00
|
|
|
it = pending_file_generations_.erase(it);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2018-11-21 11:56:14 +01:00
|
|
|
auto local_size = it->local_size;
|
|
|
|
if (it->test_local_size_decrease && local_size > it->size / 2) {
|
|
|
|
local_size = local_size * 2 - it->size;
|
|
|
|
}
|
2019-02-21 17:48:05 +01:00
|
|
|
send_request(td_api::make_object<td_api::setFileGenerationProgress>(it->id, (it->size + 3 * it->local_size) / 4,
|
|
|
|
local_size));
|
2018-12-31 20:04:05 +01:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
if (!pending_file_generations_.empty()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
set_timeout_in(0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 09:31:05 +02:00
|
|
|
void notify() override {
|
|
|
|
auto guard = scheduler_->get_send_guard();
|
|
|
|
send_event_later(actor_id(), Event::yield());
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void hangup_shared() override {
|
|
|
|
CHECK(get_link_token() == 1);
|
|
|
|
LOG(INFO) << "StdinReader stopped";
|
|
|
|
is_stdin_reader_stopped_ = true;
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_cmd(string cmd) {
|
|
|
|
cmd_queue_.push(std::move(cmd));
|
|
|
|
}
|
2018-09-10 17:09:08 +02:00
|
|
|
int stdin_getc() {
|
|
|
|
auto slice = stdin_.input_buffer().prepare_read();
|
|
|
|
if (slice.empty()) {
|
2018-09-10 20:45:34 +02:00
|
|
|
return EOF;
|
2018-09-10 17:09:08 +02:00
|
|
|
}
|
|
|
|
int res = slice[0];
|
|
|
|
stdin_.input_buffer().confirm_read(1);
|
|
|
|
return res;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-06-01 01:12:36 +02:00
|
|
|
std::unordered_map<int32, double> being_downloaded_files_;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 my_id_ = 0;
|
|
|
|
|
2018-09-11 12:37:44 +02:00
|
|
|
ConcurrentScheduler *scheduler_{nullptr};
|
2018-09-11 09:31:05 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool use_test_dc_ = false;
|
2018-10-28 18:30:47 +01:00
|
|
|
ActorOwn<ClientActor> td_client_;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::queue<string> cmd_queue_;
|
|
|
|
bool close_flag_ = false;
|
|
|
|
bool ready_to_stop_ = false;
|
|
|
|
bool is_stdin_reader_stopped_ = false;
|
|
|
|
|
|
|
|
bool get_chat_list_ = false;
|
|
|
|
bool disable_network_ = false;
|
|
|
|
int api_id_ = 0;
|
|
|
|
std::string api_hash_;
|
|
|
|
};
|
|
|
|
CliClient *CliClient::instance_ = nullptr;
|
|
|
|
|
2018-01-24 17:11:39 +01:00
|
|
|
void quit() {
|
2018-12-31 20:04:05 +01:00
|
|
|
CliClient::quit_instance();
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void fail_signal(int sig) {
|
2018-12-31 20:04:05 +01:00
|
|
|
signal_safe_write_signal_number(sig);
|
|
|
|
while (true) {
|
|
|
|
// spin forever to allow debugger to attach
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void usage() {
|
2018-12-31 20:04:05 +01:00
|
|
|
//TODO:
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:57 +01:00
|
|
|
static void on_fatal_error(const char *error) {
|
|
|
|
std::cerr << "Fatal error: " << error << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void main(int argc, char **argv) {
|
|
|
|
ignore_signal(SignalType::HangUp).ensure();
|
|
|
|
ignore_signal(SignalType::Pipe).ensure();
|
|
|
|
set_signal_handler(SignalType::Error, fail_signal).ensure();
|
|
|
|
set_signal_handler(SignalType::Abort, fail_signal).ensure();
|
2018-01-24 16:45:57 +01:00
|
|
|
td::Log::set_fatal_error_callback(on_fatal_error);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-02-09 22:52:03 +01:00
|
|
|
const char *locale_name = (std::setlocale(LC_ALL, "fr-FR") == nullptr ? "" : "fr-FR");
|
|
|
|
std::locale new_locale(locale_name);
|
|
|
|
std::locale::global(new_locale);
|
2018-02-09 18:02:01 +01:00
|
|
|
SCOPE_EXIT {
|
|
|
|
std::locale::global(std::locale::classic());
|
2018-10-08 14:59:14 +02:00
|
|
|
static NullLog null_log;
|
|
|
|
log_interface = &null_log;
|
2018-02-09 18:02:01 +01:00
|
|
|
};
|
2018-02-03 20:40:06 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
CliLog cli_log;
|
|
|
|
log_interface = &cli_log;
|
|
|
|
|
|
|
|
td::FileLog file_log;
|
|
|
|
td::TsLog ts_log(&file_log);
|
|
|
|
|
|
|
|
int new_verbosity_level = VERBOSITY_NAME(INFO);
|
|
|
|
bool use_test_dc = false;
|
|
|
|
bool get_chat_list = false;
|
|
|
|
bool disable_network = false;
|
|
|
|
auto api_id = [](auto x) -> int32 {
|
|
|
|
if (x) {
|
|
|
|
return td::to_integer<int32>(Slice(x));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}(std::getenv("TD_API_ID"));
|
|
|
|
auto api_hash = [](auto x) -> std::string {
|
|
|
|
if (x) {
|
|
|
|
return x;
|
|
|
|
}
|
2018-09-11 12:37:44 +02:00
|
|
|
return std::string();
|
2018-12-31 20:04:05 +01:00
|
|
|
}(std::getenv("TD_API_HASH"));
|
|
|
|
// TODO port OptionsParser to Windows
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (!std::strcmp(argv[i], "--test")) {
|
|
|
|
use_test_dc = true;
|
|
|
|
} else if (!std::strncmp(argv[i], "-v", 2)) {
|
|
|
|
const char *arg = argv[i] + 2;
|
|
|
|
if (*arg == '\0' && i + 1 < argc) {
|
|
|
|
arg = argv[++i];
|
|
|
|
}
|
|
|
|
int new_verbosity = 0;
|
|
|
|
if (arg[0] == 'v') {
|
|
|
|
new_verbosity = 1;
|
|
|
|
while (arg[0] == 'v') {
|
|
|
|
new_verbosity++;
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_verbosity += to_integer<int>(Slice(arg));
|
|
|
|
new_verbosity_level = VERBOSITY_NAME(FATAL) + new_verbosity;
|
|
|
|
} else if (!std::strncmp(argv[i], "-l", 2)) {
|
|
|
|
const char *arg = argv[i] + 2;
|
|
|
|
if (*arg == '\0' && i + 1 < argc) {
|
|
|
|
arg = argv[++i];
|
|
|
|
}
|
2018-10-24 17:42:40 +02:00
|
|
|
if (file_log.init(arg).is_ok() && file_log.init(arg).is_ok() && file_log.init(arg, 1000 << 20).is_ok()) {
|
2018-01-28 15:48:11 +01:00
|
|
|
log_interface = &ts_log;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else if (!std::strcmp(argv[i], "-W")) {
|
|
|
|
get_chat_list = true;
|
|
|
|
} else if (!std::strcmp(argv[i], "--disable-network") || !std::strcmp(argv[i], "-n")) {
|
|
|
|
disable_network = true;
|
|
|
|
} else if (!std::strcmp(argv[i], "--api_id")) {
|
|
|
|
if (i + 1 >= argc) {
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
api_id = td::to_integer<int32>(Slice(argv[++i]));
|
|
|
|
} else if (!std::strcmp(argv[i], "--api_hash")) {
|
|
|
|
if (i + 1 >= argc) {
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
api_hash = argv[++i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 12:37:44 +02:00
|
|
|
if (api_id == 0 || api_hash.empty()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG(ERROR) << "You should provide some valid api_id and api_hash";
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_VERBOSITY_LEVEL(new_verbosity_level);
|
|
|
|
|
|
|
|
{
|
|
|
|
ConcurrentScheduler scheduler;
|
2018-09-11 12:37:44 +02:00
|
|
|
scheduler.init(3);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
scheduler
|
2018-09-11 12:37:44 +02:00
|
|
|
.create_actor_unsafe<CliClient>(0, "CliClient", &scheduler, use_test_dc, get_chat_list, disable_network, api_id,
|
|
|
|
api_hash)
|
2018-12-31 20:04:05 +01:00
|
|
|
.release();
|
|
|
|
|
|
|
|
scheduler.start();
|
2018-09-18 15:43:16 +02:00
|
|
|
while (scheduler.run_main(td::Timestamp::in(100))) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
scheduler.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_memory_usage();
|
|
|
|
}
|
2019-01-17 21:12:31 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
td::main(argc, argv);
|
|
|
|
}
|