diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e390b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/** \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..394c410 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.4) +project(FastisCalendar) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall") +set(Boost_USE_MULTITHREADED ON) + +find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(Boost COMPONENTS system REQUIRED) +find_package(CURL) +include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) +if (CURL_FOUND) + include_directories(${CURL_INCLUDE_DIRS}) + add_definitions(-DHAVE_CURL) +endif() + +add_executable(FastisCalendar src/main.cpp) + +target_link_libraries(FastisCalendar /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5deb067 --- /dev/null +++ b/main.cpp @@ -0,0 +1,36 @@ +#include +#include + +int main() { + TgBot::Bot bot("436931164:AAG3LyZywIzODiMhXtBPzMI4U3BBEv4z4zA"); + bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "Hi!"); + }); + + bot.getEvents().onCommand("love", [&bot](TgBot::Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "I love you!"); + }); + + + bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) { + printf("User wrote %s\n", message->text.c_str()); + if (StringTools::startsWith(message->text, "/start")) { + return; + } + if (StringTools::startsWith(message->text, "/love")) { + return; + } + bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); + }); + try { + printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); + TgBot::TgLongPoll longPoll(bot); + while (true) { + printf("Long poll started\n"); + longPoll.start(); + } + } catch (TgBot::TgException& e) { + printf("error: %s\n", e.what()); + } + return 0; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..bdf6cf3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +#include // Include boost::for is_any_of +#include // Include for boost::split + + +#define OWNER 129755859 +int main() { + std::string token(getenv("TOKEN")); + TgBot::Bot bot(token); + bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "Hi!"); + }); + + + bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) + { + + bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); + }); + try { + printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); + TgBot::TgLongPoll longPoll(bot); + while (true) { + printf("Long poll started\n"); + longPoll.start(); + + } + } catch (TgBot::TgException& e) { + printf("error: %s\n", e.what()); + } + return 0; +}