From bf1a2ea04055730d4517ed74c7e039e3adf85566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DreaM=E2=9C=A8?= Date: Thu, 23 Jan 2025 19:18:49 +0300 Subject: [PATCH 01/55] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 89f74a9..9c90fd7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # EntryPoint Проект на плюсах от 3 амбициозных пацанчиков + + +### Чуток описание проекта : +Телеграмм-бот с авторизацией для студентов, преподавателей, администрации, организаторов учебного процесса (учебный офис, кураторы и т.п.). Среди базового функционала присутствуют: система анонимной студенческой оценки преподавания, система донесения информации от учебного офиса, преподавателей и кураторов до студентов c подтверждением получения (в т.ч. ссылок на чаты и объявлений). Возможность поддержания полезной информации о предметах внутри бота (ссылки, таблицы, папки, чаты, файлы) с возможностью изменения студентами (как wiki, просмотр изменений). + From a551c786e431c611c8c18cac5cfcbeb06062a7be Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 11 Feb 2025 00:39:27 +0300 Subject: [PATCH 02/55] start work --- .gitignore | 2 ++ CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++ inc/OfficeStaff.hpp | 11 +++++++++ inc/Student.hpp | 19 ++++++++++++++ inc/User.hpp | 20 +++++++++++++++ src/OfficeStaff.cpp | 0 src/Student.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/User.cpp | 10 ++++++++ src/main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 220 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 inc/OfficeStaff.hpp create mode 100644 inc/Student.hpp create mode 100644 inc/User.hpp create mode 100644 src/OfficeStaff.cpp create mode 100644 src/Student.cpp create mode 100644 src/User.cpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore index 259148f..cdd0af4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +BotToken.hpp +/build # Prerequisites *.d diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1e239bd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.10) # Указываем минимальную версию CMake +project(TelegramBot) # Указываем имя проекта + +# Устанавливаем стандарт C++ +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Поиск необходимых библиотек +find_package(Boost REQUIRED COMPONENTS system) # Ищем Boost (модуль system) +find_package(TgBot REQUIRED) # Ищем библиотеку TgBot + +# Указываем путь к заголовочным файлам +include_directories(inc) # Например, папка "inc" для .hpp файлов + +# Собираем список исходников +file(GLOB SOURCES src/*.cpp) # Собираем все .cpp файлы в папке src + +# Создаём исполняемый файл +add_executable(my_bot ${SOURCES}) # Компилируем все найденные .cpp файлы + +# Линкуем с найденными библиотеками +target_link_libraries(my_bot Boost::system TgBot::TgBot) + +# Включаем санитайзеры +# if(CMAKE_BUILD_TYPE STREQUAL "Debug") +# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") +# target_compile_options(my_bot PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) +# target_link_options(my_bot PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) +# endif() +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(my_bot PRIVATE + -g + -fsanitize=address,undefined + -fno-omit-frame-pointer + ) + target_link_options(my_bot PRIVATE + -fsanitize=address,undefined + -fno-omit-frame-pointer + ) +endif() +# cmake -DCMAKE_BUILD_TYPE=Debug .. +# make \ No newline at end of file diff --git a/inc/OfficeStaff.hpp b/inc/OfficeStaff.hpp new file mode 100644 index 0000000..c5fdae0 --- /dev/null +++ b/inc/OfficeStaff.hpp @@ -0,0 +1,11 @@ +#ifndef OFFECESTAFF_HPP_ +#define OFFECESTAFF_HPP_ + +#include "User.hpp" + +namespace mtd { + +} + + +#endif diff --git a/inc/Student.hpp b/inc/Student.hpp new file mode 100644 index 0000000..c3a641b --- /dev/null +++ b/inc/Student.hpp @@ -0,0 +1,19 @@ +#ifndef STUDENT_GPP_ +#define STUDENT_GPP_ + +#include +#include "User.hpp" + +namespace mtd { +class Student : public User { +public: + Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} + TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard(); + TgBot::InlineKeyboardMarkup::Ptr get_menu(); + TgBot::InlineKeyboardMarkup::Ptr back_button(); +}; +} + + + +#endif \ No newline at end of file diff --git a/inc/User.hpp b/inc/User.hpp new file mode 100644 index 0000000..ac617c4 --- /dev/null +++ b/inc/User.hpp @@ -0,0 +1,20 @@ +#ifndef USER_HPP_ +#define USER_HPP_ + +#include + +namespace mtd { +enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; + +class User { + int64_t chat_id = 0; + UserRole role = UserRole::NONE; +public: + explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role) {} + // virtual ~User() {} + int64_t id() const; + UserRole get_role() const; +}; +} + +#endif \ No newline at end of file diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Student.cpp b/src/Student.cpp new file mode 100644 index 0000000..7db34c5 --- /dev/null +++ b/src/Student.cpp @@ -0,0 +1,60 @@ +#include "Student.hpp" + +namespace mtd { +TgBot::InlineKeyboardMarkup::Ptr Student::get_inline_keyboard() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr time_table(new TgBot::InlineKeyboardButton); + time_table->text = "📅 Расписание"; + time_table->callbackData = "student_time_table"; + + TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); + declaration->text = "📢 Объявления"; + declaration->callbackData = "student_declaration"; + + TgBot::InlineKeyboardButton::Ptr connect_with_teacher(new TgBot::InlineKeyboardButton); + connect_with_teacher->text = "📩 Связь с преподавателем"; + connect_with_teacher->callbackData = "student_connect_with_teacher"; + + TgBot::InlineKeyboardButton::Ptr help(new TgBot::InlineKeyboardButton); + help->text = "❓ Помощь"; + help->callbackData = "student_help"; + + TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); + back->text = "🔙 Назад"; + back->callbackData = "student_back"; + + inline_keyboard->inlineKeyboard.push_back({time_table}); + inline_keyboard->inlineKeyboard.push_back({declaration}); + inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); + inline_keyboard->inlineKeyboard.push_back({help}); + inline_keyboard->inlineKeyboard.push_back({back}); + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Student::get_menu() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); + buttons->text = "кнопочки"; + buttons->callbackData = "student_buttons"; + + TgBot::InlineKeyboardButton::Ptr information(new TgBot::InlineKeyboardButton); + information->text = "Информация"; + information->callbackData = "student_information"; + + + inline_keyboard->inlineKeyboard.push_back({buttons}); + inline_keyboard->inlineKeyboard.push_back({information}); + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Student::back_button() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "🔙 Назад"; + button->callbackData = "student_back"; + keyboard->inlineKeyboard.push_back({button}); + return keyboard; +} +} \ No newline at end of file diff --git a/src/User.cpp b/src/User.cpp new file mode 100644 index 0000000..54b80d3 --- /dev/null +++ b/src/User.cpp @@ -0,0 +1,10 @@ +#include "User.hpp" + +namespace mtd { +int64_t User::id() const { + return chat_id; +} +UserRole User::get_role() const { + return role; +} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..869c722 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,55 @@ +#include +#include "BotToken.hpp" +#include +#include "Student.hpp" +#include + +int main() { + TgBot::Bot bot(mtd::token); + std::map> users; + + bot.getEvents().onCommand("start", [&bot, &users](TgBot::Message::Ptr message) { + auto st = std::make_shared(message->chat->id); + users.insert({st->id(), st}); + bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_inline_keyboard()); + }); + + bot.getEvents().onCallbackQuery([&bot, &users](TgBot::CallbackQuery::Ptr query) { + int64_t chat_id = query->message->chat->id; + // перестает блестеть кнопочка + // bot.getApi().answerCallbackQuery(query->id); + if (query->data == "student_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание"); + } + else if (query->data == "student_declaration") { + bot.getApi().sendMessage(chat_id, "Актуальные объявления"); + } + else if (query->data == "student_connect_with_teacher") { + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя"); + } + else if (query->data == "student_help") { + bot.getApi().sendMessage(chat_id, "Помощь"); + } + else if (query->data == "student_back") { + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); + return; + } + else if (query->data == "student_information") { + bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); + return; + } + bot.getApi().sendMessage(chat_id, "sdfds", 0, 0, users[chat_id]->get_inline_keyboard()); + }); + + try { + std::cout << "Bot is running...\n"; + TgBot::TgLongPoll longPoll(bot); + while (true) { + longPoll.start(); + } + } catch (const TgBot::TgException &e) { + std::cerr << "Error: " << e.what() << "\n"; + } + + return 0; +} \ No newline at end of file From 45801adb60a4e584bb9a0a29bbed0ccd24fdf835 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 12 Feb 2025 11:45:01 +0300 Subject: [PATCH 03/55] sdfsdfdsf --- .vscode/settings.json | 6 ++++ inc/OfficeStaff.hpp | 9 +++++- inc/Student.hpp | 6 ++-- inc/User.hpp | 5 +++- src/OfficeStaff.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 47 ++++++++++++++++++++++++++++-- 6 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4586f44 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "compare": "cpp", + "cstdint": "cpp" + } +} \ No newline at end of file diff --git a/inc/OfficeStaff.hpp b/inc/OfficeStaff.hpp index c5fdae0..9c66647 100644 --- a/inc/OfficeStaff.hpp +++ b/inc/OfficeStaff.hpp @@ -1,10 +1,17 @@ #ifndef OFFECESTAFF_HPP_ #define OFFECESTAFF_HPP_ +#include #include "User.hpp" namespace mtd { - +class OfficeStaff : public User { +public: + OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} + TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; + TgBot::InlineKeyboardMarkup::Ptr get_menu() override; + TgBot::InlineKeyboardMarkup::Ptr back_button() override; +}; } diff --git a/inc/Student.hpp b/inc/Student.hpp index c3a641b..df8d9a5 100644 --- a/inc/Student.hpp +++ b/inc/Student.hpp @@ -8,9 +8,9 @@ namespace mtd { class Student : public User { public: Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} - TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard(); - TgBot::InlineKeyboardMarkup::Ptr get_menu(); - TgBot::InlineKeyboardMarkup::Ptr back_button(); + TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; + TgBot::InlineKeyboardMarkup::Ptr get_menu() override; + TgBot::InlineKeyboardMarkup::Ptr back_button() override; }; } diff --git a/inc/User.hpp b/inc/User.hpp index ac617c4..ad8105c 100644 --- a/inc/User.hpp +++ b/inc/User.hpp @@ -11,9 +11,12 @@ class User { UserRole role = UserRole::NONE; public: explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role) {} - // virtual ~User() {} + virtual ~User() {} int64_t id() const; UserRole get_role() const; + virtual TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() = 0; + virtual TgBot::InlineKeyboardMarkup::Ptr get_menu() = 0; + virtual TgBot::InlineKeyboardMarkup::Ptr back_button() = 0; }; } diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp index e69de29..c3538a5 100644 --- a/src/OfficeStaff.cpp +++ b/src/OfficeStaff.cpp @@ -0,0 +1,68 @@ +#include "OfficeStaff.hpp" + +namespace mtd { +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_inline_keyboard() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr time_table(new TgBot::InlineKeyboardButton); + time_table->text = "📅 Расписание"; + time_table->callbackData = "office_staff_time_table"; + + TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); + declaration->text = "📢 Объявления"; + declaration->callbackData = "office_staff_declaration"; + + TgBot::InlineKeyboardButton::Ptr connect_with_teacher(new TgBot::InlineKeyboardButton); + connect_with_teacher->text = "📩 Связь с преподавателем"; + connect_with_teacher->callbackData = "office_staff_connect_with_teacher"; + + TgBot::InlineKeyboardButton::Ptr help(new TgBot::InlineKeyboardButton); + help->text = "❓ Помощь"; + help->callbackData = "office_staff_help"; + + // ЗДЕСЬ КАКОЙ_ТО ПИЗДЕЦ + // TgBot::InlineKeyboardButton::Ptr add_info(new TgBot::InlineKeyboardButton); + // help->text = "Добавить информацию"; + // help->callbackData = "office_add_info"; + + TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); + back->text = "🔙 Назад"; + back->callbackData = "office_staff_back"; + + inline_keyboard->inlineKeyboard.push_back({time_table}); + inline_keyboard->inlineKeyboard.push_back({declaration}); + inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); + inline_keyboard->inlineKeyboard.push_back({help}); + inline_keyboard->inlineKeyboard.push_back({back}); + // inline_keyboard->inlineKeyboard.push_back({add_info}); + std::cout << "1234567\n"; + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_menu() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); + buttons->text = "кнопочки"; + buttons->callbackData = "office_staff_buttons"; + + TgBot::InlineKeyboardButton::Ptr information(new TgBot::InlineKeyboardButton); + information->text = "Информация"; + information->callbackData = "office_staff_information"; + + + inline_keyboard->inlineKeyboard.push_back({buttons}); + inline_keyboard->inlineKeyboard.push_back({information}); + std::cout << "=====\n"; + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::back_button() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "🔙 Назад"; + button->callbackData = "office_staff_back"; + keyboard->inlineKeyboard.push_back({button}); + return keyboard; +} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 869c722..7384a14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,34 @@ #include #include "BotToken.hpp" #include +#include "User.hpp" #include "Student.hpp" +#include "OfficeStaff.hpp" #include int main() { TgBot::Bot bot(mtd::token); - std::map> users; + std::map> users; bot.getEvents().onCommand("start", [&bot, &users](TgBot::Message::Ptr message) { auto st = std::make_shared(message->chat->id); users.insert({st->id(), st}); - bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_inline_keyboard()); + bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_menu()); }); bot.getEvents().onCallbackQuery([&bot, &users](TgBot::CallbackQuery::Ptr query) { int64_t chat_id = query->message->chat->id; + if (users.find(chat_id) == users.end()) { + std::cout << "=== Error ===\n"; + return; + } + auto user = users[chat_id]; + if (user->get_role() == mtd::UserRole::STUDENT) { + std::cout << "This is student\n"; + } + else { + std::cout << "This is office staff\n"; + } // перестает блестеть кнопочка // bot.getApi().answerCallbackQuery(query->id); if (query->data == "student_time_table") { @@ -38,6 +51,36 @@ int main() { bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); return; } + // for office staff + if (query->data == "office_staff_buttons") { + std::cout << "YGVHUBJKJNJBVVHBKJNMKJNUVGNKOP\n"; + bot.getApi().sendMessage(chat_id, "zxc", 0, 0, user->get_inline_keyboard()); + return; + } + if (query->data == "office_staff_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff"); + } + else if (query->data == "office_staff_declaration") { + bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff"); + } + else if (query->data == "office_staff_connect_with_teacher") { + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff"); + } + else if (query->data == "office_staff_help") { + bot.getApi().sendMessage(chat_id, "Помощь для office staff"); + } + else if (query->data == "office_staff_back") { + bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, users[chat_id]->get_menu()); + return; + } + else if (query->data == "office_staff_information") { + bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, users[chat_id]->back_button()); + return; + } + else if (query->data == "office_add_info") { + bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию"); + } + bot.getApi().sendMessage(chat_id, "sdfds", 0, 0, users[chat_id]->get_inline_keyboard()); }); From 877a02b0db59f33ef5bb3b025e1b3e712938079f Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Thu, 13 Feb 2025 18:12:24 +0300 Subject: [PATCH 04/55] create OfficeStaffClass --- src/OfficeStaff.cpp | 8 ++++---- src/main.cpp | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp index c3538a5..efa0e81 100644 --- a/src/OfficeStaff.cpp +++ b/src/OfficeStaff.cpp @@ -21,9 +21,9 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_inline_keyboard() { help->callbackData = "office_staff_help"; // ЗДЕСЬ КАКОЙ_ТО ПИЗДЕЦ - // TgBot::InlineKeyboardButton::Ptr add_info(new TgBot::InlineKeyboardButton); - // help->text = "Добавить информацию"; - // help->callbackData = "office_add_info"; + TgBot::InlineKeyboardButton::Ptr add_info(new TgBot::InlineKeyboardButton); + add_info->text = "Добавить информацию"; + add_info->callbackData = "office_add_info"; TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); back->text = "🔙 Назад"; @@ -33,8 +33,8 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_inline_keyboard() { inline_keyboard->inlineKeyboard.push_back({declaration}); inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); inline_keyboard->inlineKeyboard.push_back({help}); + inline_keyboard->inlineKeyboard.push_back({add_info}); inline_keyboard->inlineKeyboard.push_back({back}); - // inline_keyboard->inlineKeyboard.push_back({add_info}); std::cout << "1234567\n"; return inline_keyboard; } diff --git a/src/main.cpp b/src/main.cpp index 7384a14..22f7ba8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ int main() { std::map> users; bot.getEvents().onCommand("start", [&bot, &users](TgBot::Message::Ptr message) { - auto st = std::make_shared(message->chat->id); + auto st = std::make_shared(message->chat->id); users.insert({st->id(), st}); bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_menu()); }); @@ -31,22 +31,26 @@ int main() { } // перестает блестеть кнопочка // bot.getApi().answerCallbackQuery(query->id); + if (query->data == "student_buttons") { + bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, users[chat_id]->get_inline_keyboard()); + } if (query->data == "student_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание"); + bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "student_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления"); + bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "student_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя"); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "student_help") { - bot.getApi().sendMessage(chat_id, "Помощь"); + bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "student_back") { bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); return; } + else if (query->data == "student_information") { bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); return; @@ -58,16 +62,16 @@ int main() { return; } if (query->data == "office_staff_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff"); + bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "office_staff_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff"); + bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "office_staff_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff"); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "office_staff_help") { - bot.getApi().sendMessage(chat_id, "Помощь для office staff"); + bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); } else if (query->data == "office_staff_back") { bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, users[chat_id]->get_menu()); @@ -78,10 +82,8 @@ int main() { return; } else if (query->data == "office_add_info") { - bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию"); + bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, users[chat_id]->get_inline_keyboard()); } - - bot.getApi().sendMessage(chat_id, "sdfds", 0, 0, users[chat_id]->get_inline_keyboard()); }); try { From 41a9cbf37bbd8a4828850254eecbf6c287d98251 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Fri, 14 Feb 2025 00:18:42 +0300 Subject: [PATCH 05/55] create two functions in main.cpp, good job --- .vscode/settings.json | 75 +++++++++++++++++++++++++- src/main.cpp | 119 ++++++++++++++++++++++++------------------ 2 files changed, 141 insertions(+), 53 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4586f44..63e0ee4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,79 @@ { "files.associations": { "compare": "cpp", - "cstdint": "cpp" + "cstdint": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "coroutine": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "source_location": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "format": "cpp" } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 22f7ba8..535f0e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,18 +5,78 @@ #include "Student.hpp" #include "OfficeStaff.hpp" #include +#include + +void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int64_t chat_id, std::map> &users) { + if (query->data == "student_buttons") { + bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, users[chat_id]->get_inline_keyboard()); + } + if (query->data == "student_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "student_declaration") { + bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "student_connect_with_teacher") { + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "student_help") { + bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "student_back") { + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); + return; + } + + else if (query->data == "student_information") { + bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); + return; + } +} + +void office_staff_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int64_t chat_id, std::map> &users) { + if (query->data == "office_staff_buttons") { + bot.getApi().sendMessage(chat_id, "zxc", 0, 0, users[chat_id]->get_inline_keyboard()); + return; + } + if (query->data == "office_staff_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "office_staff_declaration") { + bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "office_staff_connect_with_teacher") { + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "office_staff_help") { + bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + } + else if (query->data == "office_staff_back") { + bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, users[chat_id]->get_menu()); + return; + } + else if (query->data == "office_staff_information") { + bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, users[chat_id]->back_button()); + return; + } + else if (query->data == "office_add_info") { + bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, users[chat_id]->get_inline_keyboard()); + } +} int main() { TgBot::Bot bot(mtd::token); std::map> users; + std::mutex mutex_for_users; bot.getEvents().onCommand("start", [&bot, &users](TgBot::Message::Ptr message) { - auto st = std::make_shared(message->chat->id); + auto st = std::make_shared(message->chat->id); users.insert({st->id(), st}); bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_menu()); }); - bot.getEvents().onCallbackQuery([&bot, &users](TgBot::CallbackQuery::Ptr query) { + bot.getEvents().onCallbackQuery([&bot, &users, &mutex_for_users](TgBot::CallbackQuery::Ptr query) { + std::lock_guard lock(mutex_for_users); int64_t chat_id = query->message->chat->id; if (users.find(chat_id) == users.end()) { std::cout << "=== Error ===\n"; @@ -31,59 +91,14 @@ int main() { } // перестает блестеть кнопочка // bot.getApi().answerCallbackQuery(query->id); - if (query->data == "student_buttons") { - bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, users[chat_id]->get_inline_keyboard()); - } - if (query->data == "student_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "student_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "student_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "student_help") { - bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "student_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); - return; + if (user->get_role() == mtd::UserRole::STUDENT) { + student_call_back_query(bot, query, chat_id, users); } - - else if (query->data == "student_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); - return; + else if (user->get_role() == mtd::UserRole::OFFICE_STAFF) { + office_staff_call_back_query(bot, query, chat_id, users); } // for office staff - if (query->data == "office_staff_buttons") { - std::cout << "YGVHUBJKJNJBVVHBKJNMKJNUVGNKOP\n"; - bot.getApi().sendMessage(chat_id, "zxc", 0, 0, user->get_inline_keyboard()); - return; - } - if (query->data == "office_staff_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "office_staff_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "office_staff_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "office_staff_help") { - bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); - } - else if (query->data == "office_staff_back") { - bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, users[chat_id]->get_menu()); - return; - } - else if (query->data == "office_staff_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, users[chat_id]->back_button()); - return; - } - else if (query->data == "office_add_info") { - bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, users[chat_id]->get_inline_keyboard()); - } + }); try { From 6e3476ee8cd695444aa004ed795a7ca30bf2c4c7 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 16 Feb 2025 01:07:52 +0300 Subject: [PATCH 06/55] Create Teacher class and main.cpp was redone but note finished --- inc/OfficeStaff.hpp | 1 - inc/Student.hpp | 1 - inc/Teacher.hpp | 16 ++++++ src/OfficeStaff.cpp | 2 - src/Teacher.cpp | 46 ++++++++++++++++ src/main.cpp | 131 ++++++++++++++++++++++++++++++-------------- 6 files changed, 151 insertions(+), 46 deletions(-) create mode 100644 inc/Teacher.hpp create mode 100644 src/Teacher.cpp diff --git a/inc/OfficeStaff.hpp b/inc/OfficeStaff.hpp index 9c66647..8088759 100644 --- a/inc/OfficeStaff.hpp +++ b/inc/OfficeStaff.hpp @@ -1,7 +1,6 @@ #ifndef OFFECESTAFF_HPP_ #define OFFECESTAFF_HPP_ -#include #include "User.hpp" namespace mtd { diff --git a/inc/Student.hpp b/inc/Student.hpp index df8d9a5..c2cdf27 100644 --- a/inc/Student.hpp +++ b/inc/Student.hpp @@ -1,7 +1,6 @@ #ifndef STUDENT_GPP_ #define STUDENT_GPP_ -#include #include "User.hpp" namespace mtd { diff --git a/inc/Teacher.hpp b/inc/Teacher.hpp new file mode 100644 index 0000000..0858a6c --- /dev/null +++ b/inc/Teacher.hpp @@ -0,0 +1,16 @@ +#ifndef TEACHER_HPP_ +#define TEACHER_HPP_ + +#include "User.hpp" + +namespace mtd { +class Teacher : public User { +public: + Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) {} + TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; + TgBot::InlineKeyboardMarkup::Ptr get_menu() override; + TgBot::InlineKeyboardMarkup::Ptr back_button() override; +}; +} + +#endif \ No newline at end of file diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp index efa0e81..ac6f61d 100644 --- a/src/OfficeStaff.cpp +++ b/src/OfficeStaff.cpp @@ -35,7 +35,6 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_inline_keyboard() { inline_keyboard->inlineKeyboard.push_back({help}); inline_keyboard->inlineKeyboard.push_back({add_info}); inline_keyboard->inlineKeyboard.push_back({back}); - std::cout << "1234567\n"; return inline_keyboard; } @@ -53,7 +52,6 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_menu() { inline_keyboard->inlineKeyboard.push_back({buttons}); inline_keyboard->inlineKeyboard.push_back({information}); - std::cout << "=====\n"; return inline_keyboard; } diff --git a/src/Teacher.cpp b/src/Teacher.cpp new file mode 100644 index 0000000..09d4b7e --- /dev/null +++ b/src/Teacher.cpp @@ -0,0 +1,46 @@ +#include "Teacher.hpp" + +namespace mtd { +TgBot::InlineKeyboardMarkup::Ptr Teacher::get_inline_keyboard() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); + declaration->text = "Уведомление студентам"; + declaration->callbackData = "teacher_declaration"; + inline_keyboard->inlineKeyboard.push_back({declaration}); + + TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); + back->text = "🔙 Назад"; + back->callbackData = "teacher_back"; + inline_keyboard->inlineKeyboard.push_back({back}); + + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Teacher::get_menu() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); + buttons->text = "кнопочки"; + buttons->callbackData = "teacher_buttons"; + + TgBot::InlineKeyboardButton::Ptr information(new TgBot::InlineKeyboardButton); + information->text = "Информация"; + information->callbackData = "teachert_information"; + + + inline_keyboard->inlineKeyboard.push_back({buttons}); + inline_keyboard->inlineKeyboard.push_back({information}); + + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Teacher::back_button() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "🔙 Назад"; + button->callbackData = "teacher_back"; + keyboard->inlineKeyboard.push_back({button}); + return keyboard; +} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 535f0e4..67ea938 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,100 +4,147 @@ #include "User.hpp" #include "Student.hpp" #include "OfficeStaff.hpp" +#include "Teacher.hpp" #include #include +#include -void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int64_t chat_id, std::map> &users) { +void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { + int64_t chat_id = user->id(); if (query->data == "student_buttons") { - bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, user->get_inline_keyboard()); } - if (query->data == "student_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, users[chat_id]->get_inline_keyboard()); + else if (query->data == "student_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, user->get_inline_keyboard()); } else if (query->data == "student_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, user->get_inline_keyboard()); } else if (query->data == "student_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, user->get_inline_keyboard()); } else if (query->data == "student_help") { - bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, user->get_inline_keyboard()); } else if (query->data == "student_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); - return; + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); } - else if (query->data == "student_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, users[chat_id]->back_button()); - return; + bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, user->back_button()); } } -void office_staff_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int64_t chat_id, std::map> &users) { +void office_staff_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { + int64_t chat_id = user->id(); if (query->data == "office_staff_buttons") { - bot.getApi().sendMessage(chat_id, "zxc", 0, 0, users[chat_id]->get_inline_keyboard()); - return; + bot.getApi().sendMessage(chat_id, "Кнопочки", 0, 0, user->get_inline_keyboard()); } - if (query->data == "office_staff_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + else if (query->data == "office_staff_time_table") { + bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, user->get_inline_keyboard()); } else if (query->data == "office_staff_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, user->get_inline_keyboard()); } else if (query->data == "office_staff_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, user->get_inline_keyboard()); } else if (query->data == "office_staff_help") { - bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, user->get_inline_keyboard()); } else if (query->data == "office_staff_back") { - bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, users[chat_id]->get_menu()); - return; + bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, user->get_menu()); } else if (query->data == "office_staff_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, users[chat_id]->back_button()); - return; + bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, user->back_button()); } else if (query->data == "office_add_info") { - bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, users[chat_id]->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, user->get_inline_keyboard()); + } +} + +void teacher_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { + int64_t chat_id = user->id(); + if (query->data == "teacher_declaration") { + bot.getApi().sendMessage(chat_id, "Вы преподаватель и вы можите сделать объявление", 0, 0, user->back_button()); + } + else if (query->data == "teacher_back") { + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); + } + else if (query->data == "teacher_buttons") { + bot.getApi().sendMessage(chat_id, "Кнопочки для преподов", 0, 0, user->get_inline_keyboard()); + } + else if (query->data == "teachert_information") { + bot.getApi().sendMessage(chat_id, "Какая-то полезная инва для преподов", 0, 0, user->back_button()); } } int main() { TgBot::Bot bot(mtd::token); std::map> users; + std::set new_users; std::mutex mutex_for_users; - bot.getEvents().onCommand("start", [&bot, &users](TgBot::Message::Ptr message) { - auto st = std::make_shared(message->chat->id); - users.insert({st->id(), st}); - bot.getApi().sendMessage(st->id(), "zDF", 0, 0, st->get_menu()); + bot.getEvents().onCommand("start", [&bot, &users, &mutex_for_users, &new_users](TgBot::Message::Ptr message) { + std::lock_guard lock(mutex_for_users); + new_users.insert(message->chat->id); + + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr b1(new TgBot::InlineKeyboardButton); + b1->text = "Студент"; + b1->callbackData = "student"; + + TgBot::InlineKeyboardButton::Ptr b2(new TgBot::InlineKeyboardButton); + b2->text = "Очебный офис"; + b2->callbackData = "office_staff"; + + TgBot::InlineKeyboardButton::Ptr b3(new TgBot::InlineKeyboardButton); + b3->text = "Преподаватель"; + b3->callbackData = "teacher"; + + keyboard->inlineKeyboard.push_back({b1}); + keyboard->inlineKeyboard.push_back({b2}); + keyboard->inlineKeyboard.push_back({b3}); + + bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); }); - bot.getEvents().onCallbackQuery([&bot, &users, &mutex_for_users](TgBot::CallbackQuery::Ptr query) { + bot.getEvents().onCallbackQuery([&bot, &users, &mutex_for_users, &new_users](TgBot::CallbackQuery::Ptr query) { std::lock_guard lock(mutex_for_users); int64_t chat_id = query->message->chat->id; if (users.find(chat_id) == users.end()) { std::cout << "=== Error ===\n"; - return; - } - auto user = users[chat_id]; - if (user->get_role() == mtd::UserRole::STUDENT) { - std::cout << "This is student\n"; } - else { - std::cout << "This is office staff\n"; + + if (new_users.find(chat_id) != new_users.end()) { + if (query->data == "student") { + auto student_ptr = std::make_shared(chat_id); + users.insert({chat_id, student_ptr}); + } + else if (query->data == "office_staff") { + auto office_staff_ptr = std::make_shared(chat_id); + users.insert({chat_id, office_staff_ptr}); + } + else if (query->data == "teacher") { + auto teacher_ptr = std::make_shared(chat_id); + users.insert({chat_id, teacher_ptr}); + } + + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); + new_users.erase(chat_id); + return; } - // перестает блестеть кнопочка - // bot.getApi().answerCallbackQuery(query->id); + + + auto &user = users[chat_id]; if (user->get_role() == mtd::UserRole::STUDENT) { - student_call_back_query(bot, query, chat_id, users); + student_call_back_query(bot, query, user); } else if (user->get_role() == mtd::UserRole::OFFICE_STAFF) { - office_staff_call_back_query(bot, query, chat_id, users); + office_staff_call_back_query(bot, query, user); + } + else if (user->get_role() == mtd::UserRole::TEACHER) { + teacher_call_back_query(bot, query, user); } - // for office staff }); From e66b74f8e9036b4f36c159e2ef70575842e9b81f Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 09:24:04 +0300 Subject: [PATCH 07/55] create tutor interface --- .gitignore | 1 + .idea/.gitignore | 8 + .idea/EntryPoint.iml | 2 + .idea/editor.xml | 580 +++++++++++++++++++++++++++++++++++++++++++ .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + inc/Tutor.hpp | 17 ++ inc/User.hpp | 6 +- src/Tutor.cpp | 56 +++++ src/User.cpp | 3 + src/main.cpp | 42 +++- 12 files changed, 727 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/EntryPoint.iml create mode 100644 .idea/editor.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 inc/Tutor.hpp create mode 100644 src/Tutor.cpp diff --git a/.gitignore b/.gitignore index cdd0af4..6e28cc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ + BotToken.hpp /build # Prerequisites diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/EntryPoint.iml b/.idea/EntryPoint.iml new file mode 100644 index 0000000..6d70257 --- /dev/null +++ b/.idea/EntryPoint.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..358b28b --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,580 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f1c67df --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f3c4a97 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/inc/Tutor.hpp b/inc/Tutor.hpp new file mode 100644 index 0000000..9d26416 --- /dev/null +++ b/inc/Tutor.hpp @@ -0,0 +1,17 @@ +#ifndef TUTOR_HPP_ +#define TUTOR_HPP_ + +#include "User.hpp" + +namespace mtd { +class Tutor : public User { +public: + Tutor(int64_t chat_id); + + TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; + TgBot::InlineKeyboardMarkup::Ptr get_menu() override; + TgBot::InlineKeyboardMarkup::Ptr back_button() override; +}; +} + +#endif \ No newline at end of file diff --git a/inc/User.hpp b/inc/User.hpp index ad8105c..4340332 100644 --- a/inc/User.hpp +++ b/inc/User.hpp @@ -2,18 +2,22 @@ #define USER_HPP_ #include +#include namespace mtd { enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; +enum class UserState { MENU, BUTTONS, INFORMATION, NONE }; class User { int64_t chat_id = 0; UserRole role = UserRole::NONE; + UserState state = UserState::NONE; public: - explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role) {} + explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) {} virtual ~User() {} int64_t id() const; UserRole get_role() const; + UserState &get_state(); virtual TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() = 0; virtual TgBot::InlineKeyboardMarkup::Ptr get_menu() = 0; virtual TgBot::InlineKeyboardMarkup::Ptr back_button() = 0; diff --git a/src/Tutor.cpp b/src/Tutor.cpp new file mode 100644 index 0000000..f30bbfb --- /dev/null +++ b/src/Tutor.cpp @@ -0,0 +1,56 @@ +#include "Tutor.hpp" + +namespace mtd { +Tutor::Tutor(int64_t chat_id) : User(chat_id, UserRole::TUTOR) {} + +TgBot::InlineKeyboardMarkup::Ptr Tutor::get_inline_keyboard() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + // Добавление кнопки для добавления предмета + TgBot::InlineKeyboardButton::Ptr add_subject(new TgBot::InlineKeyboardButton); + add_subject->text = "Добавить предмет"; + add_subject->callbackData = "tutor_add_subject"; + inline_keyboard->inlineKeyboard.push_back({add_subject}); + + // Добавление кнопки для добавления людей в группы + TgBot::InlineKeyboardButton::Ptr add_people(new TgBot::InlineKeyboardButton); + add_people->text = "Добавить людей в группы"; + add_people->callbackData = "tutor_add_people"; + inline_keyboard->inlineKeyboard.push_back({add_people}); + + // Добавление кнопки для создания SOP + TgBot::InlineKeyboardButton::Ptr create_sop(new TgBot::InlineKeyboardButton); + create_sop->text = "Создать SOP"; + create_sop->callbackData = "tutor_create_sop"; + inline_keyboard->inlineKeyboard.push_back({create_sop}); + + // Добавление кнопки "Назад" + TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); + back->text = "🔙 Назад"; + back->callbackData = "tutor_back"; + inline_keyboard->inlineKeyboard.push_back({back}); + + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Tutor::get_menu() { + TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); + + // Пример кнопки меню (можно добавить другие кнопки по необходимости) + TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); + buttons->text = "Меню для куратора"; + buttons->callbackData = "tutor_buttons"; + + inline_keyboard->inlineKeyboard.push_back({buttons}); + return inline_keyboard; +} + +TgBot::InlineKeyboardMarkup::Ptr Tutor::back_button() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "🔙 Назад"; + button->callbackData = "tutor_back"; + keyboard->inlineKeyboard.push_back({button}); + return keyboard; +} +} diff --git a/src/User.cpp b/src/User.cpp index 54b80d3..5f8c341 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -7,4 +7,7 @@ int64_t User::id() const { UserRole User::get_role() const { return role; } +UserState &User::get_state() { + return state; +} } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 67ea938..210ef73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "Tutor.hpp" void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { int64_t chat_id = user->id(); @@ -78,6 +79,25 @@ void teacher_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, } } +void tutor_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { + int64_t chat_id = user->id(); + if (query->data == "tutor_buttons") { + bot.getApi().sendMessage(chat_id, "fsdf", 0, 0, user->get_inline_keyboard()); + } + else if (query->data == "tutor_add_subject") { + bot.getApi().sendMessage(chat_id, "Введите название нового предмета", 0, 0, user->get_inline_keyboard()); + } + else if (query->data == "tutor_add_people") { + bot.getApi().sendMessage(chat_id, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->get_inline_keyboard()); + } + else if (query->data == "tutor_create_sop") { + bot.getApi().sendMessage(chat_id, "Введите данные для создания SOP", 0, 0, user->get_inline_keyboard()); + } + else if (query->data == "tutor_back") { + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); + } +} + int main() { TgBot::Bot bot(mtd::token); std::map> users; @@ -101,9 +121,14 @@ int main() { b3->text = "Преподаватель"; b3->callbackData = "teacher"; + TgBot::InlineKeyboardButton::Ptr b4(new TgBot::InlineKeyboardButton); + b4->text = "Куратор"; + b4->callbackData = "tutor"; + keyboard->inlineKeyboard.push_back({b1}); keyboard->inlineKeyboard.push_back({b2}); keyboard->inlineKeyboard.push_back({b3}); + keyboard->inlineKeyboard.push_back({b4}); bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); }); @@ -111,10 +136,11 @@ int main() { bot.getEvents().onCallbackQuery([&bot, &users, &mutex_for_users, &new_users](TgBot::CallbackQuery::Ptr query) { std::lock_guard lock(mutex_for_users); int64_t chat_id = query->message->chat->id; + if (users.find(chat_id) == users.end()) { std::cout << "=== Error ===\n"; } - + if (new_users.find(chat_id) != new_users.end()) { if (query->data == "student") { auto student_ptr = std::make_shared(chat_id); @@ -128,13 +154,16 @@ int main() { auto teacher_ptr = std::make_shared(chat_id); users.insert({chat_id, teacher_ptr}); } - + else if (query->data == "tutor") { + auto tutor_ptr = std::make_shared(chat_id); + users.insert({chat_id, tutor_ptr}); + } + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); new_users.erase(chat_id); return; } - - + auto &user = users[chat_id]; if (user->get_role() == mtd::UserRole::STUDENT) { student_call_back_query(bot, query, user); @@ -145,7 +174,10 @@ int main() { else if (user->get_role() == mtd::UserRole::TEACHER) { teacher_call_back_query(bot, query, user); } - + else if (user->get_role() == mtd::UserRole::TUTOR) { + std::cout << "tutor\n"; + tutor_call_back_query(bot, query, user); + } }); try { From 39c2fb1f3ac6d82b1f43d6908e5f6ccfb8ad92db Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 13:01:07 +0300 Subject: [PATCH 08/55] create sop basic --- inc/User.hpp | 7 ++++- src/Student.cpp | 6 +++++ src/Tutor.cpp | 5 ++++ src/User.cpp | 6 +++++ src/main.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/inc/User.hpp b/inc/User.hpp index 4340332..6459b3b 100644 --- a/inc/User.hpp +++ b/inc/User.hpp @@ -3,21 +3,26 @@ #include #include +#include namespace mtd { enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; -enum class UserState { MENU, BUTTONS, INFORMATION, NONE }; +enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, NONE }; class User { int64_t chat_id = 0; UserRole role = UserRole::NONE; UserState state = UserState::NONE; + int step = 0; + std::vector evaluations; public: explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) {} virtual ~User() {} int64_t id() const; UserRole get_role() const; UserState &get_state(); + int &get_step(); + std::vector &get_evaluations(); virtual TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() = 0; virtual TgBot::InlineKeyboardMarkup::Ptr get_menu() = 0; virtual TgBot::InlineKeyboardMarkup::Ptr back_button() = 0; diff --git a/src/Student.cpp b/src/Student.cpp index 7db34c5..f65dbce 100644 --- a/src/Student.cpp +++ b/src/Student.cpp @@ -24,11 +24,17 @@ TgBot::InlineKeyboardMarkup::Ptr Student::get_inline_keyboard() { back->text = "🔙 Назад"; back->callbackData = "student_back"; + TgBot::InlineKeyboardButton::Ptr sop(new TgBot::InlineKeyboardButton); + sop->text = "Пройти СОП"; + sop->callbackData = "student_sop"; + inline_keyboard->inlineKeyboard.push_back({time_table}); inline_keyboard->inlineKeyboard.push_back({declaration}); inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); inline_keyboard->inlineKeyboard.push_back({help}); + inline_keyboard->inlineKeyboard.push_back({sop}); inline_keyboard->inlineKeyboard.push_back({back}); + return inline_keyboard; } diff --git a/src/Tutor.cpp b/src/Tutor.cpp index f30bbfb..7248c9c 100644 --- a/src/Tutor.cpp +++ b/src/Tutor.cpp @@ -24,6 +24,11 @@ TgBot::InlineKeyboardMarkup::Ptr Tutor::get_inline_keyboard() { create_sop->callbackData = "tutor_create_sop"; inline_keyboard->inlineKeyboard.push_back({create_sop}); + TgBot::InlineKeyboardButton::Ptr view_sop(new TgBot::InlineKeyboardButton); + view_sop->text = "Посмотреть СОП"; + view_sop->callbackData = "tutor_view_sop"; + inline_keyboard->inlineKeyboard.push_back({view_sop}); + // Добавление кнопки "Назад" TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); back->text = "🔙 Назад"; diff --git a/src/User.cpp b/src/User.cpp index 5f8c341..dea5ad0 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -1,6 +1,12 @@ #include "User.hpp" namespace mtd { +int &User::get_step() { + return step; +} +std::vector &User::get_evaluations() { + return evaluations; +} int64_t User::id() const { return chat_id; } diff --git a/src/main.cpp b/src/main.cpp index 210ef73..d84fba5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,59 @@ #include #include "BotToken.hpp" -#include #include "User.hpp" #include "Student.hpp" #include "OfficeStaff.hpp" #include "Teacher.hpp" +#include "Tutor.hpp" +#include #include #include #include -#include "Tutor.hpp" +#include + + + +TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + // Создаем кнопки от 1 до 10 + for (int i = 1; i < 11; ++i) { + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = std::to_string(i); + button->callbackData = std::to_string(i); // Колбек-данные соответствуют цифре + keyboard->inlineKeyboard.push_back({button}); // Добавляем кнопки в строку клавиатуры + } + return keyboard; +} void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { int64_t chat_id = user->id(); + if (query->data == "1" || query->data == "2" || query->data == "3" || query->data == "4" || + query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" || + query->data == "9" || query->data == "10") { + + bot.getApi().sendMessage(chat_id, "Этого лоха ты оценил на " + query->data + ".\nИзменить свой выбор нельзя("); + user->get_evaluations().push_back(std::stoi(query->data)); + // Следующий вопрос + if (user->get_step() < 5) { + bot.getApi().sendMessage(chat_id, "Вопрос " + std::to_string(user->get_step() + 1), 0, 0, get_raiting_scale()); + user->get_step()++; // Переход к следующему вопросу + } else { + bot.getApi().sendMessage(chat_id, "Опрос завершен. Спасибо за участие!", 0, 0, user->back_button()); + user->get_state() = mtd::UserState::NONE; + user->get_step() = 0; + } + } + + //--------------------------------- + //--------------------------------- if (query->data == "student_buttons") { bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, user->get_inline_keyboard()); } + else if (query->data == "student_sop" && user->get_step() == 0) { + bot.getApi().sendMessage(chat_id, "Вопрос 1", 0, 0, get_raiting_scale()); + user->get_step()++; + user->get_state() = mtd::UserState::STUDENT_SOP; + } else if (query->data == "student_time_table") { bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, user->get_inline_keyboard()); } @@ -87,6 +126,11 @@ void tutor_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, st else if (query->data == "tutor_add_subject") { bot.getApi().sendMessage(chat_id, "Введите название нового предмета", 0, 0, user->get_inline_keyboard()); } + else if (query->data == "tutor_view_sop") { + user->get_state() = mtd::UserState::TUTOR_SOP; + bot.getApi().sendMessage(chat_id, "Введите id пользователя"); + + } else if (query->data == "tutor_add_people") { bot.getApi().sendMessage(chat_id, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->get_inline_keyboard()); } @@ -107,7 +151,7 @@ int main() { bot.getEvents().onCommand("start", [&bot, &users, &mutex_for_users, &new_users](TgBot::Message::Ptr message) { std::lock_guard lock(mutex_for_users); new_users.insert(message->chat->id); - + std::cout << "User connect: " << message->chat->id << '\n'; TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr b1(new TgBot::InlineKeyboardButton); b1->text = "Студент"; @@ -175,11 +219,31 @@ int main() { teacher_call_back_query(bot, query, user); } else if (user->get_role() == mtd::UserRole::TUTOR) { - std::cout << "tutor\n"; + tutor_call_back_query(bot, query, user); } }); + bot.getEvents().onAnyMessage([&bot, &users, &mutex_for_users](TgBot::Message::Ptr message){ + std::lock_guard lock(mutex_for_users); + int64_t chat_id = message->chat->id; + + if (users.find(chat_id) == users.end()) { + std::cout << "=== Error 2 ===\n"; + return; + } + auto &user = users[chat_id]; + + if (user->get_state() == mtd::UserState::TUTOR_SOP) { + int64_t student_chat_id = static_cast(std::stoll(message->text)); + std::string s; + for (const auto i : users[student_chat_id]->get_evaluations()) { + s += std::to_string(i) + " "; + } + bot.getApi().sendMessage(chat_id, "Оценки этого студента:\n" + s, 0, 0, user->back_button()); + return; + } + }); try { std::cout << "Bot is running...\n"; TgBot::TgLongPoll longPoll(bot); From e6e5c60f7f21f7d15f7781abecd05671d10620a8 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 13:30:23 +0300 Subject: [PATCH 09/55] fdsfd --- .gitignore | 2 + .idea/.gitignore | 8 - .idea/EntryPoint.iml | 2 - .idea/editor.xml | 580 ------------------------------------------ .idea/misc.xml | 4 - .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .vscode/settings.json | 79 ------ 8 files changed, 2 insertions(+), 687 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/EntryPoint.iml delete mode 100644 .idea/editor.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 6e28cc9..fcff799 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ BotToken.hpp /build +.vscode/ +.idea/ # Prerequisites *.d diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 1c2fda5..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/EntryPoint.iml b/.idea/EntryPoint.iml deleted file mode 100644 index 6d70257..0000000 --- a/.idea/EntryPoint.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml deleted file mode 100644 index 358b28b..0000000 --- a/.idea/editor.xml +++ /dev/null @@ -1,580 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f1c67df..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index f3c4a97..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index c8397c9..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 63e0ee4..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "files.associations": { - "compare": "cpp", - "cstdint": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "any": "cpp", - "array": "cpp", - "atomic": "cpp", - "strstream": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "charconv": "cpp", - "chrono": "cpp", - "codecvt": "cpp", - "complex": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "coroutine": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "source_location": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "semaphore": "cpp", - "shared_mutex": "cpp", - "span": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cinttypes": "cpp", - "typeindex": "cpp", - "typeinfo": "cpp", - "variant": "cpp", - "format": "cpp" - } -} \ No newline at end of file From 3e1e8f4b54054c45a7686f527a65d81d306a6ba6 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 13:56:38 +0300 Subject: [PATCH 10/55] new codestyle --- inc/OfficeStaff.hpp | 6 ++-- inc/Student.hpp | 6 ++-- inc/Teacher.hpp | 6 ++-- inc/Tutor.hpp | 6 ++-- inc/User.hpp | 14 ++++---- src/OfficeStaff.cpp | 40 ++++++++++----------- src/Student.cpp | 34 +++++++++--------- src/Teacher.cpp | 22 ++++++------ src/Tutor.cpp | 44 +++++++++++------------ src/User.cpp | 8 ++--- src/main.cpp | 86 ++++++++++++++++++++++----------------------- 11 files changed, 136 insertions(+), 136 deletions(-) diff --git a/inc/OfficeStaff.hpp b/inc/OfficeStaff.hpp index 8088759..788fcdb 100644 --- a/inc/OfficeStaff.hpp +++ b/inc/OfficeStaff.hpp @@ -7,9 +7,9 @@ namespace mtd { class OfficeStaff : public User { public: OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} - TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; - TgBot::InlineKeyboardMarkup::Ptr get_menu() override; - TgBot::InlineKeyboardMarkup::Ptr back_button() override; + TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; + TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; + TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; } diff --git a/inc/Student.hpp b/inc/Student.hpp index c2cdf27..5bc2890 100644 --- a/inc/Student.hpp +++ b/inc/Student.hpp @@ -7,9 +7,9 @@ namespace mtd { class Student : public User { public: Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} - TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; - TgBot::InlineKeyboardMarkup::Ptr get_menu() override; - TgBot::InlineKeyboardMarkup::Ptr back_button() override; + TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; + TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; + TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; } diff --git a/inc/Teacher.hpp b/inc/Teacher.hpp index 0858a6c..878cf4f 100644 --- a/inc/Teacher.hpp +++ b/inc/Teacher.hpp @@ -7,9 +7,9 @@ namespace mtd { class Teacher : public User { public: Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) {} - TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; - TgBot::InlineKeyboardMarkup::Ptr get_menu() override; - TgBot::InlineKeyboardMarkup::Ptr back_button() override; + TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; + TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; + TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; } diff --git a/inc/Tutor.hpp b/inc/Tutor.hpp index 9d26416..1d3c70d 100644 --- a/inc/Tutor.hpp +++ b/inc/Tutor.hpp @@ -8,9 +8,9 @@ class Tutor : public User { public: Tutor(int64_t chat_id); - TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() override; - TgBot::InlineKeyboardMarkup::Ptr get_menu() override; - TgBot::InlineKeyboardMarkup::Ptr back_button() override; + TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; + TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; + TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; } diff --git a/inc/User.hpp b/inc/User.hpp index 6459b3b..c40a471 100644 --- a/inc/User.hpp +++ b/inc/User.hpp @@ -19,13 +19,13 @@ class User { explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) {} virtual ~User() {} int64_t id() const; - UserRole get_role() const; - UserState &get_state(); - int &get_step(); - std::vector &get_evaluations(); - virtual TgBot::InlineKeyboardMarkup::Ptr get_inline_keyboard() = 0; - virtual TgBot::InlineKeyboardMarkup::Ptr get_menu() = 0; - virtual TgBot::InlineKeyboardMarkup::Ptr back_button() = 0; + UserRole GetRole() const; + UserState &GetState(); + int &GetStep(); + std::vector &GetEvaluations(); + virtual TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() = 0; + virtual TgBot::InlineKeyboardMarkup::Ptr GetMenu() = 0; + virtual TgBot::InlineKeyboardMarkup::Ptr BackButton() = 0; }; } diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp index ac6f61d..020025e 100644 --- a/src/OfficeStaff.cpp +++ b/src/OfficeStaff.cpp @@ -1,44 +1,44 @@ #include "OfficeStaff.hpp" namespace mtd { -TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_inline_keyboard() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::GetInlineKeyboard() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); - TgBot::InlineKeyboardButton::Ptr time_table(new TgBot::InlineKeyboardButton); - time_table->text = "📅 Расписание"; - time_table->callbackData = "office_staff_time_table"; + TgBot::InlineKeyboardButton::Ptr timeTable(new TgBot::InlineKeyboardButton); + timeTable->text = "📅 Расписание"; + timeTable->callbackData = "office_staff_time_table"; TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); declaration->text = "📢 Объявления"; declaration->callbackData = "office_staff_declaration"; - TgBot::InlineKeyboardButton::Ptr connect_with_teacher(new TgBot::InlineKeyboardButton); - connect_with_teacher->text = "📩 Связь с преподавателем"; - connect_with_teacher->callbackData = "office_staff_connect_with_teacher"; + TgBot::InlineKeyboardButton::Ptr connectWithTeacher(new TgBot::InlineKeyboardButton); + connectWithTeacher->text = "📩 Связь с преподавателем"; + connectWithTeacher->callbackData = "office_staff_connect_with_teacher"; TgBot::InlineKeyboardButton::Ptr help(new TgBot::InlineKeyboardButton); help->text = "❓ Помощь"; help->callbackData = "office_staff_help"; // ЗДЕСЬ КАКОЙ_ТО ПИЗДЕЦ - TgBot::InlineKeyboardButton::Ptr add_info(new TgBot::InlineKeyboardButton); - add_info->text = "Добавить информацию"; - add_info->callbackData = "office_add_info"; + TgBot::InlineKeyboardButton::Ptr addInfo(new TgBot::InlineKeyboardButton); + addInfo->text = "Добавить информацию"; + addInfo->callbackData = "office_add_info"; TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); back->text = "🔙 Назад"; back->callbackData = "office_staff_back"; - inline_keyboard->inlineKeyboard.push_back({time_table}); - inline_keyboard->inlineKeyboard.push_back({declaration}); - inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); - inline_keyboard->inlineKeyboard.push_back({help}); - inline_keyboard->inlineKeyboard.push_back({add_info}); - inline_keyboard->inlineKeyboard.push_back({back}); - return inline_keyboard; + inlineKeyboard->inlineKeyboard.push_back({timeTable}); + inlineKeyboard->inlineKeyboard.push_back({declaration}); + inlineKeyboard->inlineKeyboard.push_back({connectWithTeacher}); + inlineKeyboard->inlineKeyboard.push_back({help}); + inlineKeyboard->inlineKeyboard.push_back({addInfo}); + inlineKeyboard->inlineKeyboard.push_back({back}); + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_menu() { +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::GetMenu() { TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); @@ -55,7 +55,7 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::get_menu() { return inline_keyboard; } -TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::back_button() { +TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::BackButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = "🔙 Назад"; diff --git a/src/Student.cpp b/src/Student.cpp index f65dbce..a035d08 100644 --- a/src/Student.cpp +++ b/src/Student.cpp @@ -1,20 +1,20 @@ #include "Student.hpp" namespace mtd { -TgBot::InlineKeyboardMarkup::Ptr Student::get_inline_keyboard() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr Student::GetInlineKeyboard() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); - TgBot::InlineKeyboardButton::Ptr time_table(new TgBot::InlineKeyboardButton); - time_table->text = "📅 Расписание"; - time_table->callbackData = "student_time_table"; + TgBot::InlineKeyboardButton::Ptr timeTable(new TgBot::InlineKeyboardButton); + timeTable->text = "📅 Расписание"; + timeTable->callbackData = "student_time_table"; TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); declaration->text = "📢 Объявления"; declaration->callbackData = "student_declaration"; - TgBot::InlineKeyboardButton::Ptr connect_with_teacher(new TgBot::InlineKeyboardButton); - connect_with_teacher->text = "📩 Связь с преподавателем"; - connect_with_teacher->callbackData = "student_connect_with_teacher"; + TgBot::InlineKeyboardButton::Ptr connectWithTeacher(new TgBot::InlineKeyboardButton); + connectWithTeacher->text = "📩 Связь с преподавателем"; + connectWithTeacher->callbackData = "student_connect_with_teacher"; TgBot::InlineKeyboardButton::Ptr help(new TgBot::InlineKeyboardButton); help->text = "❓ Помощь"; @@ -28,17 +28,17 @@ TgBot::InlineKeyboardMarkup::Ptr Student::get_inline_keyboard() { sop->text = "Пройти СОП"; sop->callbackData = "student_sop"; - inline_keyboard->inlineKeyboard.push_back({time_table}); - inline_keyboard->inlineKeyboard.push_back({declaration}); - inline_keyboard->inlineKeyboard.push_back({connect_with_teacher}); - inline_keyboard->inlineKeyboard.push_back({help}); - inline_keyboard->inlineKeyboard.push_back({sop}); - inline_keyboard->inlineKeyboard.push_back({back}); + inlineKeyboard->inlineKeyboard.push_back({timeTable}); + inlineKeyboard->inlineKeyboard.push_back({declaration}); + inlineKeyboard->inlineKeyboard.push_back({connectWithTeacher}); + inlineKeyboard->inlineKeyboard.push_back({help}); + inlineKeyboard->inlineKeyboard.push_back({sop}); + inlineKeyboard->inlineKeyboard.push_back({back}); - return inline_keyboard; + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr Student::get_menu() { +TgBot::InlineKeyboardMarkup::Ptr Student::GetMenu() { TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); @@ -55,7 +55,7 @@ TgBot::InlineKeyboardMarkup::Ptr Student::get_menu() { return inline_keyboard; } -TgBot::InlineKeyboardMarkup::Ptr Student::back_button() { +TgBot::InlineKeyboardMarkup::Ptr Student::BackButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = "🔙 Назад"; diff --git a/src/Teacher.cpp b/src/Teacher.cpp index 09d4b7e..a0a2577 100644 --- a/src/Teacher.cpp +++ b/src/Teacher.cpp @@ -1,24 +1,24 @@ #include "Teacher.hpp" namespace mtd { -TgBot::InlineKeyboardMarkup::Ptr Teacher::get_inline_keyboard() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr Teacher::GetInlineKeyboard() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr declaration(new TgBot::InlineKeyboardButton); declaration->text = "Уведомление студентам"; declaration->callbackData = "teacher_declaration"; - inline_keyboard->inlineKeyboard.push_back({declaration}); + inlineKeyboard->inlineKeyboard.push_back({declaration}); TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); back->text = "🔙 Назад"; back->callbackData = "teacher_back"; - inline_keyboard->inlineKeyboard.push_back({back}); + inlineKeyboard->inlineKeyboard.push_back({back}); - return inline_keyboard; + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr Teacher::get_menu() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr Teacher::GetMenu() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); buttons->text = "кнопочки"; @@ -29,13 +29,13 @@ TgBot::InlineKeyboardMarkup::Ptr Teacher::get_menu() { information->callbackData = "teachert_information"; - inline_keyboard->inlineKeyboard.push_back({buttons}); - inline_keyboard->inlineKeyboard.push_back({information}); + inlineKeyboard->inlineKeyboard.push_back({buttons}); + inlineKeyboard->inlineKeyboard.push_back({information}); - return inline_keyboard; + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr Teacher::back_button() { +TgBot::InlineKeyboardMarkup::Ptr Teacher::BackButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = "🔙 Назад"; diff --git a/src/Tutor.cpp b/src/Tutor.cpp index 7248c9c..7e2b374 100644 --- a/src/Tutor.cpp +++ b/src/Tutor.cpp @@ -3,54 +3,54 @@ namespace mtd { Tutor::Tutor(int64_t chat_id) : User(chat_id, UserRole::TUTOR) {} -TgBot::InlineKeyboardMarkup::Ptr Tutor::get_inline_keyboard() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr Tutor::GetInlineKeyboard() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); // Добавление кнопки для добавления предмета - TgBot::InlineKeyboardButton::Ptr add_subject(new TgBot::InlineKeyboardButton); - add_subject->text = "Добавить предмет"; - add_subject->callbackData = "tutor_add_subject"; - inline_keyboard->inlineKeyboard.push_back({add_subject}); + TgBot::InlineKeyboardButton::Ptr addSubject(new TgBot::InlineKeyboardButton); + addSubject->text = "Добавить предмет"; + addSubject->callbackData = "tutor_add_subject"; + inlineKeyboard->inlineKeyboard.push_back({addSubject}); // Добавление кнопки для добавления людей в группы - TgBot::InlineKeyboardButton::Ptr add_people(new TgBot::InlineKeyboardButton); - add_people->text = "Добавить людей в группы"; - add_people->callbackData = "tutor_add_people"; - inline_keyboard->inlineKeyboard.push_back({add_people}); + TgBot::InlineKeyboardButton::Ptr addPeople(new TgBot::InlineKeyboardButton); + addPeople->text = "Добавить людей в группы"; + addPeople->callbackData = "tutor_add_people"; + inlineKeyboard->inlineKeyboard.push_back({addPeople}); // Добавление кнопки для создания SOP - TgBot::InlineKeyboardButton::Ptr create_sop(new TgBot::InlineKeyboardButton); - create_sop->text = "Создать SOP"; - create_sop->callbackData = "tutor_create_sop"; - inline_keyboard->inlineKeyboard.push_back({create_sop}); + TgBot::InlineKeyboardButton::Ptr createSop(new TgBot::InlineKeyboardButton); + createSop->text = "Создать SOP"; + createSop->callbackData = "tutor_create_sop"; + inlineKeyboard->inlineKeyboard.push_back({createSop}); TgBot::InlineKeyboardButton::Ptr view_sop(new TgBot::InlineKeyboardButton); view_sop->text = "Посмотреть СОП"; view_sop->callbackData = "tutor_view_sop"; - inline_keyboard->inlineKeyboard.push_back({view_sop}); + inlineKeyboard->inlineKeyboard.push_back({view_sop}); // Добавление кнопки "Назад" TgBot::InlineKeyboardButton::Ptr back(new TgBot::InlineKeyboardButton); back->text = "🔙 Назад"; back->callbackData = "tutor_back"; - inline_keyboard->inlineKeyboard.push_back({back}); + inlineKeyboard->inlineKeyboard.push_back({back}); - return inline_keyboard; + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr Tutor::get_menu() { - TgBot::InlineKeyboardMarkup::Ptr inline_keyboard(new TgBot::InlineKeyboardMarkup); +TgBot::InlineKeyboardMarkup::Ptr Tutor::GetMenu() { + TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); // Пример кнопки меню (можно добавить другие кнопки по необходимости) TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); buttons->text = "Меню для куратора"; buttons->callbackData = "tutor_buttons"; - inline_keyboard->inlineKeyboard.push_back({buttons}); - return inline_keyboard; + inlineKeyboard->inlineKeyboard.push_back({buttons}); + return inlineKeyboard; } -TgBot::InlineKeyboardMarkup::Ptr Tutor::back_button() { +TgBot::InlineKeyboardMarkup::Ptr Tutor::BackButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = "🔙 Назад"; diff --git a/src/User.cpp b/src/User.cpp index dea5ad0..3d8a8a6 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -1,19 +1,19 @@ #include "User.hpp" namespace mtd { -int &User::get_step() { +int &User::GetStep() { return step; } -std::vector &User::get_evaluations() { +std::vector &User::GetEvaluations() { return evaluations; } int64_t User::id() const { return chat_id; } -UserRole User::get_role() const { +UserRole User::GetRole() const { return role; } -UserState &User::get_state() { +UserState &User::GetState() { return state; } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d84fba5..fcf2c2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,113 +32,113 @@ void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, query->data == "9" || query->data == "10") { bot.getApi().sendMessage(chat_id, "Этого лоха ты оценил на " + query->data + ".\nИзменить свой выбор нельзя("); - user->get_evaluations().push_back(std::stoi(query->data)); + user->GetEvaluations().push_back(std::stoi(query->data)); // Следующий вопрос - if (user->get_step() < 5) { - bot.getApi().sendMessage(chat_id, "Вопрос " + std::to_string(user->get_step() + 1), 0, 0, get_raiting_scale()); - user->get_step()++; // Переход к следующему вопросу + if (user->GetStep() < 5) { + bot.getApi().sendMessage(chat_id, "Вопрос " + std::to_string(user->GetStep() + 1), 0, 0, get_raiting_scale()); + user->GetStep()++; // Переход к следующему вопросу } else { - bot.getApi().sendMessage(chat_id, "Опрос завершен. Спасибо за участие!", 0, 0, user->back_button()); - user->get_state() = mtd::UserState::NONE; - user->get_step() = 0; + bot.getApi().sendMessage(chat_id, "Опрос завершен. Спасибо за участие!", 0, 0, user->BackButton()); + user->GetState() = mtd::UserState::NONE; + user->GetStep() = 0; } } //--------------------------------- //--------------------------------- if (query->data == "student_buttons") { - bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, user->GetInlineKeyboard()); } - else if (query->data == "student_sop" && user->get_step() == 0) { + else if (query->data == "student_sop" && user->GetStep() == 0) { bot.getApi().sendMessage(chat_id, "Вопрос 1", 0, 0, get_raiting_scale()); - user->get_step()++; - user->get_state() = mtd::UserState::STUDENT_SOP; + user->GetStep()++; + user->GetState() = mtd::UserState::STUDENT_SOP; } else if (query->data == "student_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_help") { - bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); } else if (query->data == "student_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, user->back_button()); + bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, user->BackButton()); } } void office_staff_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { int64_t chat_id = user->id(); if (query->data == "office_staff_buttons") { - bot.getApi().sendMessage(chat_id, "Кнопочки", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Кнопочки", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "office_staff_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "office_staff_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "office_staff_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "office_staff_help") { - bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "office_staff_back") { - bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, user->get_menu()); + bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, user->GetMenu()); } else if (query->data == "office_staff_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, user->back_button()); + bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, user->BackButton()); } else if (query->data == "office_add_info") { - bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, user->GetInlineKeyboard()); } } void teacher_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { int64_t chat_id = user->id(); if (query->data == "teacher_declaration") { - bot.getApi().sendMessage(chat_id, "Вы преподаватель и вы можите сделать объявление", 0, 0, user->back_button()); + bot.getApi().sendMessage(chat_id, "Вы преподаватель и вы можите сделать объявление", 0, 0, user->BackButton()); } else if (query->data == "teacher_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); } else if (query->data == "teacher_buttons") { - bot.getApi().sendMessage(chat_id, "Кнопочки для преподов", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Кнопочки для преподов", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "teachert_information") { - bot.getApi().sendMessage(chat_id, "Какая-то полезная инва для преподов", 0, 0, user->back_button()); + bot.getApi().sendMessage(chat_id, "Какая-то полезная инва для преподов", 0, 0, user->BackButton()); } } void tutor_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { int64_t chat_id = user->id(); if (query->data == "tutor_buttons") { - bot.getApi().sendMessage(chat_id, "fsdf", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "fsdf", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_add_subject") { - bot.getApi().sendMessage(chat_id, "Введите название нового предмета", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Введите название нового предмета", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_view_sop") { - user->get_state() = mtd::UserState::TUTOR_SOP; + user->GetState() = mtd::UserState::TUTOR_SOP; bot.getApi().sendMessage(chat_id, "Введите id пользователя"); } else if (query->data == "tutor_add_people") { - bot.getApi().sendMessage(chat_id, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_create_sop") { - bot.getApi().sendMessage(chat_id, "Введите данные для создания SOP", 0, 0, user->get_inline_keyboard()); + bot.getApi().sendMessage(chat_id, "Введите данные для создания SOP", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->get_menu()); + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); } } @@ -203,22 +203,22 @@ int main() { users.insert({chat_id, tutor_ptr}); } - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->get_menu()); + bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->GetMenu()); new_users.erase(chat_id); return; } auto &user = users[chat_id]; - if (user->get_role() == mtd::UserRole::STUDENT) { + if (user->GetRole() == mtd::UserRole::STUDENT) { student_call_back_query(bot, query, user); } - else if (user->get_role() == mtd::UserRole::OFFICE_STAFF) { + else if (user->GetRole() == mtd::UserRole::OFFICE_STAFF) { office_staff_call_back_query(bot, query, user); } - else if (user->get_role() == mtd::UserRole::TEACHER) { + else if (user->GetRole() == mtd::UserRole::TEACHER) { teacher_call_back_query(bot, query, user); } - else if (user->get_role() == mtd::UserRole::TUTOR) { + else if (user->GetRole() == mtd::UserRole::TUTOR) { tutor_call_back_query(bot, query, user); } @@ -234,13 +234,13 @@ int main() { } auto &user = users[chat_id]; - if (user->get_state() == mtd::UserState::TUTOR_SOP) { + if (user->GetState() == mtd::UserState::TUTOR_SOP) { int64_t student_chat_id = static_cast(std::stoll(message->text)); std::string s; - for (const auto i : users[student_chat_id]->get_evaluations()) { + for (const auto i : users[student_chat_id]->GetEvaluations()) { s += std::to_string(i) + " "; } - bot.getApi().sendMessage(chat_id, "Оценки этого студента:\n" + s, 0, 0, user->back_button()); + bot.getApi().sendMessage(chat_id, "Оценки этого студента:\n" + s, 0, 0, user->BackButton()); return; } }); From 3cd1c75475735a83ac4d0f3814d87cf489f93749 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 15:00:15 +0300 Subject: [PATCH 11/55] create two files --- .clang-format | 29 ++++ .clang-tidy | 6 + CMakeLists.txt | 12 +- README.md | 6 + inc/OfficeStaff.hpp | 7 +- inc/Student.hpp | 8 +- inc/Teacher.hpp | 4 +- inc/Tutor.hpp | 4 +- inc/User.hpp | 13 +- src/OfficeStaff.cpp | 3 +- src/Student.cpp | 5 +- src/Teacher.cpp | 5 +- src/Tutor.cpp | 7 +- src/User.cpp | 2 +- src/main.cpp | 350 ++++++++++++++++++++++---------------------- 15 files changed, 243 insertions(+), 218 deletions(-) create mode 100644 .clang-format create mode 100644 .clang-tidy diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5147b7f --- /dev/null +++ b/.clang-format @@ -0,0 +1,29 @@ +--- +BasedOnStyle: Google # Используем Google Style как основу + +# Выравнивание и отступы +AccessModifierOffset: -2 # Смещение модификаторов доступа (private, public) влево +AlignTrailingComments: true # Выравнивание комментариев +IndentPPDirectives: AfterHash # Директивы препроцессора (#define, #include) выравниваются после # +IndentWidth: 4 # Отступ в 4 пробела +NamespaceIndentation: None # Без отступов внутри namespace + +# Форматирование скобок и операторов +BreakBeforeBraces: Attach # Фигурные скобки остаются на той же строке, что и выражение +BreakBeforeBinaryOperators: All # Перенос бинарных операторов (+, -, *, /) на новую строку +BreakBeforeTernaryOperators: true # Перенос тернарных операторов (?:) на новую строку + +# Лимиты строк и форматирование длинных выражений +ColumnLimit: 100 # Максимальная длина строки 100 символов +ConstructorInitializerAllOnOneLineOrOnePerLine: true # Либо все инициализаторы конструктора в одной строке, либо каждый на новой + +# Включения (includes) +IncludeBlocks: Regroup # Группировать include'ы по категориям (стандартные, пользовательские, системные) +SortIncludes: true # Сортировать include'ы по алфавиту + +# Дополнительные улучшения читаемости +SpaceBeforeParens: ControlStatements # Пробел перед скобками у if, while, for, но не у вызовов функций +AllowShortFunctionsOnASingleLine: InlineOnly # Разрешать однострочные функции только в inline +AllowShortIfStatementsOnASingleLine: false # if всегда должен быть на новой строке +AllowShortLoopsOnASingleLine: false # Циклы тоже должны быть в отдельных строках +... diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e09ebde --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,6 @@ +Checks: "-*,boost-*,bugprone-*,concurrency-*,cppcoreguidelines-*,misc-*,modernize-*,performance-*,portability-*,readability-*,google-build-namespaces,google-build-using-namespace,google-global-names-in-headers,google-readability-casting,google-runtime-operator,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-*magic-numbers*,-*avoid-c-arrays*,-modernize-use-trailing-return-type,-readability-else-after-return,-readability-named-parameter,-readability-identifier-length,-bugprone-easily-swappable-parameters,-bugprone-exception-escape" +WarningsAsErrors: "*" +ExtraArgs: + - "-std=c++20" +ExtraArgsBefore: + - "-xc++" \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e239bd..f21a3b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(TelegramBot) # Указываем имя проекта set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Длдя генерации какого-то файлика clang-tidy # Поиск необходимых библиотек find_package(Boost REQUIRED COMPONENTS system) # Ищем Boost (модуль system) @@ -22,12 +23,7 @@ add_executable(my_bot ${SOURCES}) # Компилируем все найденн # Линкуем с найденными библиотеками target_link_libraries(my_bot Boost::system TgBot::TgBot) -# Включаем санитайзеры -# if(CMAKE_BUILD_TYPE STREQUAL "Debug") -# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") -# target_compile_options(my_bot PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) -# target_link_options(my_bot PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer) -# endif() + if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_options(my_bot PRIVATE -g @@ -38,6 +34,4 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") -fsanitize=address,undefined -fno-omit-frame-pointer ) -endif() -# cmake -DCMAKE_BUILD_TYPE=Debug .. -# make \ No newline at end of file +endif() \ No newline at end of file diff --git a/README.md b/README.md index 9c90fd7..7d83820 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,9 @@ ### Чуток описание проекта : Телеграмм-бот с авторизацией для студентов, преподавателей, администрации, организаторов учебного процесса (учебный офис, кураторы и т.п.). Среди базового функционала присутствуют: система анонимной студенческой оценки преподавания, система донесения информации от учебного офиса, преподавателей и кураторов до студентов c подтверждением получения (в т.ч. ссылок на чаты и объявлений). Возможность поддержания полезной информации о предметах внутри бота (ссылки, таблицы, папки, чаты, файлы) с возможностью изменения студентами (как wiki, просмотр изменений). +run-clang-tidy -p build/ (для запуска clang-format) + +rm -rf build # Удаляем старую директорию (если она есть) +mkdir build && cd build # Создаём новую папку и заходим в неё +cmake -G Ninja .. # Говорим CMake использовать Ninja +ninja # Собираем проект \ No newline at end of file diff --git a/inc/OfficeStaff.hpp b/inc/OfficeStaff.hpp index 788fcdb..ce889ec 100644 --- a/inc/OfficeStaff.hpp +++ b/inc/OfficeStaff.hpp @@ -5,13 +5,12 @@ namespace mtd { class OfficeStaff : public User { -public: - OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} + public: + OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; -} - +} // namespace mtd #endif diff --git a/inc/Student.hpp b/inc/Student.hpp index 5bc2890..460c054 100644 --- a/inc/Student.hpp +++ b/inc/Student.hpp @@ -5,14 +5,12 @@ namespace mtd { class Student : public User { -public: - Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} + public: + Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; -} - - +} // namespace mtd #endif \ No newline at end of file diff --git a/inc/Teacher.hpp b/inc/Teacher.hpp index 878cf4f..d3d3052 100644 --- a/inc/Teacher.hpp +++ b/inc/Teacher.hpp @@ -5,12 +5,12 @@ namespace mtd { class Teacher : public User { -public: + public: Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; -} +} // namespace mtd #endif \ No newline at end of file diff --git a/inc/Tutor.hpp b/inc/Tutor.hpp index 1d3c70d..bbdd114 100644 --- a/inc/Tutor.hpp +++ b/inc/Tutor.hpp @@ -5,13 +5,13 @@ namespace mtd { class Tutor : public User { -public: + public: Tutor(int64_t chat_id); TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; }; -} +} // namespace mtd #endif \ No newline at end of file diff --git a/inc/User.hpp b/inc/User.hpp index c40a471..d876720 100644 --- a/inc/User.hpp +++ b/inc/User.hpp @@ -2,11 +2,12 @@ #define USER_HPP_ #include + #include #include namespace mtd { -enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; +enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, NONE }; class User { @@ -15,9 +16,11 @@ class User { UserState state = UserState::NONE; int step = 0; std::vector evaluations; -public: - explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) {} - virtual ~User() {} + + public: + explicit User(int64_t chat_id, UserRole role) + : chat_id(chat_id), role(role), state(UserState::NONE) {} + virtual ~User() {} int64_t id() const; UserRole GetRole() const; UserState &GetState(); @@ -27,6 +30,6 @@ class User { virtual TgBot::InlineKeyboardMarkup::Ptr GetMenu() = 0; virtual TgBot::InlineKeyboardMarkup::Ptr BackButton() = 0; }; -} +} // namespace mtd #endif \ No newline at end of file diff --git a/src/OfficeStaff.cpp b/src/OfficeStaff.cpp index 020025e..4019a29 100644 --- a/src/OfficeStaff.cpp +++ b/src/OfficeStaff.cpp @@ -49,7 +49,6 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::GetMenu() { information->text = "Информация"; information->callbackData = "office_staff_information"; - inline_keyboard->inlineKeyboard.push_back({buttons}); inline_keyboard->inlineKeyboard.push_back({information}); return inline_keyboard; @@ -63,4 +62,4 @@ TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::BackButton() { keyboard->inlineKeyboard.push_back({button}); return keyboard; } -} \ No newline at end of file +} // namespace mtd \ No newline at end of file diff --git a/src/Student.cpp b/src/Student.cpp index a035d08..a30832f 100644 --- a/src/Student.cpp +++ b/src/Student.cpp @@ -34,7 +34,7 @@ TgBot::InlineKeyboardMarkup::Ptr Student::GetInlineKeyboard() { inlineKeyboard->inlineKeyboard.push_back({help}); inlineKeyboard->inlineKeyboard.push_back({sop}); inlineKeyboard->inlineKeyboard.push_back({back}); - + return inlineKeyboard; } @@ -49,7 +49,6 @@ TgBot::InlineKeyboardMarkup::Ptr Student::GetMenu() { information->text = "Информация"; information->callbackData = "student_information"; - inline_keyboard->inlineKeyboard.push_back({buttons}); inline_keyboard->inlineKeyboard.push_back({information}); return inline_keyboard; @@ -63,4 +62,4 @@ TgBot::InlineKeyboardMarkup::Ptr Student::BackButton() { keyboard->inlineKeyboard.push_back({button}); return keyboard; } -} \ No newline at end of file +} // namespace mtd \ No newline at end of file diff --git a/src/Teacher.cpp b/src/Teacher.cpp index a0a2577..3a3594d 100644 --- a/src/Teacher.cpp +++ b/src/Teacher.cpp @@ -14,7 +14,7 @@ TgBot::InlineKeyboardMarkup::Ptr Teacher::GetInlineKeyboard() { back->callbackData = "teacher_back"; inlineKeyboard->inlineKeyboard.push_back({back}); - return inlineKeyboard; + return inlineKeyboard; } TgBot::InlineKeyboardMarkup::Ptr Teacher::GetMenu() { @@ -28,7 +28,6 @@ TgBot::InlineKeyboardMarkup::Ptr Teacher::GetMenu() { information->text = "Информация"; information->callbackData = "teachert_information"; - inlineKeyboard->inlineKeyboard.push_back({buttons}); inlineKeyboard->inlineKeyboard.push_back({information}); @@ -43,4 +42,4 @@ TgBot::InlineKeyboardMarkup::Ptr Teacher::BackButton() { keyboard->inlineKeyboard.push_back({button}); return keyboard; } -} \ No newline at end of file +} // namespace mtd \ No newline at end of file diff --git a/src/Tutor.cpp b/src/Tutor.cpp index 7e2b374..1765eb7 100644 --- a/src/Tutor.cpp +++ b/src/Tutor.cpp @@ -1,7 +1,8 @@ #include "Tutor.hpp" namespace mtd { -Tutor::Tutor(int64_t chat_id) : User(chat_id, UserRole::TUTOR) {} +Tutor::Tutor(int64_t chat_id) : User(chat_id, UserRole::TUTOR) { +} TgBot::InlineKeyboardMarkup::Ptr Tutor::GetInlineKeyboard() { TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); @@ -45,7 +46,7 @@ TgBot::InlineKeyboardMarkup::Ptr Tutor::GetMenu() { TgBot::InlineKeyboardButton::Ptr buttons(new TgBot::InlineKeyboardButton); buttons->text = "Меню для куратора"; buttons->callbackData = "tutor_buttons"; - + inlineKeyboard->inlineKeyboard.push_back({buttons}); return inlineKeyboard; } @@ -58,4 +59,4 @@ TgBot::InlineKeyboardMarkup::Ptr Tutor::BackButton() { keyboard->inlineKeyboard.push_back({button}); return keyboard; } -} +} // namespace mtd diff --git a/src/User.cpp b/src/User.cpp index 3d8a8a6..9ac3d94 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -16,4 +16,4 @@ UserRole User::GetRole() const { UserState &User::GetState() { return state; } -} \ No newline at end of file +} // namespace mtd \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fcf2c2e..896c16a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,17 @@ #include -#include "BotToken.hpp" -#include "User.hpp" -#include "Student.hpp" -#include "OfficeStaff.hpp" -#include "Teacher.hpp" -#include "Tutor.hpp" + #include #include #include #include #include - +#include "BotToken.hpp" +#include "OfficeStaff.hpp" +#include "Student.hpp" +#include "Teacher.hpp" +#include "Tutor.hpp" +#include "User.hpp" TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); @@ -20,25 +20,28 @@ TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = std::to_string(i); button->callbackData = std::to_string(i); // Колбек-данные соответствуют цифре - keyboard->inlineKeyboard.push_back({button}); // Добавляем кнопки в строку клавиатуры + keyboard->inlineKeyboard.push_back({button}); // Добавляем кнопки в строку клавиатуры } return keyboard; } -void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { - int64_t chat_id = user->id(); - if (query->data == "1" || query->data == "2" || query->data == "3" || query->data == "4" || - query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" || - query->data == "9" || query->data == "10") { - - bot.getApi().sendMessage(chat_id, "Этого лоха ты оценил на " + query->data + ".\nИзменить свой выбор нельзя("); +void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, + std::shared_ptr user) { + int64_t ChatId = user->id(); + if (query->data == "1" || query->data == "2" || query->data == "3" || query->data == "4" + || query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" + || query->data == "9" || query->data == "10") { + bot.getApi().sendMessage( + ChatId, "Этого лоха ты оценил на " + query->data + ".\nИзменить свой выбор нельзя("); user->GetEvaluations().push_back(std::stoi(query->data)); // Следующий вопрос if (user->GetStep() < 5) { - bot.getApi().sendMessage(chat_id, "Вопрос " + std::to_string(user->GetStep() + 1), 0, 0, get_raiting_scale()); - user->GetStep()++; // Переход к следующему вопросу + bot.getApi().sendMessage(ChatId, "Вопрос " + std::to_string(user->GetStep() + 1), 0, 0, + get_raiting_scale()); + user->GetStep()++; // Переход к следующему вопросу } else { - bot.getApi().sendMessage(chat_id, "Опрос завершен. Спасибо за участие!", 0, 0, user->BackButton()); + bot.getApi().sendMessage(ChatId, "Опрос завершен. Спасибо за участие!", 0, 0, + user->BackButton()); user->GetState() = mtd::UserState::NONE; user->GetStep() = 0; } @@ -47,200 +50,189 @@ void student_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, //--------------------------------- //--------------------------------- if (query->data == "student_buttons") { - bot.getApi().sendMessage(chat_id, "fsfsdf", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "student_sop" && user->GetStep() == 0) { - bot.getApi().sendMessage(chat_id, "Вопрос 1", 0, 0, get_raiting_scale()); + bot.getApi().sendMessage(ChatId, "fsfsdf", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "student_sop" && user->GetStep() == 0) { + bot.getApi().sendMessage(ChatId, "Вопрос 1", 0, 0, get_raiting_scale()); user->GetStep()++; user->GetState() = mtd::UserState::STUDENT_SOP; - } - else if (query->data == "student_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "student_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "student_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "student_help") { - bot.getApi().sendMessage(chat_id, "Помощь", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "student_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); - } - else if (query->data == "student_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация", 0, 0, user->BackButton()); + } else if (query->data == "student_time_table") { + bot.getApi().sendMessage(ChatId, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "student_declaration") { + bot.getApi().sendMessage(ChatId, "Актуальные объявления", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "student_connect_with_teacher") { + bot.getApi().sendMessage(ChatId, "Списочек с контактами преподавателя", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "student_help") { + bot.getApi().sendMessage(ChatId, "Помощь", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "student_back") { + bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); + } else if (query->data == "student_information") { + bot.getApi().sendMessage(ChatId, "Какая-то информация", 0, 0, user->BackButton()); } } -void office_staff_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { - int64_t chat_id = user->id(); +void OfficeStaffCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, + std::shared_ptr user) { + int64_t ChatId = user->id(); if (query->data == "office_staff_buttons") { - bot.getApi().sendMessage(chat_id, "Кнопочки", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "office_staff_time_table") { - bot.getApi().sendMessage(chat_id, "Ссылка на расписание для office staff", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "office_staff_declaration") { - bot.getApi().sendMessage(chat_id, "Актуальные объявления для office staff", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "office_staff_connect_with_teacher") { - bot.getApi().sendMessage(chat_id, "Списочек с контактами преподавателя для office staff", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "office_staff_help") { - bot.getApi().sendMessage(chat_id, "Помощь для office staff", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "office_staff_back") { - bot.getApi().sendMessage(chat_id, "Меню для office staff", 0, 0, user->GetMenu()); - } - else if (query->data == "office_staff_information") { - bot.getApi().sendMessage(chat_id, "Какая-то информация для office staff", 0, 0, user->BackButton()); - } - else if (query->data == "office_add_info") { - bot.getApi().sendMessage(chat_id, "Здесь вы можете ввести информацию", 0, 0, user->GetInlineKeyboard()); + bot.getApi().sendMessage(ChatId, "Кнопочки", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "office_staff_time_table") { + bot.getApi().sendMessage(ChatId, "Ссылка на расписание для office staff", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "office_staff_declaration") { + bot.getApi().sendMessage(ChatId, "Актуальные объявления для office staff", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "office_staff_connect_with_teacher") { + bot.getApi().sendMessage(ChatId, "Списочек с контактами преподавателя для office staff", 0, + 0, user->GetInlineKeyboard()); + } else if (query->data == "office_staff_help") { + bot.getApi().sendMessage(ChatId, "Помощь для office staff", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "office_staff_back") { + bot.getApi().sendMessage(ChatId, "Меню для office staff", 0, 0, user->GetMenu()); + } else if (query->data == "office_staff_information") { + bot.getApi().sendMessage(ChatId, "Какая-то информация для office staff", 0, 0, + user->BackButton()); + } else if (query->data == "office_add_info") { + bot.getApi().sendMessage(ChatId, "Здесь вы можете ввести информацию", 0, 0, + user->GetInlineKeyboard()); } } -void teacher_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { - int64_t chat_id = user->id(); +void TeacherCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, + std::shared_ptr user) { + int64_t ChatId = user->id(); if (query->data == "teacher_declaration") { - bot.getApi().sendMessage(chat_id, "Вы преподаватель и вы можите сделать объявление", 0, 0, user->BackButton()); - } - else if (query->data == "teacher_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); - } - else if (query->data == "teacher_buttons") { - bot.getApi().sendMessage(chat_id, "Кнопочки для преподов", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "teachert_information") { - bot.getApi().sendMessage(chat_id, "Какая-то полезная инва для преподов", 0, 0, user->BackButton()); + bot.getApi().sendMessage(ChatId, "Вы преподаватель и вы можите сделать объявление", 0, 0, + user->BackButton()); + } else if (query->data == "teacher_back") { + bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); + } else if (query->data == "teacher_buttons") { + bot.getApi().sendMessage(ChatId, "Кнопочки для преподов", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "teachert_information") { + bot.getApi().sendMessage(ChatId, "Какая-то полезная инва для преподов", 0, 0, + user->BackButton()); } } -void tutor_call_back_query(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, std::shared_ptr user) { - int64_t chat_id = user->id(); +void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, + std::shared_ptr user) { + int64_t ChatId = user->id(); if (query->data == "tutor_buttons") { - bot.getApi().sendMessage(chat_id, "fsdf", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "tutor_add_subject") { - bot.getApi().sendMessage(chat_id, "Введите название нового предмета", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "tutor_view_sop") { + bot.getApi().sendMessage(ChatId, "fsdf", 0, 0, user->GetInlineKeyboard()); + } else if (query->data == "tutor_add_subject") { + bot.getApi().sendMessage(ChatId, "Введите название нового предмета", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "tutor_view_sop") { user->GetState() = mtd::UserState::TUTOR_SOP; - bot.getApi().sendMessage(chat_id, "Введите id пользователя"); - - } - else if (query->data == "tutor_add_people") { - bot.getApi().sendMessage(chat_id, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "tutor_create_sop") { - bot.getApi().sendMessage(chat_id, "Введите данные для создания SOP", 0, 0, user->GetInlineKeyboard()); - } - else if (query->data == "tutor_back") { - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, user->GetMenu()); + bot.getApi().sendMessage(ChatId, "Введите id пользователя"); + + } else if (query->data == "tutor_add_people") { + bot.getApi().sendMessage(ChatId, "Введите ID студентов и групп, которых нужно добавить", 0, + 0, user->GetInlineKeyboard()); + } else if (query->data == "tutor_create_sop") { + bot.getApi().sendMessage(ChatId, "Введите данные для создания SOP", 0, 0, + user->GetInlineKeyboard()); + } else if (query->data == "tutor_back") { + bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); } } int main() { TgBot::Bot bot(mtd::token); std::map> users; - std::set new_users; - std::mutex mutex_for_users; - - bot.getEvents().onCommand("start", [&bot, &users, &mutex_for_users, &new_users](TgBot::Message::Ptr message) { - std::lock_guard lock(mutex_for_users); - new_users.insert(message->chat->id); - std::cout << "User connect: " << message->chat->id << '\n'; - TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); - TgBot::InlineKeyboardButton::Ptr b1(new TgBot::InlineKeyboardButton); - b1->text = "Студент"; - b1->callbackData = "student"; - - TgBot::InlineKeyboardButton::Ptr b2(new TgBot::InlineKeyboardButton); - b2->text = "Очебный офис"; - b2->callbackData = "office_staff"; - - TgBot::InlineKeyboardButton::Ptr b3(new TgBot::InlineKeyboardButton); - b3->text = "Преподаватель"; - b3->callbackData = "teacher"; - - TgBot::InlineKeyboardButton::Ptr b4(new TgBot::InlineKeyboardButton); - b4->text = "Куратор"; - b4->callbackData = "tutor"; - - keyboard->inlineKeyboard.push_back({b1}); - keyboard->inlineKeyboard.push_back({b2}); - keyboard->inlineKeyboard.push_back({b3}); - keyboard->inlineKeyboard.push_back({b4}); - - bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); - }); - - bot.getEvents().onCallbackQuery([&bot, &users, &mutex_for_users, &new_users](TgBot::CallbackQuery::Ptr query) { - std::lock_guard lock(mutex_for_users); - int64_t chat_id = query->message->chat->id; - - if (users.find(chat_id) == users.end()) { - std::cout << "=== Error ===\n"; - } - - if (new_users.find(chat_id) != new_users.end()) { - if (query->data == "student") { - auto student_ptr = std::make_shared(chat_id); - users.insert({chat_id, student_ptr}); - } - else if (query->data == "office_staff") { - auto office_staff_ptr = std::make_shared(chat_id); - users.insert({chat_id, office_staff_ptr}); + std::set NewUsers; + std::mutex MutexForUsers; + + bot.getEvents().onCommand( + "start", [&bot, &users, &MutexForUsers, &NewUsers](TgBot::Message::Ptr message) { + std::lock_guard lock(MutexForUsers); + NewUsers.insert(message->chat->id); + std::cout << "User connect: " << message->chat->id << '\n'; + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr b1(new TgBot::InlineKeyboardButton); + b1->text = "Студент"; + b1->callbackData = "student"; + + TgBot::InlineKeyboardButton::Ptr b2(new TgBot::InlineKeyboardButton); + b2->text = "Очебный офис"; + b2->callbackData = "office_staff"; + + TgBot::InlineKeyboardButton::Ptr b3(new TgBot::InlineKeyboardButton); + b3->text = "Преподаватель"; + b3->callbackData = "teacher"; + + TgBot::InlineKeyboardButton::Ptr b4(new TgBot::InlineKeyboardButton); + b4->text = "Куратор"; + b4->callbackData = "tutor"; + + keyboard->inlineKeyboard.push_back({b1}); + keyboard->inlineKeyboard.push_back({b2}); + keyboard->inlineKeyboard.push_back({b3}); + keyboard->inlineKeyboard.push_back({b4}); + + bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); + }); + + bot.getEvents().onCallbackQuery( + [&bot, &users, &MutexForUsers, &NewUsers](TgBot::CallbackQuery::Ptr query) { + std::lock_guard lock(MutexForUsers); + int64_t ChatId = query->message->chat->id; + + if (users.find(ChatId) == users.end()) { + std::cout << "=== Error ===\n"; } - else if (query->data == "teacher") { - auto teacher_ptr = std::make_shared(chat_id); - users.insert({chat_id, teacher_ptr}); + + if (NewUsers.find(ChatId) != NewUsers.end()) { + if (query->data == "student") { + auto student_ptr = std::make_shared(ChatId); + users.insert({ChatId, student_ptr}); + } else if (query->data == "office_staff") { + auto office_staff_ptr = std::make_shared(ChatId); + users.insert({ChatId, office_staff_ptr}); + } else if (query->data == "teacher") { + auto teacher_ptr = std::make_shared(ChatId); + users.insert({ChatId, teacher_ptr}); + } else if (query->data == "tutor") { + auto tutor_ptr = std::make_shared(ChatId); + users.insert({ChatId, tutor_ptr}); + } + + bot.getApi().sendMessage(ChatId, "Меню", 0, 0, users[ChatId]->GetMenu()); + NewUsers.erase(ChatId); + return; } - else if (query->data == "tutor") { - auto tutor_ptr = std::make_shared(chat_id); - users.insert({chat_id, tutor_ptr}); + + auto &user = users[ChatId]; + if (user->GetRole() == mtd::UserRole::STUDENT) { + StudentCallBackQuery(bot, query, user); + } else if (user->GetRole() == mtd::UserRole::OFFICE_STAFF) { + OfficeStaffCallBackQuery(bot, query, user); + } else if (user->GetRole() == mtd::UserRole::TEACHER) { + TeacherCallBackQuery(bot, query, user); + } else if (user->GetRole() == mtd::UserRole::TUTOR) { + TutorCallBackQuery(bot, query, user); } - - bot.getApi().sendMessage(chat_id, "Меню", 0, 0, users[chat_id]->GetMenu()); - new_users.erase(chat_id); - return; - } - - auto &user = users[chat_id]; - if (user->GetRole() == mtd::UserRole::STUDENT) { - student_call_back_query(bot, query, user); - } - else if (user->GetRole() == mtd::UserRole::OFFICE_STAFF) { - office_staff_call_back_query(bot, query, user); - } - else if (user->GetRole() == mtd::UserRole::TEACHER) { - teacher_call_back_query(bot, query, user); - } - else if (user->GetRole() == mtd::UserRole::TUTOR) { - - tutor_call_back_query(bot, query, user); - } - }); + }); + + bot.getEvents().onAnyMessage([&bot, &users, &MutexForUsers](TgBot::Message::Ptr message) { + std::lock_guard lock(MutexForUsers); + int64_t ChatId = message->chat->id; - bot.getEvents().onAnyMessage([&bot, &users, &mutex_for_users](TgBot::Message::Ptr message){ - std::lock_guard lock(mutex_for_users); - int64_t chat_id = message->chat->id; - - if (users.find(chat_id) == users.end()) { + if (users.find(ChatId) == users.end()) { std::cout << "=== Error 2 ===\n"; return; } - auto &user = users[chat_id]; + auto &user = users[ChatId]; if (user->GetState() == mtd::UserState::TUTOR_SOP) { - int64_t student_chat_id = static_cast(std::stoll(message->text)); + int64_t student_ChatId = static_cast(std::stoll(message->text)); std::string s; - for (const auto i : users[student_chat_id]->GetEvaluations()) { + for (const auto i : users[student_ChatId]->GetEvaluations()) { s += std::to_string(i) + " "; } - bot.getApi().sendMessage(chat_id, "Оценки этого студента:\n" + s, 0, 0, user->BackButton()); + bot.getApi().sendMessage(ChatId, "Оценки этого студента:\n" + s, 0, 0, + user->BackButton()); return; } }); From b09d1778980d8a0b8441e5d2741ee5295d31f86e Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 15:08:08 +0300 Subject: [PATCH 12/55] redone README and clang-tidy --- .clang-tidy | 21 +++++++++++++++++---- README.md | 14 +++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e09ebde..64c511b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,19 @@ -Checks: "-*,boost-*,bugprone-*,concurrency-*,cppcoreguidelines-*,misc-*,modernize-*,performance-*,portability-*,readability-*,google-build-namespaces,google-build-using-namespace,google-global-names-in-headers,google-readability-casting,google-runtime-operator,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-*magic-numbers*,-*avoid-c-arrays*,-modernize-use-trailing-return-type,-readability-else-after-return,-readability-named-parameter,-readability-identifier-length,-bugprone-easily-swappable-parameters,-bugprone-exception-escape" +Checks: >- + -*, + bugprone-*, + concurrency-*, + cppcoreguidelines-*, + misc-*, + modernize-*, + performance-*, + portability-*, + readability-*, + google-readability-casting, + google-runtime-operator, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index + WarningsAsErrors: "*" + ExtraArgs: - - "-std=c++20" -ExtraArgsBefore: - - "-xc++" \ No newline at end of file + - "-std=c++20" \ No newline at end of file diff --git a/README.md b/README.md index 7d83820..e73220b 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,13 @@ ### Чуток описание проекта : Телеграмм-бот с авторизацией для студентов, преподавателей, администрации, организаторов учебного процесса (учебный офис, кураторы и т.п.). Среди базового функционала присутствуют: система анонимной студенческой оценки преподавания, система донесения информации от учебного офиса, преподавателей и кураторов до студентов c подтверждением получения (в т.ч. ссылок на чаты и объявлений). Возможность поддержания полезной информации о предметах внутри бота (ссылки, таблицы, папки, чаты, файлы) с возможностью изменения студентами (как wiki, просмотр изменений). +```sh +# Запуск с clang-tidy run-clang-tidy -p build/ (для запуска clang-format) - -rm -rf build # Удаляем старую директорию (если она есть) -mkdir build && cd build # Создаём новую папку и заходим в неё -cmake -G Ninja .. # Говорим CMake использовать Ninja -ninja # Собираем проект \ No newline at end of file +``` +```sh +rm -rf build +mkdir build && cd build +cmake -G Ninja .. +ninja +``` \ No newline at end of file From fdbfac1df25a1a1f073ac6e9c5cd3eddba06f5f9 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 19:37:50 +0300 Subject: [PATCH 13/55] commit 24.02.37 --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e73220b..ed57a9e 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ Телеграмм-бот с авторизацией для студентов, преподавателей, администрации, организаторов учебного процесса (учебный офис, кураторы и т.п.). Среди базового функционала присутствуют: система анонимной студенческой оценки преподавания, система донесения информации от учебного офиса, преподавателей и кураторов до студентов c подтверждением получения (в т.ч. ссылок на чаты и объявлений). Возможность поддержания полезной информации о предметах внутри бота (ссылки, таблицы, папки, чаты, файлы) с возможностью изменения студентами (как wiki, просмотр изменений). ```sh -# Запуск с clang-tidy -run-clang-tidy -p build/ (для запуска clang-format) +# Запуск clang-tidy +run-clang-tidy -p build/ ``` -```sh -rm -rf build +```sh mkdir build && cd build -cmake -G Ninja .. +cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. # Флаг для поддержки clang-tidy ninja ``` \ No newline at end of file From 30b642de57ef3dde0d4217735c58747dd2497630 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 19:51:51 +0300 Subject: [PATCH 14/55] redone README --- README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ed57a9e..21124fb 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,31 @@ -# EntryPoint -Проект на плюсах от 3 амбициозных пацанчиков +# 🚀 EntryPoint +A **Telegram Bot** designed for students, teachers, administration, and educational process organizers. -### Чуток описание проекта : -Телеграмм-бот с авторизацией для студентов, преподавателей, администрации, организаторов учебного процесса (учебный офис, кураторы и т.п.). Среди базового функционала присутствуют: система анонимной студенческой оценки преподавания, система донесения информации от учебного офиса, преподавателей и кураторов до студентов c подтверждением получения (в т.ч. ссылок на чаты и объявлений). Возможность поддержания полезной информации о предметах внутри бота (ссылки, таблицы, папки, чаты, файлы) с возможностью изменения студентами (как wiki, просмотр изменений). +## 📌 Project Description +EntryPoint is a Telegram bot with an authorization system for different roles in the educational process: + +- **Students** — can anonymously evaluate teaching quality and receive important announcements. +- **Teachers & Curators** — can send notifications to students with read confirmation. +- **Administration** — can manage information distribution within the university. + +🔹 The bot also allows storing useful subject-related information (links, tables, files, chats). +🔹 Any student can edit the materials **Wiki-style**, with a change history feature. + +--- + +## 🛠 Installation & Build + +### 🔹 1. Clone the repository ```sh -# Запуск clang-tidy -run-clang-tidy -p build/ -``` -```sh +git clone git@github.com:EntryPoint-C-project/EntryPoint.git +cd EntryPoint mkdir build && cd build -cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. # Флаг для поддержки clang-tidy -ninja +cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. # Enable clang-tidy support +ninja +``` +### 🔹 2. Running clang-tidy +```sh +run-clang-tidy -p build/ ``` \ No newline at end of file From 493639ba188f9ce4622bbd8731247a8672096087 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Mon, 24 Feb 2025 19:53:28 +0300 Subject: [PATCH 15/55] redone README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 21124fb..25c0187 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ EntryPoint is a Telegram bot with an authorization system for different roles in ```sh git clone git@github.com:EntryPoint-C-project/EntryPoint.git cd EntryPoint +# You need to make a telegram-bot token mkdir build && cd build cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. # Enable clang-tidy support ninja From 41d12c05d5d9de679cf63031a5a6414cd221e792 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 25 Feb 2025 17:14:48 +0300 Subject: [PATCH 16/55] create LICENSE --- .clang-format | 39 +++++++++++++---------------- CMakeLists.txt | 4 +-- LICENSE | 21 ++++++++++++++++ {inc => include}/OfficeStaff.hpp | 2 +- {inc => include}/Student.hpp | 2 +- {inc => include}/Teacher.hpp | 2 +- {inc => include}/Tutor.hpp | 3 +-- {inc => include}/User.hpp | 6 +++-- include/sop.hpp | 34 +++++++++++++++++++++++++ {src => source}/OfficeStaff.cpp | 0 {src => source}/Student.cpp | 0 {src => source}/Teacher.cpp | 0 {src => source}/Tutor.cpp | 0 {src => source}/User.cpp | 0 {src => source}/main.cpp | 43 ++++++++++++++++++++------------ 15 files changed, 109 insertions(+), 47 deletions(-) create mode 100644 LICENSE rename {inc => include}/OfficeStaff.hpp (97%) rename {inc => include}/Student.hpp (97%) rename {inc => include}/Teacher.hpp (97%) rename {inc => include}/Tutor.hpp (96%) rename {inc => include}/User.hpp (82%) create mode 100644 include/sop.hpp rename {src => source}/OfficeStaff.cpp (100%) rename {src => source}/Student.cpp (100%) rename {src => source}/Teacher.cpp (100%) rename {src => source}/Tutor.cpp (100%) rename {src => source}/User.cpp (100%) rename {src => source}/main.cpp (88%) diff --git a/.clang-format b/.clang-format index 5147b7f..35e5969 100644 --- a/.clang-format +++ b/.clang-format @@ -1,29 +1,24 @@ --- -BasedOnStyle: Google # Используем Google Style как основу +BasedOnStyle: Google -# Выравнивание и отступы -AccessModifierOffset: -2 # Смещение модификаторов доступа (private, public) влево -AlignTrailingComments: true # Выравнивание комментариев -IndentPPDirectives: AfterHash # Директивы препроцессора (#define, #include) выравниваются после # -IndentWidth: 4 # Отступ в 4 пробела -NamespaceIndentation: None # Без отступов внутри namespace +AccessModifierOffset: -4 +AlignTrailingComments: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +NamespaceIndentation: None -# Форматирование скобок и операторов -BreakBeforeBraces: Attach # Фигурные скобки остаются на той же строке, что и выражение -BreakBeforeBinaryOperators: All # Перенос бинарных операторов (+, -, *, /) на новую строку -BreakBeforeTernaryOperators: true # Перенос тернарных операторов (?:) на новую строку +BreakBeforeBraces: Attach +BreakBeforeBinaryOperators: All +BreakBeforeTernaryOperators: true -# Лимиты строк и форматирование длинных выражений -ColumnLimit: 100 # Максимальная длина строки 100 символов -ConstructorInitializerAllOnOneLineOrOnePerLine: true # Либо все инициализаторы конструктора в одной строке, либо каждый на новой +ColumnLimit: 100 +ConstructorInitializerAllOnOneLineOrOnePerLine: true -# Включения (includes) -IncludeBlocks: Regroup # Группировать include'ы по категориям (стандартные, пользовательские, системные) -SortIncludes: true # Сортировать include'ы по алфавиту +IncludeBlocks: Regroup +SortIncludes: true -# Дополнительные улучшения читаемости -SpaceBeforeParens: ControlStatements # Пробел перед скобками у if, while, for, но не у вызовов функций -AllowShortFunctionsOnASingleLine: InlineOnly # Разрешать однострочные функции только в inline -AllowShortIfStatementsOnASingleLine: false # if всегда должен быть на новой строке -AllowShortLoopsOnASingleLine: false # Циклы тоже должны быть в отдельных строках +SpaceBeforeParens: ControlStatements +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false ... diff --git a/CMakeLists.txt b/CMakeLists.txt index f21a3b4..fbdea6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,10 @@ find_package(Boost REQUIRED COMPONENTS system) # Ищем Boost (модуль sy find_package(TgBot REQUIRED) # Ищем библиотеку TgBot # Указываем путь к заголовочным файлам -include_directories(inc) # Например, папка "inc" для .hpp файлов +include_directories(include) # Например, папка "inc" для .hpp файлов # Собираем список исходников -file(GLOB SOURCES src/*.cpp) # Собираем все .cpp файлы в папке src +file(GLOB SOURCES source/*.cpp) # Собираем все .cpp файлы в папке src # Создаём исполняемый файл add_executable(my_bot ${SOURCES}) # Компилируем все найденные .cpp файлы diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..34a1f1b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Melnikov Kirill + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/inc/OfficeStaff.hpp b/include/OfficeStaff.hpp similarity index 97% rename from inc/OfficeStaff.hpp rename to include/OfficeStaff.hpp index ce889ec..f373890 100644 --- a/inc/OfficeStaff.hpp +++ b/include/OfficeStaff.hpp @@ -5,7 +5,7 @@ namespace mtd { class OfficeStaff : public User { - public: +public: OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; diff --git a/inc/Student.hpp b/include/Student.hpp similarity index 97% rename from inc/Student.hpp rename to include/Student.hpp index 460c054..6512369 100644 --- a/inc/Student.hpp +++ b/include/Student.hpp @@ -5,7 +5,7 @@ namespace mtd { class Student : public User { - public: +public: Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; diff --git a/inc/Teacher.hpp b/include/Teacher.hpp similarity index 97% rename from inc/Teacher.hpp rename to include/Teacher.hpp index d3d3052..009bb8e 100644 --- a/inc/Teacher.hpp +++ b/include/Teacher.hpp @@ -5,7 +5,7 @@ namespace mtd { class Teacher : public User { - public: +public: Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) {} TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; diff --git a/inc/Tutor.hpp b/include/Tutor.hpp similarity index 96% rename from inc/Tutor.hpp rename to include/Tutor.hpp index bbdd114..d60fe6f 100644 --- a/inc/Tutor.hpp +++ b/include/Tutor.hpp @@ -5,9 +5,8 @@ namespace mtd { class Tutor : public User { - public: +public: Tutor(int64_t chat_id); - TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; diff --git a/inc/User.hpp b/include/User.hpp similarity index 82% rename from inc/User.hpp rename to include/User.hpp index d876720..b81e625 100644 --- a/inc/User.hpp +++ b/include/User.hpp @@ -5,10 +5,11 @@ #include #include +#include "sop.hpp" namespace mtd { enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; -enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, NONE }; +enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP_LECTION, STUDENT_SOP_PRACTICE, TUTOR_SOP, CREATE_SOP, NONE }; class User { int64_t chat_id = 0; @@ -17,10 +18,11 @@ class User { int step = 0; std::vector evaluations; - public: +public: explicit User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) {} virtual ~User() {} + Feedback feedback; int64_t id() const; UserRole GetRole() const; UserState &GetState(); diff --git a/include/sop.hpp b/include/sop.hpp new file mode 100644 index 0000000..6a648d5 --- /dev/null +++ b/include/sop.hpp @@ -0,0 +1,34 @@ +#ifndef SOP_HPP_ +#define SOP_HPP_ + +#include +#include +#include +#include + +namespace mtd { +// эта структура -- кусочек сопа для какого-то предмета +// например, если говорим про ОМП, то это часть типа практика группы 2 +// или оценивание лекции +const int NO_HOMEWORK = -1; +struct Feedback { + std::string teacher_name; // имя преподавателя + int grade = 0; // оценка преподавания + int grade_home_work = -1; // проверка дз (-1 -- это лекция, нет дз) + std::string advantages; // что нравится + std::string disadvantages; // что не нравится + int step = 0; // шаг, на котоором сейчас студент, например 1 -- комментарий +}; + +struct Subject { + std::string name_subject; + std::vector lections_result; // все фидбеки по лекциям + std::vector practice_result; // по практикам + std::vector comments; // дополнительные комментарии к предмету +}; + + + +} // namespace mtd + +#endif \ No newline at end of file diff --git a/src/OfficeStaff.cpp b/source/OfficeStaff.cpp similarity index 100% rename from src/OfficeStaff.cpp rename to source/OfficeStaff.cpp diff --git a/src/Student.cpp b/source/Student.cpp similarity index 100% rename from src/Student.cpp rename to source/Student.cpp diff --git a/src/Teacher.cpp b/source/Teacher.cpp similarity index 100% rename from src/Teacher.cpp rename to source/Teacher.cpp diff --git a/src/Tutor.cpp b/source/Tutor.cpp similarity index 100% rename from src/Tutor.cpp rename to source/Tutor.cpp diff --git a/src/User.cpp b/source/User.cpp similarity index 100% rename from src/User.cpp rename to source/User.cpp diff --git a/src/main.cpp b/source/main.cpp similarity index 88% rename from src/main.cpp rename to source/main.cpp index 896c16a..2f99b86 100644 --- a/src/main.cpp +++ b/source/main.cpp @@ -22,6 +22,10 @@ TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { button->callbackData = std::to_string(i); // Колбек-данные соответствуют цифре keyboard->inlineKeyboard.push_back({button}); // Добавляем кнопки в строку клавиатуры } + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "Не моя группа"; + button->callbackData = "-1"; + keyboard->inlineKeyboard.push_back({button}); return keyboard; } @@ -30,20 +34,12 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int64_t ChatId = user->id(); if (query->data == "1" || query->data == "2" || query->data == "3" || query->data == "4" || query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" - || query->data == "9" || query->data == "10") { - bot.getApi().sendMessage( - ChatId, "Этого лоха ты оценил на " + query->data + ".\nИзменить свой выбор нельзя("); - user->GetEvaluations().push_back(std::stoi(query->data)); - // Следующий вопрос - if (user->GetStep() < 5) { - bot.getApi().sendMessage(ChatId, "Вопрос " + std::to_string(user->GetStep() + 1), 0, 0, - get_raiting_scale()); - user->GetStep()++; // Переход к следующему вопросу - } else { - bot.getApi().sendMessage(ChatId, "Опрос завершен. Спасибо за участие!", 0, 0, - user->BackButton()); - user->GetState() = mtd::UserState::NONE; - user->GetStep() = 0; + || query->data == "9" || query->data == "10" || query->data == "-1") { + + if (user->feedback.step == 0) { + bot.getApi().sendMessage(ChatId, "Лекция оценена на " + query->data); + bot.getApi().sendMessage(ChatId, "Напишите, что нравится в лекциях"); + user->feedback.step++; } } @@ -52,9 +48,9 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, if (query->data == "student_buttons") { bot.getApi().sendMessage(ChatId, "fsfsdf", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_sop" && user->GetStep() == 0) { - bot.getApi().sendMessage(ChatId, "Вопрос 1", 0, 0, get_raiting_scale()); + bot.getApi().sendMessage(ChatId, "Оцените лекции по ОМП", 0, 0, get_raiting_scale()); user->GetStep()++; - user->GetState() = mtd::UserState::STUDENT_SOP; + user->GetState() = mtd::UserState::STUDENT_SOP_LECTION; } else if (query->data == "student_time_table") { bot.getApi().sendMessage(ChatId, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_declaration") { @@ -131,6 +127,8 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, bot.getApi().sendMessage(ChatId, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_create_sop") { + user->GetStep()++; + user->GetState() = mtd::UserState::CREATE_SOP; bot.getApi().sendMessage(ChatId, "Введите данные для создания SOP", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_back") { @@ -235,6 +233,19 @@ int main() { user->BackButton()); return; } + else if (user->GetState() == mtd::UserState::STUDENT_SOP) { + if (user->feedback.step == 1) { + std::cout << "fsdfsdfs\n"; + user->feedback.advantages = message->text; + user->feedback.step++; + bot.getApi().sendMessage(ChatId, "Что не нравится в лекциях?"); + } + else if (user->feedback.step == 2) { + user->feedback.disadvantages = message->text; + user->feedback.step = 0; + bot.getApi().sendMessage(ChatId, "Оцените практику группа 1", 0, 0, get_raiting_scale()); + } + } }); try { std::cout << "Bot is running...\n"; From 19a7b3f32cf557f66f5faf38cd8f4020fafac838 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 25 Feb 2025 20:01:02 +0300 Subject: [PATCH 17/55] fsdf --- include/User.hpp | 2 +- include/sop.hpp | 25 +++++++++-- source/main.cpp | 108 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 116 insertions(+), 19 deletions(-) diff --git a/include/User.hpp b/include/User.hpp index b81e625..4ec19b5 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -9,7 +9,7 @@ namespace mtd { enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; -enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP_LECTION, STUDENT_SOP_PRACTICE, TUTOR_SOP, CREATE_SOP, NONE }; +enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, CREATE_SOP, NONE }; class User { int64_t chat_id = 0; diff --git a/include/sop.hpp b/include/sop.hpp index 6a648d5..bc3e0e2 100644 --- a/include/sop.hpp +++ b/include/sop.hpp @@ -7,23 +7,42 @@ #include namespace mtd { +struct Discipline { + std::string name_subject = "ОМП"; + std::string lector = "Сайфулин Д.Т"; + std::vector seminarians = {"Сайфулин Д.Т.", "Галоев И.Б.", "Иванцов И.С."}; +}; // эта структура -- кусочек сопа для какого-то предмета // например, если говорим про ОМП, то это часть типа практика группы 2 // или оценивание лекции const int NO_HOMEWORK = -1; struct Feedback { - std::string teacher_name; // имя преподавателя int grade = 0; // оценка преподавания int grade_home_work = -1; // проверка дз (-1 -- это лекция, нет дз) std::string advantages; // что нравится std::string disadvantages; // что не нравится int step = 0; // шаг, на котоором сейчас студент, например 1 -- комментарий + int index = 0; +}; + +struct LectionFeedback { + int grade; + std::string advantages; // что нравится + std::string disadvantages; // что не нравится +}; + +struct PracticeFeedback { + std::string name_teacher; + int grade; + int grade_for_homework; + std::string advantages; // что нравится + std::string disadvantages; // что не нравится }; struct Subject { std::string name_subject; - std::vector lections_result; // все фидбеки по лекциям - std::vector practice_result; // по практикам + std::vector lections_result; // все фидбеки по лекциям + std::vector practice_result; // по практикам std::vector comments; // дополнительные комментарии к предмету }; diff --git a/source/main.cpp b/source/main.cpp index 2f99b86..3a5626b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,6 +12,11 @@ #include "Teacher.hpp" #include "Tutor.hpp" #include "User.hpp" +#include "sop.hpp" + +const mtd::Discipline t; +mtd::Subject OMP; + TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); @@ -36,10 +41,22 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, || query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" || query->data == "9" || query->data == "10" || query->data == "-1") { - if (user->feedback.step == 0) { - bot.getApi().sendMessage(ChatId, "Лекция оценена на " + query->data); - bot.getApi().sendMessage(ChatId, "Напишите, что нравится в лекциях"); - user->feedback.step++; + if (user->GetState() == mtd::UserState::STUDENT_SOP) { + if (user->GetStep() == 0) { // оценка лектора + user->feedback.grade = std::stoi(query->data); + bot.getApi().sendMessage(ChatId, "вы оценили лекции на " + query->data + "\nНапишите, что вам нравится в лекциях"); + user->GetStep()++; + } + else if (user->GetStep() == 3) { + user->feedback.grade = std::stoi(query->data); + user->GetStep()++; + bot.getApi().sendMessage(ChatId, "Оцените домашку", 0, 0, get_raiting_scale()); + } + else if (user->GetStep() == 4) { + user->feedback.grade_home_work = std::stoi(query->data); + user->GetStep()++; + bot.getApi().sendMessage(ChatId, "Что нравится"); + } } } @@ -48,9 +65,8 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, if (query->data == "student_buttons") { bot.getApi().sendMessage(ChatId, "fsfsdf", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_sop" && user->GetStep() == 0) { - bot.getApi().sendMessage(ChatId, "Оцените лекции по ОМП", 0, 0, get_raiting_scale()); - user->GetStep()++; - user->GetState() = mtd::UserState::STUDENT_SOP_LECTION; + bot.getApi().sendMessage(ChatId, "Оцените лекции по " + t.name_subject + " (" + t.lector + ")", 0, 0, get_raiting_scale()); + user->GetState() = mtd::UserState::STUDENT_SOP; } else if (query->data == "student_time_table") { bot.getApi().sendMessage(ChatId, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_declaration") { @@ -120,8 +136,35 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, bot.getApi().sendMessage(ChatId, "Введите название нового предмета", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_view_sop") { - user->GetState() = mtd::UserState::TUTOR_SOP; - bot.getApi().sendMessage(ChatId, "Введите id пользователя"); + // user->GetState() = mtd::UserState::TUTOR_SOP; + // bot.getApi().sendMessage(ChatId, "Введите id пользователя"); + std::string s = "лекции "; + for (auto p : OMP.lections_result) { + s = s + std::to_string(p.grade); + } + s += "\n Что понравилось:\n"; + for (auto p : OMP.lections_result) { + s = s + p.advantages + '\n'; + } + s += "Что не понравилось: "; + for (auto p : OMP.lections_result) { + s = s + p.disadvantages + '\n'; + } + bot.getApi().sendMessage(ChatId, s); + + s = "Праки "; + for (auto p : OMP.practice_result) { + s = s + std::to_string(p.grade); + } + s += "\n Что понравилось:\n"; + for (auto p : OMP.practice_result) { + s = s + p.advantages + '\n'; + } + s += "Что не понравилось: "; + for (auto p : OMP.practice_result) { + s = s + p.disadvantages + '\n'; + } + bot.getApi().sendMessage(ChatId, s); } else if (query->data == "tutor_add_people") { bot.getApi().sendMessage(ChatId, "Введите ID студентов и групп, которых нужно добавить", 0, @@ -137,6 +180,7 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, } int main() { + OMP.name_subject = "ОМП"; TgBot::Bot bot(mtd::token); std::map> users; std::set NewUsers; @@ -234,16 +278,50 @@ int main() { return; } else if (user->GetState() == mtd::UserState::STUDENT_SOP) { - if (user->feedback.step == 1) { - std::cout << "fsdfsdfs\n"; + if (user->GetStep() == -1) { // конец + OMP.comments.push_back(message->text); + } + if (user->GetStep() == 1) { user->feedback.advantages = message->text; - user->feedback.step++; bot.getApi().sendMessage(ChatId, "Что не нравится в лекциях?"); + user->GetStep()++; + } + else if (user->GetStep() == 2) { + if (user->feedback.index == 0) { + user->feedback.disadvantages = message->text; + mtd::LectionFeedback q; + q.grade = user->feedback.grade; + q.advantages = user->feedback.advantages; + q.disadvantages = user->feedback.disadvantages; + OMP.lections_result.push_back(q); + } + user->GetStep()++; + if (user->feedback.index < t.seminarians.size()) { + bot.getApi().sendMessage(ChatId, "Оцените практику с " + t.seminarians[user->feedback.index], 0, 0, get_raiting_scale()); + } + else { + user->GetStep() = -1; + bot.getApi().sendMessage(ChatId, "Введите какой-нибудь коммент"); + } + + } + else if (user->GetStep() == 5) { + user->feedback.advantages = message->text; + bot.getApi().sendMessage(ChatId, "Что не нравится"); + user->GetStep()++; } - else if (user->feedback.step == 2) { + else if (user->GetStep() == 6) { user->feedback.disadvantages = message->text; - user->feedback.step = 0; - bot.getApi().sendMessage(ChatId, "Оцените практику группа 1", 0, 0, get_raiting_scale()); + mtd::PracticeFeedback q; + q.grade = user->feedback.grade; + q.grade_for_homework = user->feedback.grade_home_work; + q.advantages = user->feedback.advantages; + q.disadvantages = user->feedback.disadvantages; + q.name_teacher = t.seminarians[user->feedback.index]; + OMP.practice_result.push_back(q); + user->feedback.index++; + user->GetStep() = 2; + bot.getApi().sendMessage(ChatId, "Если хотите продолжить, введите что-то"); } } }); From 7e928547c24ef60138793c3d228f4ce071796c34 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 25 Feb 2025 20:11:17 +0300 Subject: [PATCH 18/55] modified sop.hpp --- include/sop.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/sop.hpp b/include/sop.hpp index bc3e0e2..2f540a4 100644 --- a/include/sop.hpp +++ b/include/sop.hpp @@ -15,22 +15,28 @@ struct Discipline { // эта структура -- кусочек сопа для какого-то предмета // например, если говорим про ОМП, то это часть типа практика группы 2 // или оценивание лекции -const int NO_HOMEWORK = -1; +/* + Данная структура находится в каждого студента в классе, + он заполняет чать сопа, из этой структуры все перекидывается в другие две (которые ниже), + потом в эту структуру записываются новые данные (у каждого студента своя) +*/ struct Feedback { int grade = 0; // оценка преподавания int grade_home_work = -1; // проверка дз (-1 -- это лекция, нет дз) std::string advantages; // что нравится std::string disadvantages; // что не нравится - int step = 0; // шаг, на котоором сейчас студент, например 1 -- комментарий - int index = 0; + int step = 0; // Вроде бесполезная херня, но лучше пока не трогать + int index = 0; // Чтобы итерироваться по практикам }; +// Для каждого студента саздается одна такая по каждому прежмету struct LectionFeedback { int grade; std::string advantages; // что нравится std::string disadvantages; // что не нравится }; +// таки создается для каждого студента столько, сколько всего групп struct PracticeFeedback { std::string name_teacher; int grade; @@ -46,7 +52,7 @@ struct Subject { std::vector comments; // дополнительные комментарии к предмету }; - +// Если ты это читаешь, то искренне сочувствую тебе. Может, тебе удастся что-то понять } // namespace mtd From 163ed79e747e705b9c08a55ab95f36f5d3873410 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 25 Feb 2025 22:51:04 +0300 Subject: [PATCH 19/55] I can do itgit add .! --- include/User.hpp | 1 + include/sop.hpp | 24 +++++---- include/statistics.hpp | 8 +++ source/main.cpp | 117 ++++++++++++++++++++--------------------- source/statistics.cpp | 71 +++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 71 deletions(-) create mode 100644 include/statistics.hpp create mode 100644 source/statistics.cpp diff --git a/include/User.hpp b/include/User.hpp index 4ec19b5..cad3639 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -5,6 +5,7 @@ #include #include + #include "sop.hpp" namespace mtd { diff --git a/include/sop.hpp b/include/sop.hpp index 2f540a4..20daa8a 100644 --- a/include/sop.hpp +++ b/include/sop.hpp @@ -1,20 +1,20 @@ #ifndef SOP_HPP_ #define SOP_HPP_ -#include -#include #include #include +#include +#include namespace mtd { struct Discipline { - std::string name_subject = "ОМП"; - std::string lector = "Сайфулин Д.Т"; - std::vector seminarians = {"Сайфулин Д.Т.", "Галоев И.Б.", "Иванцов И.С."}; + std::string name_subject; + std::string lector; + std::vector seminarians; }; // эта структура -- кусочек сопа для какого-то предмета // например, если говорим про ОМП, то это часть типа практика группы 2 -// или оценивание лекции +// или оценивание лекции /* Данная структура находится в каждого студента в классе, он заполняет чать сопа, из этой структуры все перекидывается в другие две (которые ниже), @@ -25,8 +25,8 @@ struct Feedback { int grade_home_work = -1; // проверка дз (-1 -- это лекция, нет дз) std::string advantages; // что нравится std::string disadvantages; // что не нравится - int step = 0; // Вроде бесполезная херня, но лучше пока не трогать - int index = 0; // Чтобы итерироваться по практикам + int step = 0; // Вроде бесполезная херня, но лучше пока не трогать + int index = 0; // Чтобы итерироваться по практикам }; // Для каждого студента саздается одна такая по каждому прежмету @@ -47,12 +47,14 @@ struct PracticeFeedback { struct Subject { std::string name_subject; - std::vector lections_result; // все фидбеки по лекциям - std::vector practice_result; // по практикам - std::vector comments; // дополнительные комментарии к предмету + std::vector lections_result; // все фидбеки по лекциям + std::vector practice_result; // по практикам + std::vector comments; // дополнительные комментарии к предмету }; // Если ты это читаешь, то искренне сочувствую тебе. Может, тебе удастся что-то понять +// Я тебе не советую этого делать, лучше иди погуляй, потрогай траву, посмотри на небо, на людей +// Подумай, программирование -- это реально то, на что ты готов потратить свою короткую жизнь } // namespace mtd diff --git a/include/statistics.hpp b/include/statistics.hpp new file mode 100644 index 0000000..68f9be6 --- /dev/null +++ b/include/statistics.hpp @@ -0,0 +1,8 @@ +#ifndef STATISTICS_H +#define STATISTICS_H + +#include "sop.hpp" // если у вас есть этот файл с описанием структур + +std::string generate_statistics(const mtd::Subject& subject); + +#endif // STATISTICS_H \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 3a5626b..15d2bc5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -13,10 +13,19 @@ #include "Tutor.hpp" #include "User.hpp" #include "sop.hpp" +#include "statistics.hpp" -const mtd::Discipline t; +mtd::Discipline t; mtd::Subject OMP; +TgBot::InlineKeyboardMarkup::Ptr CompleteButton() { + TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); + TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); + button->text = "Завершить"; + button->callbackData = "complete_button"; + keyboard->inlineKeyboard.push_back({button}); + return keyboard; +} TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); @@ -30,7 +39,7 @@ TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = "Не моя группа"; button->callbackData = "-1"; - keyboard->inlineKeyboard.push_back({button}); + keyboard->inlineKeyboard.push_back({button}); return keyboard; } @@ -40,19 +49,17 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, if (query->data == "1" || query->data == "2" || query->data == "3" || query->data == "4" || query->data == "5" || query->data == "6" || query->data == "7" || query->data == "8" || query->data == "9" || query->data == "10" || query->data == "-1") { - if (user->GetState() == mtd::UserState::STUDENT_SOP) { - if (user->GetStep() == 0) { // оценка лектора + if (user->GetStep() == 0) { // оценка лектора user->feedback.grade = std::stoi(query->data); - bot.getApi().sendMessage(ChatId, "вы оценили лекции на " + query->data + "\nНапишите, что вам нравится в лекциях"); + bot.getApi().sendMessage(ChatId, "вы оценили лекции на " + query->data + + "\nНапишите, что вам нравится в лекциях"); user->GetStep()++; - } - else if (user->GetStep() == 3) { + } else if (user->GetStep() == 3) { user->feedback.grade = std::stoi(query->data); user->GetStep()++; bot.getApi().sendMessage(ChatId, "Оцените домашку", 0, 0, get_raiting_scale()); - } - else if (user->GetStep() == 4) { + } else if (user->GetStep() == 4) { user->feedback.grade_home_work = std::stoi(query->data); user->GetStep()++; bot.getApi().sendMessage(ChatId, "Что нравится"); @@ -65,7 +72,9 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, if (query->data == "student_buttons") { bot.getApi().sendMessage(ChatId, "fsfsdf", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_sop" && user->GetStep() == 0) { - bot.getApi().sendMessage(ChatId, "Оцените лекции по " + t.name_subject + " (" + t.lector + ")", 0, 0, get_raiting_scale()); + bot.getApi().sendMessage(ChatId, + "Оцените лекции по " + t.name_subject + " (" + t.lector + ")", 0, + 0, get_raiting_scale()); user->GetState() = mtd::UserState::STUDENT_SOP; } else if (query->data == "student_time_table") { bot.getApi().sendMessage(ChatId, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); @@ -136,44 +145,15 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, bot.getApi().sendMessage(ChatId, "Введите название нового предмета", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_view_sop") { - // user->GetState() = mtd::UserState::TUTOR_SOP; - // bot.getApi().sendMessage(ChatId, "Введите id пользователя"); - std::string s = "лекции "; - for (auto p : OMP.lections_result) { - s = s + std::to_string(p.grade); - } - s += "\n Что понравилось:\n"; - for (auto p : OMP.lections_result) { - s = s + p.advantages + '\n'; - } - s += "Что не понравилось: "; - for (auto p : OMP.lections_result) { - s = s + p.disadvantages + '\n'; - } - bot.getApi().sendMessage(ChatId, s); - - s = "Праки "; - for (auto p : OMP.practice_result) { - s = s + std::to_string(p.grade); - } - s += "\n Что понравилось:\n"; - for (auto p : OMP.practice_result) { - s = s + p.advantages + '\n'; - } - s += "Что не понравилось: "; - for (auto p : OMP.practice_result) { - s = s + p.disadvantages + '\n'; - } - bot.getApi().sendMessage(ChatId, s); + bot.getApi().sendMessage(ChatId, generate_statistics(OMP), 0, 0, user->GetMenu()); } else if (query->data == "tutor_add_people") { bot.getApi().sendMessage(ChatId, "Введите ID студентов и групп, которых нужно добавить", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "tutor_create_sop") { - user->GetStep()++; + user->GetStep() = 0; user->GetState() = mtd::UserState::CREATE_SOP; - bot.getApi().sendMessage(ChatId, "Введите данные для создания SOP", 0, 0, - user->GetInlineKeyboard()); + bot.getApi().sendMessage(ChatId, "Название предмета"); } else if (query->data == "tutor_back") { bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); } @@ -221,10 +201,6 @@ int main() { std::lock_guard lock(MutexForUsers); int64_t ChatId = query->message->chat->id; - if (users.find(ChatId) == users.end()) { - std::cout << "=== Error ===\n"; - } - if (NewUsers.find(ChatId) != NewUsers.end()) { if (query->data == "student") { auto student_ptr = std::make_shared(ChatId); @@ -244,8 +220,18 @@ int main() { NewUsers.erase(ChatId); return; } - + if (users.find(ChatId) == users.end()) { + std::cout << "=== Error ===\n"; + return; + } auto &user = users[ChatId]; + + if (query->data == "complete_button") { + std::cout << "sfdfdfdf\n"; + bot.getApi().sendMessage(ChatId, "_", 0, 0, user->GetMenu()); + return; + } + if (user->GetRole() == mtd::UserRole::STUDENT) { StudentCallBackQuery(bot, query, user); } else if (user->GetRole() == mtd::UserRole::OFFICE_STAFF) { @@ -276,17 +262,16 @@ int main() { bot.getApi().sendMessage(ChatId, "Оценки этого студента:\n" + s, 0, 0, user->BackButton()); return; - } - else if (user->GetState() == mtd::UserState::STUDENT_SOP) { - if (user->GetStep() == -1) { // конец + } else if (user->GetState() == mtd::UserState::STUDENT_SOP) { + if (user->GetStep() == -1) { // конец OMP.comments.push_back(message->text); + bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); } if (user->GetStep() == 1) { user->feedback.advantages = message->text; bot.getApi().sendMessage(ChatId, "Что не нравится в лекциях?"); user->GetStep()++; - } - else if (user->GetStep() == 2) { + } else if (user->GetStep() == 2) { if (user->feedback.index == 0) { user->feedback.disadvantages = message->text; mtd::LectionFeedback q; @@ -297,20 +282,19 @@ int main() { } user->GetStep()++; if (user->feedback.index < t.seminarians.size()) { - bot.getApi().sendMessage(ChatId, "Оцените практику с " + t.seminarians[user->feedback.index], 0, 0, get_raiting_scale()); - } - else { + bot.getApi().sendMessage( + ChatId, "Оцените практику с " + t.seminarians[user->feedback.index], 0, 0, + get_raiting_scale()); + } else { user->GetStep() = -1; bot.getApi().sendMessage(ChatId, "Введите какой-нибудь коммент"); } - - } - else if (user->GetStep() == 5) { + + } else if (user->GetStep() == 5) { user->feedback.advantages = message->text; bot.getApi().sendMessage(ChatId, "Что не нравится"); user->GetStep()++; - } - else if (user->GetStep() == 6) { + } else if (user->GetStep() == 6) { user->feedback.disadvantages = message->text; mtd::PracticeFeedback q; q.grade = user->feedback.grade; @@ -323,6 +307,19 @@ int main() { user->GetStep() = 2; bot.getApi().sendMessage(ChatId, "Если хотите продолжить, введите что-то"); } + } else if (user->GetState() == mtd::UserState::CREATE_SOP) { + if (user->GetStep() == 0) { + t.name_subject = message->text; + user->GetStep()++; + bot.getApi().sendMessage(ChatId, "Как зовут лектора"); + } else if (user->GetStep() == 1) { + t.lector = message->text; + user->GetStep()++; + bot.getApi().sendMessage(ChatId, "Как зовут практика", 0, 0, CompleteButton()); + } else if (user->GetStep() == 2) { + t.seminarians.push_back(message->text); + bot.getApi().sendMessage(ChatId, "Как зовут практика", 0, 0, CompleteButton()); + } } }); try { diff --git a/source/statistics.cpp b/source/statistics.cpp new file mode 100644 index 0000000..bc1d317 --- /dev/null +++ b/source/statistics.cpp @@ -0,0 +1,71 @@ +#include "statistics.hpp" + +#include + +float calculate_average_grade(const std::vector& lections, + const std::vector& practices) { + int total_grade = 0; + int total_count = 0; + + // Суммируем оценки по лекциям + for (const auto& lection : lections) { + total_grade += lection.grade; + total_count++; + } + + // Суммируем оценки по практикам + for (const auto& practice : practices) { + total_grade += practice.grade; + total_count++; + } + + return total_count > 0 ? static_cast(total_grade) / total_count : 0.0f; +} + +std::string generate_statistics(const mtd::Subject& subject) { + std::stringstream ss; + + ss << "Статистика по предмету: " << subject.name_subject << "\n\n"; + + ss << "Лекции:\n"; + if (subject.lections_result.empty()) { + ss << "Нет отзывов по лекциям.\n"; + } else { + for (const auto& lection : subject.lections_result) { + ss << "Оценка: " << lection.grade << "\n"; + ss << "Что нравится: " << (lection.advantages.empty() ? "Нет" : lection.advantages) + << "\n"; + ss << "Что не нравится: " + << (lection.disadvantages.empty() ? "Нет" : lection.disadvantages) << "\n\n"; + } + } + + ss << "Практики:\n"; + if (subject.practice_result.empty()) { + ss << "Нет отзывов по практикам.\n"; + } else { + for (const auto& practice : subject.practice_result) { + ss << "Преподаватель: " << practice.name_teacher << "\n"; + ss << "Оценка: " << practice.grade << "\n"; + ss << "Оценка за домашку: " << practice.grade_for_homework << "\n"; + ss << "Что нравится: " << (practice.advantages.empty() ? "Нет" : practice.advantages) + << "\n"; + ss << "Что не нравится: " + << (practice.disadvantages.empty() ? "Нет" : practice.disadvantages) << "\n\n"; + } + } + + if (!subject.comments.empty()) { + ss << "Комментарии:\n"; + for (const auto& comment : subject.comments) { + ss << "- " << comment << "\n"; + } + } else { + ss << "Нет комментариев.\n"; + } + + float average_grade = calculate_average_grade(subject.lections_result, subject.practice_result); + ss << "\nСредняя оценка по предмету: " << average_grade << "\n"; + + return ss.str(); +} From 604cc143ec337f818f59d1e685932b0703cd78c0 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 26 Feb 2025 00:01:11 +0300 Subject: [PATCH 20/55] fdfssdf --- include/OfficeStaff.hpp | 2 +- include/Student.hpp | 2 +- include/Teacher.hpp | 2 +- include/User.hpp | 5 ++--- source/OfficeStaff.cpp | 2 ++ source/Student.cpp | 2 ++ source/Teacher.cpp | 2 ++ source/User.cpp | 4 ++++ 8 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/OfficeStaff.hpp b/include/OfficeStaff.hpp index f373890..446d9b4 100644 --- a/include/OfficeStaff.hpp +++ b/include/OfficeStaff.hpp @@ -6,7 +6,7 @@ namespace mtd { class OfficeStaff : public User { public: - OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) {} + OfficeStaff(int64_t chat_id); TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; diff --git a/include/Student.hpp b/include/Student.hpp index 6512369..4264fe4 100644 --- a/include/Student.hpp +++ b/include/Student.hpp @@ -6,7 +6,7 @@ namespace mtd { class Student : public User { public: - Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) {} + Student(int64_t chat_id); TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; diff --git a/include/Teacher.hpp b/include/Teacher.hpp index 009bb8e..6cab586 100644 --- a/include/Teacher.hpp +++ b/include/Teacher.hpp @@ -6,7 +6,7 @@ namespace mtd { class Teacher : public User { public: - Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) {} + Teacher(int64_t chat_id); TgBot::InlineKeyboardMarkup::Ptr GetInlineKeyboard() override; TgBot::InlineKeyboardMarkup::Ptr GetMenu() override; TgBot::InlineKeyboardMarkup::Ptr BackButton() override; diff --git a/include/User.hpp b/include/User.hpp index cad3639..a4da434 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -20,9 +20,8 @@ class User { std::vector evaluations; public: - explicit User(int64_t chat_id, UserRole role) - : chat_id(chat_id), role(role), state(UserState::NONE) {} - virtual ~User() {} + explicit User(int64_t chat_id, UserRole role); + virtual ~User(); Feedback feedback; int64_t id() const; UserRole GetRole() const; diff --git a/source/OfficeStaff.cpp b/source/OfficeStaff.cpp index 4019a29..006a81f 100644 --- a/source/OfficeStaff.cpp +++ b/source/OfficeStaff.cpp @@ -1,6 +1,8 @@ #include "OfficeStaff.hpp" namespace mtd { +OfficeStaff::OfficeStaff(int64_t chat_id) : User(chat_id, UserRole::OFFICE_STAFF) { +} TgBot::InlineKeyboardMarkup::Ptr OfficeStaff::GetInlineKeyboard() { TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); diff --git a/source/Student.cpp b/source/Student.cpp index a30832f..b7d2709 100644 --- a/source/Student.cpp +++ b/source/Student.cpp @@ -1,6 +1,8 @@ #include "Student.hpp" namespace mtd { +Student::Student(int64_t chat_id) : User(chat_id, UserRole::STUDENT) { +} TgBot::InlineKeyboardMarkup::Ptr Student::GetInlineKeyboard() { TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); diff --git a/source/Teacher.cpp b/source/Teacher.cpp index 3a3594d..eca9acf 100644 --- a/source/Teacher.cpp +++ b/source/Teacher.cpp @@ -1,6 +1,8 @@ #include "Teacher.hpp" namespace mtd { +Teacher::Teacher(int64_t chat_id) : User(chat_id, UserRole::TEACHER) { +} TgBot::InlineKeyboardMarkup::Ptr Teacher::GetInlineKeyboard() { TgBot::InlineKeyboardMarkup::Ptr inlineKeyboard(new TgBot::InlineKeyboardMarkup); diff --git a/source/User.cpp b/source/User.cpp index 9ac3d94..e6ad1f8 100644 --- a/source/User.cpp +++ b/source/User.cpp @@ -1,6 +1,10 @@ #include "User.hpp" namespace mtd { +User::User(int64_t chat_id, UserRole role) : chat_id(chat_id), role(role), state(UserState::NONE) { +} +User::~User() { +} int &User::GetStep() { return step; } From bc0b7e8c4958a77aa9d7b75cd3a8960a4a5121c2 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 00:18:45 +0300 Subject: [PATCH 21/55] create .github --- .github/workflows/clang-checks.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/clang-checks.yml diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml new file mode 100644 index 0000000..c8bf6db --- /dev/null +++ b/.github/workflows/clang-checks.yml @@ -0,0 +1,30 @@ +name: Clang Checks + +on: + pull_request: + branches: + - dev/meytardzhevtd + +defaults: + run: + working-directory: . + +jobs: + clang-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Clang tools + run: sudo apt-get install -y clang-format clang-tidy + + - name: Run Clang Format + run: | + find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + + - name: Run Clang Tidy + run: | + find source -name '*.cpp' | xargs clang-tidy --warnings-as-errors=* From 5ce0bf0dc9f4f021f77563cf783c5ae0c532b690 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 00:20:38 +0300 Subject: [PATCH 22/55] create .github --- .github/workflows/clang-checks.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index c8bf6db..07f56eb 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -1,9 +1,12 @@ name: Clang Checks on: + push: + branches: + - dev/meytardzhevtd pull_request: branches: - - dev/meytardzhevtd + - pre-main defaults: run: From 14a780dd806b8e757daa5c3a314596bd5779d427 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 01:00:24 +0300 Subject: [PATCH 23/55] renode .github --- .github/workflows/clang-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 07f56eb..e018646 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -3,7 +3,7 @@ name: Clang Checks on: push: branches: - - dev/meytardzhevtd + - '**' pull_request: branches: - pre-main From 7af99d6d7d3b561a980af65e65a0e40d5b62ad90 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 11:53:59 +0300 Subject: [PATCH 24/55] redone .github --- .github/workflows/clang-checks.yml | 31 ++++++------------------------ 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index e018646..628a14a 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -1,33 +1,14 @@ name: Clang Checks - on: push: branches: - '**' - pull_request: - branches: - - pre-main - defaults: run: - working-directory: . - + working-directory: EntryPoint jobs: - clang-check: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install Clang tools - run: sudo apt-get install -y clang-format clang-tidy - - - name: Run Clang Format - run: | - find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i - git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) - - - name: Run Clang Tidy - run: | - find source -name '*.cpp' | xargs clang-tidy --warnings-as-errors=* + c: + uses: ./.github/workflows/clang-checks.yml + with: + working_directory: EntryPoint + simple_compilation_name: my_bot From 17b2b1aa374b63ed55bc82d827b98396e65cb039 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 11:58:48 +0300 Subject: [PATCH 25/55] redone .github --- .github/workflows/clang-checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 628a14a..6f5c5b3 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -5,10 +5,10 @@ on: - '**' defaults: run: - working-directory: EntryPoint + working-directory: .. jobs: c: uses: ./.github/workflows/clang-checks.yml with: - working_directory: EntryPoint + working_directory: .. simple_compilation_name: my_bot From 752ff82e61cd9d0fed366caf67e06c6f57a6e5a9 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 11:59:54 +0300 Subject: [PATCH 26/55] redone .github --- .github/workflows/clang-checks.yml | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 6f5c5b3..e018646 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -1,14 +1,33 @@ name: Clang Checks + on: push: branches: - '**' + pull_request: + branches: + - pre-main + defaults: run: - working-directory: .. + working-directory: . + jobs: - c: - uses: ./.github/workflows/clang-checks.yml - with: - working_directory: .. - simple_compilation_name: my_bot + clang-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Clang tools + run: sudo apt-get install -y clang-format clang-tidy + + - name: Run Clang Format + run: | + find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + + - name: Run Clang Tidy + run: | + find source -name '*.cpp' | xargs clang-tidy --warnings-as-errors=* From 5bee22b41229d507038a2dfca1d9e8b127e4e9de Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:02:19 +0300 Subject: [PATCH 27/55] redone .github --- .github/workflows/clang-checks.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index e018646..9dc7a89 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -10,7 +10,7 @@ on: defaults: run: - working-directory: . + working-directory: . jobs: clang-check: @@ -23,6 +23,9 @@ jobs: - name: Install Clang tools run: sudo apt-get install -y clang-format clang-tidy + - name: Generate compile_commands.json + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + - name: Run Clang Format run: | find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i @@ -30,4 +33,4 @@ jobs: - name: Run Clang Tidy run: | - find source -name '*.cpp' | xargs clang-tidy --warnings-as-errors=* + find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* From 0fef003c3956c3473623e3688903faea0228ab26 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:06:41 +0300 Subject: [PATCH 28/55] redone .github --- .github/workflows/clang-checks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 9dc7a89..84b33a1 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -20,10 +20,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Install Clang tools - run: sudo apt-get install -y clang-format clang-tidy + - name: Install dependencies + run: sudo apt-get install -y clang-format clang-tidy libboost-all-dev - - name: Generate compile_commands.json + - name: Configure CMake run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Run Clang Format From dcea22fd695c6ffbd31e22546f8c961ded89247f Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:08:34 +0300 Subject: [PATCH 29/55] redone .github --- .github/workflows/clang-checks.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 84b33a1..7c83077 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -23,8 +23,18 @@ jobs: - name: Install dependencies run: sudo apt-get install -y clang-format clang-tidy libboost-all-dev + - name: Install TgBot + run: | + git clone https://github.com/reo7sp/tgbot-cpp.git + cd tgbot-cpp + mkdir build + cd build + cmake .. + make -j$(nproc) + sudo make install + - name: Configure CMake - run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - name: Run Clang Format run: | From ba341bd7e5640fa761ab6bcca28cf2bb3afa1318 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:20:12 +0300 Subject: [PATCH 30/55] redone .github --- .github/workflows/clang-checks.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 7c83077..291c0b9 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v3 - name: Install dependencies - run: sudo apt-get install -y clang-format clang-tidy libboost-all-dev + run: sudo apt-get install -y clang-format clang-tidy libboost-all-dev cppcheck - name: Install TgBot run: | @@ -29,7 +29,7 @@ jobs: cd tgbot-cpp mkdir build cd build - cmake .. + cmake .. make -j$(nproc) sudo make install @@ -44,3 +44,7 @@ jobs: - name: Run Clang Tidy run: | find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* + + - name: Run Cppcheck + run: | + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 source include From 7023def716c820534210ab661105c92dff8c2cd9 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:24:27 +0300 Subject: [PATCH 31/55] redone .github --- .github/workflows/clang-checks.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 291c0b9..3bf711e 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -21,7 +21,11 @@ jobs: uses: actions/checkout@v3 - name: Install dependencies - run: sudo apt-get install -y clang-format clang-tidy libboost-all-dev cppcheck + run: | + sudo apt-get update + sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ + libcurl4-openssl-dev libpq-dev \ + nlohmann-json3-dev libpqxx-dev - name: Install TgBot run: | @@ -29,7 +33,7 @@ jobs: cd tgbot-cpp mkdir build cd build - cmake .. + cmake .. make -j$(nproc) sudo make install @@ -45,6 +49,6 @@ jobs: run: | find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* - - name: Run Cppcheck + - name: Run CppCheck run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 source include + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json From 509a93695ba70f28dd32f0508eeb2e4f44663160 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:45:33 +0300 Subject: [PATCH 32/55] redone .github --- .github/workflows/clang-checks.yml | 60 ++++++++++++++++--- .github/workflows/installing-dependencies.yml | 15 +++++ 2 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/installing-dependencies.yml diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 3bf711e..64adbec 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -1,4 +1,4 @@ -name: Clang Checks +name: Static Analysis Checks on: push: @@ -13,19 +13,14 @@ defaults: working-directory: . jobs: - clang-check: + install-deps: runs-on: ubuntu-latest - steps: - name: Checkout repository uses: actions/checkout@v3 - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ - libcurl4-openssl-dev libpq-dev \ - nlohmann-json3-dev libpqxx-dev + uses: ./.github/workflows/installing-dependencies.yml - name: Install TgBot run: | @@ -33,22 +28,69 @@ jobs: cd tgbot-cpp mkdir build cd build - cmake .. + cmake .. make -j$(nproc) sudo make install + - name: Cache Build Directory + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-build- + - name: Configure CMake run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot + clang-format: + needs: install-deps + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + - name: Run Clang Format run: | find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + clang-tidy: + needs: install-deps + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + - name: Run Clang Tidy run: | find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* + cppcheck: + needs: install-deps + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + - name: Run CppCheck run: | cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json diff --git a/.github/workflows/installing-dependencies.yml b/.github/workflows/installing-dependencies.yml new file mode 100644 index 0000000..3d44e7a --- /dev/null +++ b/.github/workflows/installing-dependencies.yml @@ -0,0 +1,15 @@ +name: Install Dependencies + +on: + workflow_call: + +jobs: + install-deps: + runs-on: ubuntu-latest + steps: + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ + libcurl4-openssl-dev libpq-dev \ + nlohmann-json3-dev libpqxx-dev \ No newline at end of file From 2ad9e79114ac3f8e5f07587a24f8fc6196d1d703 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:46:43 +0300 Subject: [PATCH 33/55] redone .github --- .github/workflows/clang-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 64adbec..31cd775 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v3 - name: Install dependencies - uses: ./.github/workflows/installing-dependencies.yml + uses: .github/workflows/installing-dependencies.yml - name: Install TgBot run: | From 10d64b3ffe32359a6185956aac8157e3fbad2891 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:47:21 +0300 Subject: [PATCH 34/55] redone .github --- .github/workflows/clang-checks.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 31cd775..d8d9a00 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -20,7 +20,11 @@ jobs: uses: actions/checkout@v3 - name: Install dependencies - uses: .github/workflows/installing-dependencies.yml + run: | + sudo apt-get update + sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ + libcurl4-openssl-dev libpq-dev \ + nlohmann-json3-dev libpqxx-dev - name: Install TgBot run: | From fb9be1b9ae7f53bfbbb72eb1cf5977de433763a1 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:52:39 +0300 Subject: [PATCH 35/55] redone .github --- .github/workflows/CppCheck-Analysis.yml | 26 +++++++++++++++++++++++++ .github/workflows/clang-checks.yml | 19 ------------------ 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/CppCheck-Analysis.yml diff --git a/.github/workflows/CppCheck-Analysis.yml b/.github/workflows/CppCheck-Analysis.yml new file mode 100644 index 0000000..083a906 --- /dev/null +++ b/.github/workflows/CppCheck-Analysis.yml @@ -0,0 +1,26 @@ +name: CppCheck Analysis + +on: + push: + branches: + - '**' + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y cppcheck + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + - name: Run CppCheck + run: | + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index d8d9a00..8d74074 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -4,9 +4,6 @@ on: push: branches: - '**' - pull_request: - branches: - - pre-main defaults: run: @@ -82,19 +79,3 @@ jobs: run: | find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* - cppcheck: - needs: install-deps - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Restore Cached Build - uses: actions/cache@v3 - with: - path: build - key: ${{ runner.os }}-build-${{ github.sha }} - - - name: Run CppCheck - run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json From a6709f3f610361efa3c9195fc2a7b5d0a6b37fb1 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 12:58:25 +0300 Subject: [PATCH 36/55] redone .github --- .github/workflows/clang-checks.yml | 17 ---------------- .github/workflows/clang-format-chec.yml | 26 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/clang-format-chec.yml diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 8d74074..9dde38d 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -44,23 +44,6 @@ jobs: - name: Configure CMake run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - clang-format: - needs: install-deps - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Restore Cached Build - uses: actions/cache@v3 - with: - path: build - key: ${{ runner.os }}-build-${{ github.sha }} - - - name: Run Clang Format - run: | - find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i - git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) clang-tidy: needs: install-deps diff --git a/.github/workflows/clang-format-chec.yml b/.github/workflows/clang-format-chec.yml new file mode 100644 index 0000000..af424de --- /dev/null +++ b/.github/workflows/clang-format-chec.yml @@ -0,0 +1,26 @@ +name: Clang Format Check + +on: + pull_request: + branches: + - pre-main + +jobs: + clang-format: + needs: install-deps + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + + - name: Run Clang Format + run: | + find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) From 96f2e9e768860e668f70ca73fb37e9e64f229e0b Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 4 Mar 2025 13:13:30 +0300 Subject: [PATCH 37/55] redone .github --- .../workflows/{clang-format-chec.yml => clang-format-check.yml} | 0 CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{clang-format-chec.yml => clang-format-check.yml} (100%) diff --git a/.github/workflows/clang-format-chec.yml b/.github/workflows/clang-format-check.yml similarity index 100% rename from .github/workflows/clang-format-chec.yml rename to .github/workflows/clang-format-check.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index b745b36..12fcbec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.30) project(TelegramBot) # Устанавливаем стандарт C++ set(CMAKE_CXX_STANDARD 20) From ea3a1c03b86f7e3a4eae561208193871254b9bf1 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 11:24:50 +0300 Subject: [PATCH 38/55] redone .yml --- .github/workflows/CppCheck-Analysis.yml | 37 +++++++++++- .github/workflows/ci.yml | 59 +++++++++++++++++++ .github/workflows/clang-checks.yml | 25 ++++++-- .github/workflows/clang-format-check.yml | 23 ++++---- .github/workflows/installing-dependencies.yml | 15 ----- CMakeLists.txt | 2 +- cmake/CPM.cmake | 24 ++++++++ 7 files changed, 150 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/installing-dependencies.yml create mode 100644 cmake/CPM.cmake diff --git a/.github/workflows/CppCheck-Analysis.yml b/.github/workflows/CppCheck-Analysis.yml index 083a906..ad02105 100644 --- a/.github/workflows/CppCheck-Analysis.yml +++ b/.github/workflows/CppCheck-Analysis.yml @@ -16,11 +16,42 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y cppcheck + sudo apt-get install -y cppcheck libboost-all-dev libssl-dev + + - name: Cache TgBot + id: cache-tgbot + uses: actions/cache@v3 + with: + path: | + /usr/local/lib/libTgBot.so + /usr/local/include/tgbot + key: tgbot-${{ runner.os }}-v1 + + - name: Install TgBot + if: steps.cache-tgbot.outputs.cache-hit != 'true' + run: | + git clone https://github.com/reo7sp/tgbot-cpp.git + cd tgbot-cpp + mkdir build && cd build + cmake .. + make -j$(nproc) + sudo make install - name: Configure CMake - run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot + + - name: Cache CppCheck results + uses: actions/cache@v3 + with: + path: .cppcheck_cache + key: cppcheck-${{ runner.os }}-${{ github.sha }} + restore-keys: | + cppcheck-${{ runner.os }}- - name: Run CppCheck run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json + mkdir -p .cppcheck_cache + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 \ + --project=build/compile_commands.json \ + --cppcheck-build-dir=.cppcheck_cache \ + source include diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..655ff91 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: C++ CI + +on: + push: + branches: + - '**' + +jobs: + analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y clang-tidy clang-format cppcheck libboost-all-dev libssl-dev + + - name: Cache tgbot-cpp + id: cache-tgbot + uses: actions/cache@v4 + with: + path: /usr/local/lib/libTgBot.so + key: tgbot-${{ runner.os }}-v1 + + - name: Build tgbot-cpp + if: steps.cache-tgbot.outputs.cache-hit != 'true' + run: | + git clone https://github.com/reo7sp/tgbot-cpp.git + cd tgbot-cpp + mkdir build && cd build + cmake .. + make -j$(nproc) + sudo make install + + - name: Run clang-tidy (only changed files) + run: | + git fetch origin main + CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '\.(cpp|h)$' || echo "") + if [[ -n "$CHANGED_FILES" ]]; then + clang-tidy $CHANGED_FILES -- -I./include || true + else + echo "No C++ files changed." + fi + + - name: Run clang-format (only changed files) + run: | + git fetch origin main + CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '\.(cpp|h)$' || echo "") + if [[ -n "$CHANGED_FILES" ]]; then + clang-format -i $CHANGED_FILES || true + else + echo "No C++ files changed." + fi + + - name: Run cppcheck + run: cppcheck --enable=all --inconclusive --quiet --std=c++17 --suppress=missingIncludeSystem . diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-checks.yml index 9dde38d..06ea04f 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-checks.yml @@ -23,7 +23,17 @@ jobs: libcurl4-openssl-dev libpq-dev \ nlohmann-json3-dev libpqxx-dev + - name: Cache TgBot + id: cache-tgbot + uses: actions/cache@v3 + with: + path: | + /usr/local/lib/libTgBot.so + /usr/local/include/tgbot + key: tgbot-${{ runner.os }}-v1 + - name: Install TgBot + if: steps.cache-tgbot.outputs.cache-hit != 'true' run: | git clone https://github.com/reo7sp/tgbot-cpp.git cd tgbot-cpp @@ -33,6 +43,9 @@ jobs: make -j$(nproc) sudo make install + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot + - name: Cache Build Directory uses: actions/cache@v3 with: @@ -41,10 +54,6 @@ jobs: restore-keys: | ${{ runner.os }}-build- - - name: Configure CMake - run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - - clang-tidy: needs: install-deps runs-on: ubuntu-latest @@ -60,5 +69,9 @@ jobs: - name: Run Clang Tidy run: | - find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* - + CHANGED_FILES=$(git ls-files '*.cpp' '*.h') + if [[ -n "$CHANGED_FILES" ]]; then + echo "$CHANGED_FILES" | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* + else + echo "No C++ files found." + fi diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index af424de..51b67d6 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -1,26 +1,29 @@ name: Clang Format Check on: - pull_request: + push: branches: - - pre-main + - '**' jobs: clang-format: - needs: install-deps runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Restore Cached Build - uses: actions/cache@v3 - with: - path: build - key: ${{ runner.os }}-build-${{ github.sha }} + - name: Install Clang Format + run: | + sudo apt-get update + sudo apt-get install -y clang-format - name: Run Clang Format run: | - find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i - git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + CHANGED_FILES=$(git ls-files '*.cpp' '*.h') + if [[ -n "$CHANGED_FILES" ]]; then + echo "$CHANGED_FILES" | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) + else + echo "No C++ files found." + fi diff --git a/.github/workflows/installing-dependencies.yml b/.github/workflows/installing-dependencies.yml deleted file mode 100644 index 3d44e7a..0000000 --- a/.github/workflows/installing-dependencies.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Install Dependencies - -on: - workflow_call: - -jobs: - install-deps: - runs-on: ubuntu-latest - steps: - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ - libcurl4-openssl-dev libpq-dev \ - nlohmann-json3-dev libpqxx-dev \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 12fcbec..b745b36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.30) +cmake_minimum_required(VERSION 3.10) project(TelegramBot) # Устанавливаем стандарт C++ set(CMAKE_CXX_STANDARD 20) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..f8f2c89 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.6) +set(CPM_HASH_SUM "3440292907e35353bf0761049d3680e9ed0031443c8ebeb9cbb6a421c4550ec1") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) From 3bdc9e09b3e6d8c998967702efe020b3722a04cb Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 12:03:40 +0300 Subject: [PATCH 39/55] sdfs --- .github/workflows/CppCheck-Analysis.yml | 57 ------------------ .github/workflows/ci.yml | 59 ------------------- .github/workflows/clang-format-check.yml | 48 +++++++++++---- .../{clang-checks.yml => clang-tidy.yml} | 25 ++------ .github/workflows/cppcheck.yml | 26 ++++++++ 5 files changed, 70 insertions(+), 145 deletions(-) delete mode 100644 .github/workflows/CppCheck-Analysis.yml delete mode 100644 .github/workflows/ci.yml rename .github/workflows/{clang-checks.yml => clang-tidy.yml} (72%) create mode 100644 .github/workflows/cppcheck.yml diff --git a/.github/workflows/CppCheck-Analysis.yml b/.github/workflows/CppCheck-Analysis.yml deleted file mode 100644 index ad02105..0000000 --- a/.github/workflows/CppCheck-Analysis.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: CppCheck Analysis - -on: - push: - branches: - - '**' - -jobs: - cppcheck: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y cppcheck libboost-all-dev libssl-dev - - - name: Cache TgBot - id: cache-tgbot - uses: actions/cache@v3 - with: - path: | - /usr/local/lib/libTgBot.so - /usr/local/include/tgbot - key: tgbot-${{ runner.os }}-v1 - - - name: Install TgBot - if: steps.cache-tgbot.outputs.cache-hit != 'true' - run: | - git clone https://github.com/reo7sp/tgbot-cpp.git - cd tgbot-cpp - mkdir build && cd build - cmake .. - make -j$(nproc) - sudo make install - - - name: Configure CMake - run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - - - name: Cache CppCheck results - uses: actions/cache@v3 - with: - path: .cppcheck_cache - key: cppcheck-${{ runner.os }}-${{ github.sha }} - restore-keys: | - cppcheck-${{ runner.os }}- - - - name: Run CppCheck - run: | - mkdir -p .cppcheck_cache - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 \ - --project=build/compile_commands.json \ - --cppcheck-build-dir=.cppcheck_cache \ - source include diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 655ff91..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: C++ CI - -on: - push: - branches: - - '**' - -jobs: - analyze: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y clang-tidy clang-format cppcheck libboost-all-dev libssl-dev - - - name: Cache tgbot-cpp - id: cache-tgbot - uses: actions/cache@v4 - with: - path: /usr/local/lib/libTgBot.so - key: tgbot-${{ runner.os }}-v1 - - - name: Build tgbot-cpp - if: steps.cache-tgbot.outputs.cache-hit != 'true' - run: | - git clone https://github.com/reo7sp/tgbot-cpp.git - cd tgbot-cpp - mkdir build && cd build - cmake .. - make -j$(nproc) - sudo make install - - - name: Run clang-tidy (only changed files) - run: | - git fetch origin main - CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '\.(cpp|h)$' || echo "") - if [[ -n "$CHANGED_FILES" ]]; then - clang-tidy $CHANGED_FILES -- -I./include || true - else - echo "No C++ files changed." - fi - - - name: Run clang-format (only changed files) - run: | - git fetch origin main - CHANGED_FILES=$(git diff --name-only origin/main...HEAD | grep -E '\.(cpp|h)$' || echo "") - if [[ -n "$CHANGED_FILES" ]]; then - clang-format -i $CHANGED_FILES || true - else - echo "No C++ files changed." - fi - - - name: Run cppcheck - run: cppcheck --enable=all --inconclusive --quiet --std=c++17 --suppress=missingIncludeSystem . diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 51b67d6..bbcb846 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -7,23 +7,51 @@ on: jobs: clang-format: + install-deps: runs-on: ubuntu-latest - steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Install Clang Format + - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y clang-format + sudo apt-get install -y clang-format clang-tidy libboost-all-dev \ + libcurl4-openssl-dev libpq-dev \ + nlohmann-json3-dev libpqxx-dev + + - name: Install TgBot + run: | + git clone https://github.com/reo7sp/tgbot-cpp.git + cd tgbot-cpp + mkdir build + cd build + cmake .. + make -j$(nproc) + sudo make install + + - name: Cache Build Directory + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-build- + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Restore Cached Build + uses: actions/cache@v3 + with: + path: build + key: ${{ runner.os }}-build-${{ github.sha }} - name: Run Clang Format run: | - CHANGED_FILES=$(git ls-files '*.cpp' '*.h') - if [[ -n "$CHANGED_FILES" ]]; then - echo "$CHANGED_FILES" | xargs clang-format -i - git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) - else - echo "No C++ files found." - fi + find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i + git diff --exit-code || (echo "Clang format check failed! Run clang-format and commit changes."; exit 1) diff --git a/.github/workflows/clang-checks.yml b/.github/workflows/clang-tidy.yml similarity index 72% rename from .github/workflows/clang-checks.yml rename to .github/workflows/clang-tidy.yml index 06ea04f..9dde38d 100644 --- a/.github/workflows/clang-checks.yml +++ b/.github/workflows/clang-tidy.yml @@ -23,17 +23,7 @@ jobs: libcurl4-openssl-dev libpq-dev \ nlohmann-json3-dev libpqxx-dev - - name: Cache TgBot - id: cache-tgbot - uses: actions/cache@v3 - with: - path: | - /usr/local/lib/libTgBot.so - /usr/local/include/tgbot - key: tgbot-${{ runner.os }}-v1 - - name: Install TgBot - if: steps.cache-tgbot.outputs.cache-hit != 'true' run: | git clone https://github.com/reo7sp/tgbot-cpp.git cd tgbot-cpp @@ -43,9 +33,6 @@ jobs: make -j$(nproc) sudo make install - - name: Configure CMake - run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - - name: Cache Build Directory uses: actions/cache@v3 with: @@ -54,6 +41,10 @@ jobs: restore-keys: | ${{ runner.os }}-build- + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot + + clang-tidy: needs: install-deps runs-on: ubuntu-latest @@ -69,9 +60,5 @@ jobs: - name: Run Clang Tidy run: | - CHANGED_FILES=$(git ls-files '*.cpp' '*.h') - if [[ -n "$CHANGED_FILES" ]]; then - echo "$CHANGED_FILES" | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* - else - echo "No C++ files found." - fi + find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* + diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..083a906 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,26 @@ +name: CppCheck Analysis + +on: + push: + branches: + - '**' + +jobs: + cppcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y cppcheck + + - name: Configure CMake + run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + - name: Run CppCheck + run: | + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json From 005c914b3cd0f34b99d75851e90b134e491df0bf Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 13:23:20 +0300 Subject: [PATCH 40/55] I can do itgit add .git add . --- CMakeLists.txt | 44 ++++++++++++++++++-------------------------- cmake/CPM.cmake | 4 ++-- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b745b36..c4d1bae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,28 @@ -cmake_minimum_required(VERSION 3.10) -project(TelegramBot) -# Устанавливаем стандарт C++ -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -# Поиск необходимых библиотек -find_package(Boost REQUIRED COMPONENTS system) -find_package(TgBot REQUIRED) +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +project(MyProject) include_directories(include) - file(GLOB SOURCES source/*.cpp) +add_executable(main ${SOURCES}) -add_executable(my_bot ${SOURCES}) - +include(cmake/CPM.cmake) -target_link_libraries(my_bot Boost::system TgBot::TgBot) +CPMAddPackage( + NAME Boost + VERSION 1.86.0 + URL https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-cmake.tar.xz + URL_HASH SHA256=2c5ec5edcdff47ff55e27ed9560b0a0b94b07bd07ed9928b476150e16b0efc57 + OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_SKIP_INSTALL_RULES ON" + "BUILD_SHARED_LIBS OFF" "BOOST_INCLUDE_LIBRARIES system" +) +CPMAddPackage( + NAME TgBot + GIT_REPOSITORY https://github.com/reo7sp/tgbot-cpp.git + GIT_TAG master +) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_options(my_bot PRIVATE - -g - -fsanitize=address,undefined - -fno-omit-frame-pointer - ) - target_link_options(my_bot PRIVATE - -fsanitize=address,undefined - -fno-omit-frame-pointer - ) -endif() \ No newline at end of file +target_link_libraries(main Boost::system TgBot) \ No newline at end of file diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index f8f2c89..9d87d01 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -2,8 +2,8 @@ # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors -set(CPM_DOWNLOAD_VERSION 0.40.6) -set(CPM_HASH_SUM "3440292907e35353bf0761049d3680e9ed0031443c8ebeb9cbb6a421c4550ec1") +set(CPM_DOWNLOAD_VERSION 0.40.7) +set(CPM_HASH_SUM "c0fc82149e00c43a21febe7b2ca57b2ffea2b8e88ab867022c21d6b81937eb50") if(CPM_SOURCE_CACHE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") From 9726748e7262b1323aa948ac32e256057e956098 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:16:09 +0300 Subject: [PATCH 41/55] redone cppcheck --- .github/workflows/cppcheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 083a906..87b3bd2 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -23,4 +23,4 @@ jobs: - name: Run CppCheck run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json --exclude=build From 39b3a08478b65543ece67f439f87f6312180f587 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:25:46 +0300 Subject: [PATCH 42/55] redone cppcheck --- .github/workflows/cppcheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 87b3bd2..a1d5e54 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -23,4 +23,4 @@ jobs: - name: Run CppCheck run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json --exclude=build + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json --suppress=build/* From 7d66cdf3e5648089aa8870f60fcfd4ce19bd1e2b Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:29:54 +0300 Subject: [PATCH 43/55] redone cppcheck --- .github/workflows/cppcheck.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index a1d5e54..ac0c884 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -23,4 +23,5 @@ jobs: - name: Run CppCheck run: | - cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 --project=build/compile_commands.json --suppress=build/* + # Указываем CppCheck проверять только исходные файлы в папке source или include + cppcheck --enable=all --inconclusive --quiet --error-exitcode=1 source/ include/ From ab19efff6924e35fc305527af5a51d5122d5d067 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:36:12 +0300 Subject: [PATCH 44/55] redone cppcheck --- .github/workflows/clang-format-check.yml | 18 +++++++----------- .github/workflows/clang-tidy.yml | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index bbcb846..ca3d77d 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -7,12 +7,14 @@ on: jobs: clang-format: - install-deps: runs-on: ubuntu-latest + steps: + # Шаг 1: Checkout репозитория - name: Checkout repository uses: actions/checkout@v3 + # Шаг 2: Установка зависимостей - name: Install dependencies run: | sudo apt-get update @@ -20,6 +22,7 @@ jobs: libcurl4-openssl-dev libpq-dev \ nlohmann-json3-dev libpqxx-dev + # Шаг 3: Установка TgBot - name: Install TgBot run: | git clone https://github.com/reo7sp/tgbot-cpp.git @@ -30,6 +33,7 @@ jobs: make -j$(nproc) sudo make install + # Шаг 4: Кэширование директории сборки - name: Cache Build Directory uses: actions/cache@v3 with: @@ -38,19 +42,11 @@ jobs: restore-keys: | ${{ runner.os }}-build- + # Шаг 5: Конфигурация CMake - name: Configure CMake run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DTgBot_DIR=/usr/local/lib/cmake/TgBot - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Restore Cached Build - uses: actions/cache@v3 - with: - path: build - key: ${{ runner.os }}-build-${{ github.sha }} - + # Шаг 6: Запуск Clang Format - name: Run Clang Format run: | find include source -name '*.cpp' -o -name '*.h' | xargs clang-format -i diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 9dde38d..fb106e4 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -29,7 +29,7 @@ jobs: cd tgbot-cpp mkdir build cd build - cmake .. + cmake .. make -j$(nproc) sudo make install @@ -60,5 +60,5 @@ jobs: - name: Run Clang Tidy run: | + # Найдем все исходные файлы (.cpp и .h) в нужных папках (source, include), исключая build find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* - From 1f180ccc220c22bc88c071a4f9826219b712ab9c Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:42:53 +0300 Subject: [PATCH 45/55] redone cppcheck --- .github/workflows/clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index fb106e4..fe4ad22 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -61,4 +61,4 @@ jobs: - name: Run Clang Tidy run: | # Найдем все исходные файлы (.cpp и .h) в нужных папках (source, include), исключая build - find source include -name '*.cpp' -o -name '*.h' | xargs clang-tidy -p build --extra-arg="-Iinclude" --warnings-as-errors=* + clang-tidy --enable=all --inconclusive --quiet --error-exitcode=1 source/ include/ From 63e1d05ba202d4c4a85a2f4a7e30ca8b75134e30 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Wed, 5 Mar 2025 14:45:38 +0300 Subject: [PATCH 46/55] redone cppcheck --- .github/workflows/clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index fe4ad22..8acdfbe 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -61,4 +61,4 @@ jobs: - name: Run Clang Tidy run: | # Найдем все исходные файлы (.cpp и .h) в нужных папках (source, include), исключая build - clang-tidy --enable=all --inconclusive --quiet --error-exitcode=1 source/ include/ + clang-tidy source/*.cpp include/*.hpp From bfa4221039af5b93cdbed06bb10953badcd371e5 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 9 Mar 2025 12:11:09 +0300 Subject: [PATCH 47/55] fdsfdf --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4d1bae..192d232 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(main ${SOURCES}) include(cmake/CPM.cmake) +# Boost CPMAddPackage( NAME Boost VERSION 1.86.0 @@ -19,10 +20,15 @@ CPMAddPackage( "BUILD_SHARED_LIBS OFF" "BOOST_INCLUDE_LIBRARIES system" ) +# TgBot CPMAddPackage( NAME TgBot GIT_REPOSITORY https://github.com/reo7sp/tgbot-cpp.git GIT_TAG master ) -target_link_libraries(main Boost::system TgBot) \ No newline at end of file +# Линкуем библиотеки +target_link_libraries(main + Boost::system + TgBot +) From d564748a17b99d4a00ef582fe4259df3ff61e380 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 9 Mar 2025 12:25:26 +0300 Subject: [PATCH 48/55] add library --- CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 192d232..0ef3858 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,21 @@ CPMAddPackage( GIT_TAG master ) +# nlohmann/json +CPMAddPackage( + NAME nlohmann_json + VERSION 3.11.2 + GITHUB_REPOSITORY nlohmann/json + OPTIONS "JSON_BuildTests OFF" +) + +# curl +find_package(CURL REQUIRED) + # Линкуем библиотеки target_link_libraries(main Boost::system TgBot -) + nlohmann_json::nlohmann_json + CURL::libcurl +) \ No newline at end of file From d20ed0a62a5f8c8e72aa219a875d20af95964238 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 9 Mar 2025 12:44:35 +0300 Subject: [PATCH 49/55] Update CMakeLists.txt --- CMakeLists.txt | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ef3858..d3683ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,6 @@ add_executable(main ${SOURCES}) include(cmake/CPM.cmake) -# Boost CPMAddPackage( NAME Boost VERSION 1.86.0 @@ -20,28 +19,14 @@ CPMAddPackage( "BUILD_SHARED_LIBS OFF" "BOOST_INCLUDE_LIBRARIES system" ) -# TgBot CPMAddPackage( NAME TgBot GIT_REPOSITORY https://github.com/reo7sp/tgbot-cpp.git GIT_TAG master ) -# nlohmann/json -CPMAddPackage( - NAME nlohmann_json - VERSION 3.11.2 - GITHUB_REPOSITORY nlohmann/json - OPTIONS "JSON_BuildTests OFF" -) - -# curl -find_package(CURL REQUIRED) - -# Линкуем библиотеки target_link_libraries(main Boost::system TgBot nlohmann_json::nlohmann_json - CURL::libcurl -) \ No newline at end of file +) From 5e43687a07c74f81a020b2de2dda8810ce52fbd6 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 9 Mar 2025 12:44:48 +0300 Subject: [PATCH 50/55] Update CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3683ad..b17810c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,5 +28,4 @@ CPMAddPackage( target_link_libraries(main Boost::system TgBot - nlohmann_json::nlohmann_json ) From 287527c3432c55c298f86942ad089fd9c55209b6 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Tue, 1 Apr 2025 13:53:21 +0300 Subject: [PATCH 51/55] Create declaration function --- CMakeLists.txt | 2 +- include/User.hpp | 2 +- source/Tutor.cpp | 6 ++++++ source/main.cpp | 24 +++++++++++++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b17810c..8ca788d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,4 +28,4 @@ CPMAddPackage( target_link_libraries(main Boost::system TgBot -) +) \ No newline at end of file diff --git a/include/User.hpp b/include/User.hpp index a4da434..44385c1 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -10,7 +10,7 @@ namespace mtd { enum class UserRole { STUDENT, TEACHER, OFFICE_STAFF, TUTOR, NONE }; -enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, CREATE_SOP, NONE }; +enum class UserState { MENU, BUTTONS, INFORMATION, STUDENT_SOP, TUTOR_SOP, CREATE_SOP, TUTOR_ADD_DECLARATION, NONE }; class User { int64_t chat_id = 0; diff --git a/source/Tutor.cpp b/source/Tutor.cpp index 1765eb7..a020d61 100644 --- a/source/Tutor.cpp +++ b/source/Tutor.cpp @@ -13,6 +13,12 @@ TgBot::InlineKeyboardMarkup::Ptr Tutor::GetInlineKeyboard() { addSubject->callbackData = "tutor_add_subject"; inlineKeyboard->inlineKeyboard.push_back({addSubject}); + // Добавление кнопки для объявления + TgBot::InlineKeyboardButton::Ptr addDeclaration(new TgBot::InlineKeyboardButton); + addDeclaration->text = "Сделать объявление"; + addDeclaration->callbackData = "tutor_add_declaration"; + inlineKeyboard->inlineKeyboard.push_back({addDeclaration}); + // Добавление кнопки для добавления людей в группы TgBot::InlineKeyboardButton::Ptr addPeople(new TgBot::InlineKeyboardButton); addPeople->text = "Добавить людей в группы"; diff --git a/source/main.cpp b/source/main.cpp index 15d2bc5..06b91d0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -17,6 +17,7 @@ mtd::Discipline t; mtd::Subject OMP; +std::vector declarations; TgBot::InlineKeyboardMarkup::Ptr CompleteButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); @@ -79,7 +80,14 @@ void StudentCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, } else if (query->data == "student_time_table") { bot.getApi().sendMessage(ChatId, "Ссылка на расписание", 0, 0, user->GetInlineKeyboard()); } else if (query->data == "student_declaration") { - bot.getApi().sendMessage(ChatId, "Актуальные объявления", 0, 0, user->GetInlineKeyboard()); + std::string result_string; + for (auto declaration : declarations) { + result_string += declaration + "\n"; + } + if (result_string.empty()) { + result_string = "Объявлений нет"; + } + bot.getApi().sendMessage(ChatId, result_string, 0, 0, user->BackButton()); } else if (query->data == "student_connect_with_teacher") { bot.getApi().sendMessage(ChatId, "Списочек с контактами преподавателя", 0, 0, user->GetInlineKeyboard()); @@ -156,6 +164,9 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, bot.getApi().sendMessage(ChatId, "Название предмета"); } else if (query->data == "tutor_back") { bot.getApi().sendMessage(ChatId, "Меню", 0, 0, user->GetMenu()); + } else if (query->data == "tutor_add_declaration") { + bot.getApi().sendMessage(ChatId, "Введите объявление"); + user->GetState() = mtd::UserState::TUTOR_ADD_DECLARATION; } } @@ -262,6 +273,17 @@ int main() { bot.getApi().sendMessage(ChatId, "Оценки этого студента:\n" + s, 0, 0, user->BackButton()); return; + } else if (user->GetState() == mtd::UserState::TUTOR_ADD_DECLARATION) { + declarations.push_back(message->text); + bot.getApi().sendMessage(ChatId, "Объявление успешно создано и сделана рассылка пользователям", 0, 0, user->GetMenu()); + for (const auto &iter : users) { + if (iter.first == ChatId) { + continue; + } + std::string dec = "Объвяление от " + message->chat->firstName + " " + message->chat->lastName + ":\n" + message->text; + bot.getApi().sendMessage(iter.first, dec, 0, 0, iter.second->GetMenu()); + } + return; } else if (user->GetState() == mtd::UserState::STUDENT_SOP) { if (user->GetStep() == -1) { // конец OMP.comments.push_back(message->text); From 2f1d4cbcbd018165fdc822f0882c0a9f5117056e Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sun, 11 May 2025 23:00:17 +0300 Subject: [PATCH 52/55] fdfsdfs --- source/main.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 06b91d0..e4a7fe6 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,12 +1,14 @@ #include +#include #include #include #include #include +#include #include -#include "BotToken.hpp" +// #include "BotToken.hpp" #include "OfficeStaff.hpp" #include "Student.hpp" #include "Teacher.hpp" @@ -18,6 +20,10 @@ mtd::Discipline t; mtd::Subject OMP; std::vector declarations; +std::vector quotes + = {"Учись так, как будто тебе предстоит жить вечно.", "Знание — сила.", + "Мотивация приходит во время действия.", "Каждый день — шанс стать лучше.", + "Не бойся ошибаться — бойся не попробовать."}; TgBot::InlineKeyboardMarkup::Ptr CompleteButton() { TgBot::InlineKeyboardMarkup::Ptr keyboard(new TgBot::InlineKeyboardMarkup); @@ -34,7 +40,7 @@ TgBot::InlineKeyboardMarkup::Ptr get_raiting_scale() { for (int i = 1; i < 11; ++i) { TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); button->text = std::to_string(i); - button->callbackData = std::to_string(i); // Колбек-данные соответствуют цифре + button->callbackData = std::to_string(i); // Колбек-данные соответствуют цифре keyboard->inlineKeyboard.push_back({button}); // Добавляем кнопки в строку клавиатуры } TgBot::InlineKeyboardButton::Ptr button(new TgBot::InlineKeyboardButton); @@ -172,7 +178,7 @@ void TutorCallBackQuery(TgBot::Bot &bot, TgBot::CallbackQuery::Ptr &query, int main() { OMP.name_subject = "ОМП"; - TgBot::Bot bot(mtd::token); + TgBot::Bot bot("7472835556:AAGGxuQuWDgYb9rskK3tn7YG660YEg7OgKM"); std::map> users; std::set NewUsers; std::mutex MutexForUsers; @@ -207,6 +213,13 @@ int main() { bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); }); + bot.getEvents().onCommand("quote", [&bot, "es](TgBot::Message::Ptr message) { + std::srand(std::time(nullptr)); + int idx = std::rand() % quotes.size(); + bot.getApi().sendChatAction(message->chat->id, "typing"); // имитируем "думает..." + std::this_thread::sleep_for(std::chrono::seconds(3)); // пауза 3 секунды + bot.getApi().sendMessage(message->chat->id, quotes[idx]); + }); bot.getEvents().onCallbackQuery( [&bot, &users, &MutexForUsers, &NewUsers](TgBot::CallbackQuery::Ptr query) { std::lock_guard lock(MutexForUsers); @@ -275,12 +288,15 @@ int main() { return; } else if (user->GetState() == mtd::UserState::TUTOR_ADD_DECLARATION) { declarations.push_back(message->text); - bot.getApi().sendMessage(ChatId, "Объявление успешно создано и сделана рассылка пользователям", 0, 0, user->GetMenu()); + bot.getApi().sendMessage(ChatId, + "Объявление успешно создано и сделана рассылка пользователям", + 0, 0, user->GetMenu()); for (const auto &iter : users) { if (iter.first == ChatId) { continue; } - std::string dec = "Объвяление от " + message->chat->firstName + " " + message->chat->lastName + ":\n" + message->text; + std::string dec = "Объвяление от " + message->chat->firstName + " " + + message->chat->lastName + ":\n" + message->text; bot.getApi().sendMessage(iter.first, dec, 0, 0, iter.second->GetMenu()); } return; From 766a7264b05832c877ba40db18b725fe9b867892 Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sat, 31 May 2025 01:04:17 +0300 Subject: [PATCH 53/55] Update main.cpp --- source/main.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index e4a7fe6..1221d70 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -213,13 +213,6 @@ int main() { bot.getApi().sendMessage(message->chat->id, "Кто ты?", 0, 0, keyboard); }); - bot.getEvents().onCommand("quote", [&bot, "es](TgBot::Message::Ptr message) { - std::srand(std::time(nullptr)); - int idx = std::rand() % quotes.size(); - bot.getApi().sendChatAction(message->chat->id, "typing"); // имитируем "думает..." - std::this_thread::sleep_for(std::chrono::seconds(3)); // пауза 3 секунды - bot.getApi().sendMessage(message->chat->id, quotes[idx]); - }); bot.getEvents().onCallbackQuery( [&bot, &users, &MutexForUsers, &NewUsers](TgBot::CallbackQuery::Ptr query) { std::lock_guard lock(MutexForUsers); @@ -371,4 +364,4 @@ int main() { } return 0; -} \ No newline at end of file +} From b70e4ffe8f53e98431ccc8aea8c9bf6bc99f402d Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sat, 31 May 2025 19:09:18 +0300 Subject: [PATCH 54/55] Update CMakeLists.txt --- CMakeLists.txt | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ca788d..f0040e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,29 @@ CPMAddPackage( GIT_TAG master ) +CPMAddPackage( + NAME nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.2 +) + +CPMAddPackage( + NAME libcurl + GIT_REPOSITORY https://github.com/curl/curl.git + GIT_TAG curl-8_1_2 + OPTIONS "BUILD_CURL_EXE OFF" "BUILD_TESTING OFF" +) + +CPMAddPackage( + NAME libpqxx + GIT_REPOSITORY https://github.com/jtv/libpqxx.git + GIT_TAG 7.6.0 +) + target_link_libraries(main Boost::system TgBot -) \ No newline at end of file + nlohmann_json::nlohmann_json + curl + pqxx +) From fa6a70cffbdb27190ad1c0d5a58e6a14c3780a0b Mon Sep 17 00:00:00 2001 From: Meytardzhevtd Date: Sat, 31 May 2025 22:03:14 +0300 Subject: [PATCH 55/55] Update CMakeLists.txt --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0040e4..434c885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,10 +44,17 @@ CPMAddPackage( GIT_TAG 7.6.0 ) +CPMAddPackage( + NAME fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 10.2.1 # можно заменить на нужную версию +) + target_link_libraries(main Boost::system TgBot nlohmann_json::nlohmann_json curl pqxx + fmt::fmt )