diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-07-09 15:03:59 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-07-09 15:03:59 +0300 |
commit | 51d2176d1535c8c8176426909e1c7b70633d794b (patch) | |
tree | 4301e0bb6f93913c53d4f41bdd96ddf1fcff9221 /samples | |
parent | 28ef71aa3c6d9473d4127dd648161a0afa109895 (diff) |
Refactoring
Diffstat (limited to 'samples')
-rw-r--r-- | samples/echobot/src/main.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/samples/echobot/src/main.cpp b/samples/echobot/src/main.cpp index 4874aab..03d9d3d 100644 --- a/samples/echobot/src/main.cpp +++ b/samples/echobot/src/main.cpp @@ -25,8 +25,9 @@ #include <exception> #include <tgbot/Bot.h> -#include <tgbot/tools/StringTools.h> +#include <tgbot/net/TgLongPoll.h> #include <tgbot/TgException.h> +#include <tgbot/tools/StringTools.h> using namespace std; using namespace TgBot; @@ -39,28 +40,31 @@ int main() { sigintGot = true; }); - Bot bot("PLACE_YOUR_TOKEN_HERE"); - bot.getEvents().onCommand("start", [](Message::Ptr message, Bot* const bot) { - bot->getApi().sendMessage(message->chat->id, "Hi!"); + Bot bot("100743144:AAEzJJSWYezyUYlwgzSjf0-5hdokGyUjbXM"); + bot.getEvents().onCommand("start", [&bot](Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "Hi!"); }); - bot.getEvents().onAnyMessage([](Message::Ptr message, Bot* const bot) { + bot.getEvents().onAnyMessage([&bot](Message::Ptr message) { printf("User wrote %s\n", message->text.c_str()); if (StringTools::startsWith(message->text, "/start")) { return; } - bot->getApi().sendMessage(message->chat->id, "Your message is: " + message->text); + bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); }); + printf("try {\n"); try { printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); + TgLongPoll longPoll(bot); while (!sigintGot) { printf("Long poll started\n"); - bot.startLongPoll(); + longPoll.start(); } } catch (TgException& e) { printf("error: %s\n", e.what()); } + printf("}\n"); return 0; } |