Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ constexpr char welcomeMessage[] =
"свою группу и добавь дисциплину";
constexpr char createdGroup[] = "✨Группа создана!✨";
constexpr char deletedGroup[] = "Группа удалена";
constexpr char enterGroupName[] = "Введите название группы:";
constexpr char enterGroupName[] = "Введите название группы:";
constexpr char enterNewGroupName[] = "Введите новое название группы:";
constexpr char groupNameSaved[] = "Название группы сохранено ✅";
constexpr char newGroupNameSaved[] = "Новое имя группы сохранено ✅";
Expand All @@ -64,10 +64,11 @@ constexpr char create_group[] = "create_group";
constexpr char delete_group[] = "delete_group";
constexpr char edit_group[] = "edit_group";
constexpr char make_discipline[] = "make_discipline";
constexpr char main_menu[] = "main_menu";

const std::unordered_set<std::string> commands({start, create_group,
delete_group, edit_group,
make_discipline});
make_discipline, main_menu});
} // namespace commands

namespace db_queries {}
Expand All @@ -86,6 +87,7 @@ constexpr char dontAddDescription[] = "Не добавлять описание"
constexpr char createGroup[] = "Создать группу";
constexpr char editGroup[] = "Изменить имя группы ✏️";
constexpr char deleteGroup[] = "Удалить группу";
constexpr char mainMenu[] = "Главное меню.";
} // namespace button_names

namespace button_data {
Expand All @@ -97,6 +99,7 @@ constexpr char dontAddDescription[] = "dontAddDescription";
constexpr char createGroup[] = "createGroup";
constexpr char editGroup[] = "editGroup";
constexpr char deleteGroup[] = "deleteGroup";
constexpr char mainMenu[] = "mainMenu";
} // namespace button_data

namespace standard_text {
Expand Down Expand Up @@ -170,6 +173,11 @@ TgBot::InlineKeyboardButton::Ptr deleteGroup(new TgBot::InlineKeyboardButton{
button_names::deleteGroup, {}, button_data::deleteGroup});
const TgBot::InlineKeyboardMarkup::Ptr deleteGroupKeyboard(
new TgBot::InlineKeyboardMarkup);
// main menu
TgBot::InlineKeyboardButton::Ptr mainMenu(new TgBot::InlineKeyboardButton{
button_names::mainMenu, {}, button_data::mainMenu});
const TgBot::InlineKeyboardMarkup::Ptr mainMenuKeyboard(
new TgBot::InlineKeyboardMarkup);

void init_keyboards() {
making_discipline_keyboard->inlineKeyboard = {{std::move(make_discipline)}};
Expand All @@ -183,6 +191,7 @@ void init_keyboards() {
createGroupKeyboard->inlineKeyboard = {{std::move(createGroup)}};
deleteGroupKeyboard->inlineKeyboard = {{std::move(deleteGroup)}};
editGroupKeyboard->inlineKeyboard = {{std::move(editGroup)}};
mainMenuKeyboard->inlineKeyboard = {{std::move(mainMenu)}};
}

} // namespace keyboards
Expand Down
24 changes: 24 additions & 0 deletions include/db_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <utility>

#include "constants.h"

Expand All @@ -23,6 +24,29 @@ void init_conn() {
}

void close_conn() { sqlite3_close(db_conn); }

TgBot::InlineKeyboardMarkup::Ptr make_MainMenuKeyboard(const TgBot::Bot &bot) {
// открываем бд

// Создаем запрос который даст нам имена всех груп пользователя
// В соответствии с запросом берем из бд имена и конвертируем их в кнопки
const TgBot::InlineKeyboardMarkup::Ptr MenuKeyboard(
new TgBot::InlineKeyboardMarkup);
/*
while (sqlite3_step(statement) == SQLITE_ROW) {
TgBot::InlineKeyboardButton::Ptr GroupButton(new
TgBot::InlineKeyboardButton); GroupButton->text = reinterpret_cast<const char
*>(sqlite3_column_text(statement, 1)); GroupButton->callbackData=
std::to_string(sqlite3_column_int(statement, 0)); MenuKeyboard->inlineKeyboard
= {{std::move(GroupButton)}};
}*/

MenuKeyboard->inlineKeyboard = {{std::move(keyboards::createGroup)}};

// закрываем бд
return MenuKeyboard;
}

} // namespace db

#endif // INCLUDE_DB_UTILS_H_
52 changes: 30 additions & 22 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <tgbot/tgbot.h>

#include <format>

#include <cstdio>
#include <format>

