Skip to content

Commit

Permalink
update bot
Browse files Browse the repository at this point in the history
  • Loading branch information
iljavaleev committed Jun 15, 2024
1 parent 3a1588d commit 21e9daa
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 63 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Main workflow

on:
push:
branches:
- main

jobs:
build_and_push:
name: Build Docker images and push them to DockerHub
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image_name: valeevilja/cppbot:v1
dockerfile: Dockerfile
steps:
- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image_name }}

- name: Build and push
uses: docker/build-push-action@v5
with:
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy:
name: Deploy to server
runs-on: ubuntu-latest
needs: build_and_push
steps:
- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
script: |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/cppbot:v1
sudo docker-compose down
touch .env
echo BOT_TOKEN=${{ secrets.BOT_TOKEN }} >> .env
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} >> .env
echo POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} >> .env
echo ADMIN_CHAT_ID=${{ secrets.ADMIN_CHAT_ID }} >> .env
sudo docker-compose up -d --build
send_message:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: send message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: ${{ github.workflow }} успешно выполнен!
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

build/
data/
cppinfra/
.env
todo.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.17)
cmake_minimum_required(VERSION 3.5)

project(cppbot)

Expand Down
24 changes: 12 additions & 12 deletions botstaff/src/handlers/handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ namespace CommandHandlers
clear_lesson_state(chat_id);
botUser user = botUser::get(chat_id);
if (is_admin(chat_id))
return bot.getApi().sendMessage(chat_id, "Вход для админа", false, 0, teacherKeyboards::create_teacher_start_kb(true));
return bot.getApi().sendMessage(chat_id, "Вход для админа", nullptr, nullptr, teacherKeyboards::create_teacher_start_kb(true));
else if(is_teacher(user))
return bot.getApi().sendMessage(chat_id, "Вход для учителя", false, 0, teacherKeyboards::create_teacher_start_kb(false));
return bot.getApi().sendMessage(chat_id, "Вход для учителя", nullptr, nullptr, teacherKeyboards::create_teacher_start_kb(false));
else
return bot.getApi().sendMessage(
chat_id,
"Вход для пользователя",
false,
0,
nullptr,
nullptr,
UserKeyboards::create_user_start_kb(chat_id, !user.empty())
);

Expand Down Expand Up @@ -104,8 +104,8 @@ namespace Handlers
return bot.getApi().sendMessage(
query->message->chat->id,
std::format("<b><i>Расписание на {}</i></b>", MONTHS_RU.at(ymd[1]-1)),
false,
0,
nullptr,
nullptr,
Keyboards::create_calendar_kb(ymd[0], ymd[1], 1, role, query->message->chat->id),
"HTML"
);
Expand Down Expand Up @@ -137,8 +137,8 @@ namespace Handlers
return bot.getApi().sendMessage(
query->message->chat->id,
std::format("<b><i>Расписание на {}</i></b>", MONTHS_RU.at(month-1)),
false,
0,
nullptr,
nullptr,
Keyboards::create_calendar_kb(year, month, 1, role, query->message->chat->id, update),
"HTML"
);
Expand Down Expand Up @@ -166,8 +166,8 @@ namespace Handlers
return bot.getApi().sendMessage(
query->message->chat->id,
kb->inlineKeyboard.empty() ? "Сегодня нет занятий" : "Занятия сегодня",
false,
0,
nullptr,
nullptr,
kb
);

Expand All @@ -190,8 +190,8 @@ namespace Handlers
return bot.getApi().sendMessage(
query->message->chat->id,
get_user_lesson_info(query->message->chat->id, user_lesson_id, role),
false,
0,
nullptr,
nullptr,
Keyboards::day_info_kb(user_lesson_id, role),
"HTML"
);
Expand Down
28 changes: 14 additions & 14 deletions botstaff/src/handlers/teacher_handlers/createLessonHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace createLesson
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите ученика",
false,
0,
nullptr,
nullptr,
teacherKeyboards::create_list_pupils_kb(query->message->chat->id)
);

