Kaynağa Gözat

First commit with code, just hello bot...

master
Martin Klimeš 5 yıl önce
ebeveyn
işleme
d266829e1b
4 değiştirilmiş dosya ile 93 ekleme ve 0 silme
  1. +1
    -0
      .gitignore
  2. +19
    -0
      CMakeLists.txt
  3. +36
    -0
      main.cpp
  4. +37
    -0
      src/main.cpp

+ 1
- 0
.gitignore Dosyayı Görüntüle

@ -0,0 +1 @@
build/**

+ 19
- 0
CMakeLists.txt Dosyayı Görüntüle

@ -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})

+ 36
- 0
main.cpp Dosyayı Görüntüle

@ -0,0 +1,36 @@
#include <stdio.h>
#include <tgbot/tgbot.h>
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;
}

+ 37
- 0
src/main.cpp Dosyayı Görüntüle

@ -0,0 +1,37 @@
#include <stdio.h>
#include <iostream>
#include <tgbot/tgbot.h>
#include <string>
#include <vector>
#include <boost/algorithm/string/classification.hpp> // Include boost::for is_any_of
#include <boost/algorithm/string/split.hpp> // 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;
}

Yükleniyor…
İptal
Kaydet