#include "../include/constants.h"
#include "../include/db_utils.h"
Expand All @@ -23,6 +22,7 @@ int main() {
keyboards::discipline_confirmation_keyboard;
const auto& dont_add_description_keyboard =
keyboards::dont_add_description_keyboard;
const auto& mainMenuKeyboard = keyboards::mainMenuKeyboard;

db::init_conn();

Expand All @@ -33,8 +33,8 @@ int main() {
making_discipline_keyboard,
stop_making_discipline_keyboard,
discipline_confirmation_keyboard,
dont_add_description_keyboard]
(const TgBot::CallbackQuery::Ptr& query) {
dont_add_description_keyboard](
const TgBot::CallbackQuery::Ptr& query) {
int64_t userId = query->message->chat->id;
if (query->data == button_data::createGroup) {
getGroup(userId)->set_owner_id(userId);
Expand Down Expand Up @@ -62,17 +62,27 @@ int main() {
} else if (query->data == button_data::disciplineConfirmed) {
bot.getApi().sendMessage(userId, messages::disciplineIsSaved);
} else if (query->data == button_data::dontAddDescription) {
bot.getApi().sendMessage(userId,
messages::disciplineHaveNoDescription);
bot.getApi().sendMessage(userId, messages::disciplineHaveNoDescription);
getSubject(userId)->set_description(standard_text::defaultDescription);
bot.getApi().sendMessage(userId, getSubject(userId)->print_all());
bot.getApi().sendMessage(
userId, messages::checkDiscipline, nullptr, nullptr,
discipline_confirmation_keyboard);
bot.getApi().sendMessage(userId, messages::checkDiscipline, nullptr,
nullptr, discipline_confirmation_keyboard);
setState(userId, State::NONE);
} else if (query->data == button_data::mainMenu) {
TgBot::InlineKeyboardMarkup::Ptr MenuKeyboard =
db::make_MainMenuKeyboard(bot);
bot.getApi().sendMessage(query->message->chat->id, messages::MenuTitle,
nullptr, nullptr, MenuKeyboard);
}
});

bot.getEvents().onCommand(
commands::main_menu,
[&bot, mainMenuKeyboard](const TgBot::Message::Ptr& message) {
bot.getApi().sendMessage(message->chat->id, messages::MenuTitle,
nullptr, nullptr, mainMenuKeyboard);
});

bot.getEvents().onCommand(
commands::start, [&bot](const TgBot::Message::Ptr& message) {
if (message->chat->type == TgBot::Chat::Type::Private) {
Expand Down Expand Up @@ -103,7 +113,7 @@ int main() {

bot.getEvents().onCommand(
commands::make_discipline, [&bot, stop_making_discipline_keyboard](
const TgBot::Message::Ptr& message) {
const TgBot::Message::Ptr& message) {
int64_t userId = message->chat->id;
bot.getApi().sendMessage(userId, messages::disciplineMakingNew);
bot.getApi().sendMessage(userId, messages::disciplineEnterName, nullptr,
Expand Down Expand Up @@ -154,11 +164,10 @@ int main() {
nullptr, nullptr,
stop_making_discipline_keyboard);
} else {
bot.getApi().sendMessage(userId,
std::format(
messages::disciplineWrongNameLength,
lengths::min_discipline_name_length,
lengths::min_discipline_name_length));
bot.getApi().sendMessage(
userId, std::format(messages::disciplineWrongNameLength,
lengths::min_discipline_name_length,
lengths::min_discipline_name_length));
}
break;
case State::WAITING_FOR_PROFESSOR_NAME: {
Expand All @@ -167,14 +176,13 @@ int main() {
if (spaceCount >= lengths::minimal_space_count_in_name) {
getSubject(userId)->set_professor_name(message->text);
bot.getApi().sendMessage(
userId, messages::disciplineProfessorNameSaved, nullptr,
nullptr, stop_making_discipline_keyboard);
userId, messages::disciplineProfessorNameSaved, nullptr, nullptr,
stop_making_discipline_keyboard);
setState(userId, State::WAITING_FOR_PROFESSOR_EMAIL);
bot.getApi().sendMessage(userId, messages::disciplineEnterEmail,
nullptr, nullptr);
} else {
bot.getApi().sendMessage(userId,
messages::disciplineWrongFullName);
bot.getApi().sendMessage(userId, messages::disciplineWrongFullName);
}
} break;
case State::WAITING_FOR_PROFESSOR_EMAIL:
Expand All @@ -184,9 +192,9 @@ int main() {
nullptr, nullptr,
stop_making_discipline_keyboard);
setState(userId, State::WAITING_FOR_DESCRIPTION);
bot.getApi().sendMessage(
userId, messages::disciplineEnterDescription, nullptr, nullptr,
dont_add_description_keyboard);
bot.getApi().sendMessage(userId, messages::disciplineEnterDescription,
nullptr, nullptr,
dont_add_description_keyboard);
} else {
bot.getApi().sendMessage(userId, messages::disciplineWrongEmail);
}
Expand Down