Skip to content

Commit

Permalink
TgBot++: Update tgbot-cpp submodule
Browse files Browse the repository at this point in the history
- Bot API revision 7.2
  • Loading branch information
Royna2544 committed Jun 26, 2024
1 parent 8c4121a commit 61d9d38
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
43 changes: 31 additions & 12 deletions src/BotMessageUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
#include <BotReplyMessage.h>

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<MessageEntity::Ptr>(), noError);
#include <memory>

#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<TgBot::ReplyParameters>();
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<TgBot::ReplyParameters>();
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/SpamBlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/command_modules/alive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/config.hpp>
#include <filesystem>
#include <memory>
#include <mutex>
#include <StringResManager.hpp>

Expand All @@ -13,6 +14,7 @@
#include "CompileTimeStringConcat.hpp"
#include "database/bot/TgBotDatabaseImpl.hpp"
#include "internal/_tgbot.h"
#include "tgbot/types/ReplyParameters.h"

template <unsigned Len>
consteval auto cat(const char (&strings)[Len]) {
Expand Down Expand Up @@ -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<TgBot::ReplyParameters>();
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/third-party/tgbot-cpp

0 comments on commit 61d9d38

Please sign in to comment.