Started creating structure of bot interface
This commit is contained in:
parent
879a7981cd
commit
602e9b62d8
8 changed files with 122 additions and 0 deletions
15
modules/bot/front/src/KeyboardFactory.cpp
Normal file
15
modules/bot/front/src/KeyboardFactory.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include "KeyboardFactory.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
TgBot::InlineKeyboardMarkup::Ptr KeyboardFactory::createMainMenu() {
|
||||
auto keyboard = std::make_shared<TgBot::InlineKeyboardMarkup>();
|
||||
TgBot::InlineKeyboardButton::Ptr button1(new TgBot::InlineKeyboardButton);
|
||||
button1->text = BotConstants::Button::FIND_ANIME;
|
||||
button1->callbackData = BotConstants::Callback::FIND_ANIME;
|
||||
TgBot::InlineKeyboardButton::Ptr button2(new TgBot::InlineKeyboardButton);
|
||||
button2->text = BotConstants::Button::MY_TITLES;
|
||||
button2->callbackData = BotConstants::Callback::MY_TITLES;
|
||||
|
||||
keyboard->inlineKeyboard = {{button1, button2}};
|
||||
return keyboard;
|
||||
}
|
||||
21
modules/bot/front/src/front.cpp
Normal file
21
modules/bot/front/src/front.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "front.hpp"
|
||||
#include "KeyboardFactory.hpp"
|
||||
|
||||
AnimeBot::AnimeBot(const std::string& token) : bot(token) {
|
||||
setupHandlers();
|
||||
}
|
||||
|
||||
void AnimeBot::setupHandlers() {
|
||||
bot.getEvents().onCommand("start", [this](TgBot::Message::Ptr message) {
|
||||
sendMainMenu(message->chat->id);
|
||||
});
|
||||
}
|
||||
|
||||
void AnimeBot::sendMainMenu(int64_t chatId) {
|
||||
auto keyboard = KeyboardFactory::createMainMenu();
|
||||
bot.getApi().sendMessage(chatId, "Главное меню", nullptr, nullptr, keyboard);
|
||||
}
|
||||
|
||||
TgBot::Bot& AnimeBot::getBot() {
|
||||
return bot;
|
||||
}
|
||||
15
modules/bot/front/src/main.cpp
Normal file
15
modules/bot/front/src/main.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <front.hpp>
|
||||
|
||||
int main() {
|
||||
AnimeBot bot(getenv("TOKEN"));
|
||||
TgBot::TgLongPoll longPoll(bot.getBot());
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
longPoll.start();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue