From 61d9d3846faabec941bf3b730bac563b62b27652 Mon Sep 17 00:00:00 2001 From: Soo Hwan Na Date: Wed, 26 Jun 2024 14:34:49 +0900 Subject: [PATCH] TgBot++: Update tgbot-cpp submodule - Bot API revision 7.2 --- CMakeLists.txt | 8 +++---- src/BotMessageUtils.cpp | 43 +++++++++++++++++++++++++---------- src/SpamBlocker.cpp | 2 +- src/command_modules/alive.cpp | 7 +++++- src/third-party/tgbot-cpp | 2 +- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce81e01a..4908ca7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,10 @@ string(TIMESTAMP TODAY "%Y-%m-%d") configure_file(resources/about.html.in ${CMAKE_SOURCE_DIR}/resources/about.html) ##################################################################### +#################### TgBot cpp (the core) Library ################### +add_subdirectory(src/third-party/tgbot-cpp EXCLUDE_FROM_ALL) +##################################################################### + ########################## ABSEIL log deps ########################## add_subdirectory(src/third-party/googletest EXCLUDE_FROM_ALL) add_subdirectory(src/third-party/abseil-cpp EXCLUDE_FROM_ALL) @@ -383,10 +387,6 @@ target_link_libraries(TgBotUtils ${Boost_LIBRARIES} ${LIBGIT2_LIBS}) target_link_lib_if_windows(TgBotUtils shlwapi) ##################################################################### -#################### TgBot cpp (the core) Library ################### -add_subdirectory(src/third-party/tgbot-cpp EXCLUDE_FROM_ALL) -##################################################################### - ################### The Bot's main functionaility ################### add_library(${PROJECT_NAME} SHARED ${SRC_LIST}) target_include_directories(${PROJECT_NAME} PRIVATE src/third-party/rapidjson/include) diff --git a/src/BotMessageUtils.cpp b/src/BotMessageUtils.cpp index e9e0b4dd..e61d3c01 100644 --- a/src/BotMessageUtils.cpp +++ b/src/BotMessageUtils.cpp @@ -1,17 +1,35 @@ #include -static Message::Ptr _bot_sendReplyMessage(const Bot &bot, - const Message::Ptr &message, - const std::string &text, - const MessageId replyToMsg = 0, - const bool noError = false, - const std::string parsemode = "") { - return bot.getApi().sendMessage( - message->chat->id, text, true, - (replyToMsg == 0) ? message->messageId : replyToMsg, nullptr, parsemode, - false, std::vector(), noError); +#include + +#include "tgbot/types/Message.h" +#include "tgbot/types/ReplyParameters.h" + +namespace { +Message::Ptr _bot_sendReplyMessage(const Bot &bot, const Message::Ptr &message, + const std::string &text, + const MessageId replyToMsg = 0, + const bool noError = false, + const std::string &parsemode = "") { + auto params = std::make_shared(); + params->allowSendingWithoutReply = noError; + params->chatId = message->chat->id; + params->messageId = replyToMsg == 0 ? message->messageId : replyToMsg; + + return bot.getApi().sendMessage(message->chat->id, text, nullptr, params, + nullptr, parsemode); +} + +TgBot::ReplyParameters::Ptr createFromReplyMsg( + const TgBot::Message::Ptr &message) { + auto params = std::make_shared(); + params->chatId = message->chat->id; + params->messageId = message->messageId; + return params; } +} // namespace + Message::Ptr bot_sendReplyMessage(const Bot &bot, const Message::Ptr &message, const std::string &text, const MessageId replyToMsg, @@ -57,7 +75,7 @@ Message::Ptr bot_sendSticker(const Bot &bot, const ChatId &chatid, Sticker::Ptr sticker, const Message::Ptr &replyTo) { return bot.getApi().sendSticker(chatid, sticker->fileId, - replyTo->messageId); + createFromReplyMsg(replyTo)); } Message::Ptr bot_sendSticker(const Bot &bot, const ChatId &chat, @@ -68,7 +86,8 @@ Message::Ptr bot_sendSticker(const Bot &bot, const ChatId &chat, Message::Ptr bot_sendAnimation(const Bot &bot, const ChatId &chat, Animation::Ptr gif, const Message::Ptr &replyTo) { - return bot.getApi().sendSticker(chat, gif->fileId, replyTo->messageId); + return bot.getApi().sendSticker(chat, gif->fileId, + createFromReplyMsg(replyTo)); } Message::Ptr bot_sendAnimation(const Bot &bot, const ChatId &chat, diff --git a/src/SpamBlocker.cpp b/src/SpamBlocker.cpp index e47db000..9b89999f 100644 --- a/src/SpamBlocker.cpp +++ b/src/SpamBlocker.cpp @@ -156,7 +156,7 @@ void SpamBlockBase::addMessage(const Message::Ptr &message) { // We care GIF, sticker, text spams only, or if it isn't fowarded msg if ((!message->animation && message->text.empty() && !message->sticker) || - message->forwardFrom) { + message->forwardOrigin) { return; } // Bot's PM is not a concern diff --git a/src/command_modules/alive.cpp b/src/command_modules/alive.cpp index 4f57b7fb..ea3d67c9 100644 --- a/src/command_modules/alive.cpp +++ b/src/command_modules/alive.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -13,6 +14,7 @@ #include "CompileTimeStringConcat.hpp" #include "database/bot/TgBotDatabaseImpl.hpp" #include "internal/_tgbot.h" +#include "tgbot/types/ReplyParameters.h" template consteval auto cat(const char (&strings)[Len]) { @@ -50,9 +52,12 @@ static void AliveCommandFn(const Bot& bot, const Message::Ptr message) { const auto info = TgBotDatabaseImpl::getInstance()->queryMediaInfo("alive"); bool sentAnimation = false; if (info) { + auto params = std::make_shared(); + params->chatId = message->chat->id; + params->messageId = message->messageId; try { bot.getApi().sendAnimation(message->chat->id, info->mediaId, 0, 0, - 0, "", version, message->messageId, + 0, "", version, params, nullptr, "html"); sentAnimation = true; } catch (const TgBot::TgException& e) { diff --git a/src/third-party/tgbot-cpp b/src/third-party/tgbot-cpp index 6a2eb660..942372cb 160000 --- a/src/third-party/tgbot-cpp +++ b/src/third-party/tgbot-cpp @@ -1 +1 @@ -Subproject commit 6a2eb66087050756fb26c3b9bfec88760a7239f8 +Subproject commit 942372cb6e21faf2ef91bc8dc60eb08ba121baba