Expand Down Expand Up @@ -184,8 +184,8 @@ namespace createLesson
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите новую дату",
false,
0,
nullptr,
nullptr,
Keyboards::create_calendar_kb(
ymd[0],
ymd[1],
Expand All @@ -201,8 +201,8 @@ namespace createLesson
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите ученика",
false,
0,
nullptr,
nullptr,
teacherKeyboards::create_list_pupils_kb(query->message->chat->id, true, true)
);
}
Expand Down Expand Up @@ -258,8 +258,8 @@ namespace createLesson
bot.getApi().sendMessage(
teacher_id,
mess,
false,
0,
nullptr,
nullptr,
nullptr,
"HTML"
);
Expand Down Expand Up @@ -332,8 +332,8 @@ Message::Ptr send_lesson_update_kb(
return bot.getApi().sendMessage(
message->chat->id,
"Редактирование. Нажмите Завершить, чтобы сохранить изменения",
false,
0,
nullptr,
nullptr,
teacherKeyboards::update_lesson_info_kb(lesson_id)
);
}
Expand Down Expand Up @@ -420,8 +420,8 @@ Message::Ptr lesson_comment_for_teacher_handler(
"Вы успешно создали занятие.\nУченику отправлено сообщение\n\n{}",
get_user_lesson_info(message->chat->id, user_lesson_id, teacher.role)
),
false,
0,
nullptr,
nullptr,
Keyboards::day_info_kb(user_lesson_id, teacher.role),
"HTML"
);
Expand All @@ -440,8 +440,8 @@ Message::Ptr send_lesson_info_to_pupil(
return bot.getApi().sendMessage(
pupil_id,
message,
false,
0,
nullptr,
nullptr,
nullptr,
"HTML"
);
Expand Down
30 changes: 15 additions & 15 deletions botstaff/src/handlers/teacher_handlers/teacherHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace teacherHandlers
{
return bot.getApi().sendMessage(
query->message->chat->id,
"Ваши недавние комметарии", false, 0, teacherKeyboards::create_comments_kb(query->message->chat->id)
"Ваши недавние комметарии", nullptr, nullptr, teacherKeyboards::create_comments_kb(query->message->chat->id)
);
}
return Message::Ptr(nullptr);
Expand All @@ -38,8 +38,8 @@ namespace teacherHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
get_comment_text(lesson_id),
false,
0,
nullptr,
nullptr,
nullptr,
"HTML"
);
Expand All @@ -58,7 +58,7 @@ namespace teacherHandlers
{
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите категорию", false, 0, teacherKeyboards::create_teachers_kb()
"Выберите категорию", nullptr, nullptr, teacherKeyboards::create_teachers_kb()
);
}
return Message::Ptr(nullptr);
Expand All @@ -76,14 +76,14 @@ namespace teacherHandlers
{
return bot.getApi().sendMessage(
query->message->chat->id,
"Список педагогов по фамилии", false, 0, teacherKeyboards::create_list_users_kb(0)
"Список педагогов по фамилии", nullptr, nullptr, teacherKeyboards::create_list_users_kb(0)
);
}
else
{
return bot.getApi().sendMessage(
query->message->chat->id,
"Список кандидатов по фамилии", false, 0, teacherKeyboards::create_list_users_kb(0, false)
"Список кандидатов по фамилии", nullptr, nullptr, teacherKeyboards::create_list_users_kb(0, false)
);
}

Expand All @@ -102,7 +102,7 @@ namespace teacherHandlers
{
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите категорию", false, 0, teacherKeyboards::create_pupils_kb(query->message->chat->id)
"Выберите категорию", nullptr, nullptr, teacherKeyboards::create_pupils_kb(query->message->chat->id)
);
}
return Message::Ptr(nullptr);
Expand All @@ -124,8 +124,8 @@ namespace teacherHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
message,
false,
0,
nullptr,
nullptr,
kb
);
}
Expand All @@ -136,8 +136,8 @@ namespace teacherHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
message,
false,
0,
nullptr,
nullptr,
kb
);
}
Expand Down Expand Up @@ -169,8 +169,8 @@ namespace teacherHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
info,
false,
0,
nullptr,
nullptr,
teacherKeyboards::create_user_info_kb(u),
"HTML"
);
Expand Down Expand Up @@ -239,8 +239,8 @@ namespace teacherHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
"Что вы хотите изменить?",
false,
0,
nullptr,
nullptr,
teacherKeyboards::update_user_info_kb(role, user_id)
);

Expand Down
4 changes: 2 additions & 2 deletions botstaff/src/handlers/user_handlers/userHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace UserHandlers
return bot.getApi().sendMessage(
query->message->chat->id,
"Выберите роль",
false,
0,
nullptr,
nullptr,
UserKeyboards::choose_role_kb()
);

Expand Down
Loading

0 comments on commit 21e9daa

Please sign in to comment.