diff options
author | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2022-09-20 15:38:45 +0200 |
---|---|---|
committer | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2022-09-20 15:38:45 +0200 |
commit | f9e16bde59f57c3b6990c47e5082e3edeb527e4d (patch) | |
tree | 595f0ea62a5c8da7ace4eea387e37693fa70781a /src | |
parent | 930a2f0fdb4ef5ba7cadab2e493bcd24e5b44809 (diff) |
Add function to check if bot is blocked by user
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index ea9a550..875a79a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1024,17 +1024,6 @@ File::Ptr Api::getFile(const std::string& fileId) const { return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); } -std::string Api::downloadFile(const std::string& filePath, - const std::vector<HttpReqArg>& args) const { - std::string url(_url); - url += "/file/bot"; - url += _token; - url += "/"; - url += filePath; - - return _httpClient.makeRequest(url, args); -} - bool Api::banChatMember(boost::variant<std::int64_t, const std::string&> chatId, std::int64_t userId, std::int32_t untilDate, @@ -2243,6 +2232,34 @@ std::vector<GameHighScore::Ptr> Api::getGameHighScores(std::int64_t userId, return _tgTypeParser.parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); } +std::string Api::downloadFile(const std::string& filePath, + const std::vector<HttpReqArg>& args) const { + std::string url(_url); + url += "/file/bot"; + url += _token; + url += "/"; + url += filePath; + + return _httpClient.makeRequest(url, args); +} + +bool Api::blockedByUser(std::int64_t chatId) const { + bool isBotBlocked = false; + + try { + sendChatAction(chatId, "typing"); + + } catch (std::exception& e) { + std::string error = e.what(); + + if (error.compare("Forbidden: bot was blocked by the user") == 0) { + isBotBlocked = true; + } + } + + return isBotBlocked; +} + boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector<HttpReqArg>& args) const { std::string url(_url); url += "/bot"; |