diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..32552d9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tgbot"] + path = tgbot + url = git@github.com:mandlm/telegram-bot-api diff --git a/BeezleBot/BeezleBot.cpp b/BeezleBot/BeezleBot.cpp index 3a86265..3d7e24c 100644 --- a/BeezleBot/BeezleBot.cpp +++ b/BeezleBot/BeezleBot.cpp @@ -1,6 +1,8 @@ #include "settings.h" +#include "tgbot/bot.h" #include +#include int main(int argc, char **argv) { @@ -15,6 +17,25 @@ int main(int argc, char **argv) std::cout << user << " "; } std::cout << std::endl; + + tgbot::LongPollBot bot(settings.token); + bot.callback([] (const tgbot::types::Message message, const tgbot::methods::Api &api) + { + if (message.text != nullptr && message.from != nullptr) + { + std::ostringstream logMessage; + logMessage << message.from->firstName; + + if (message.from->username != nullptr) + { + logMessage << " (" << *message.from->username << ")"; + } + + logMessage << ": " << *message.text; + api.getLogger().info(logMessage.str()); + } + }); + bot.start(); } catch (std::runtime_error &e) { diff --git a/BeezleBot/CMakeLists.txt b/BeezleBot/CMakeLists.txt index 81f0929..31aee14 100644 --- a/BeezleBot/CMakeLists.txt +++ b/BeezleBot/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE Boost::program_options + tgbot ) target_compile_features(${PROJECT_NAME} diff --git a/CMakeLists.txt b/CMakeLists.txt index 296a3d7..c5c0a29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.5) -project(Beezle) - +add_subdirectory(tgbot) add_subdirectory(BeezleBot) diff --git a/tgbot b/tgbot new file mode 160000 index 0000000..b51e3ae --- /dev/null +++ b/tgbot @@ -0,0 +1 @@ +Subproject commit b51e3aeb9c59a62ae620e7d2b7e856edef1db5b1