mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 10:25:29 +03:00
update
This commit is contained in:
@@ -42,6 +42,7 @@ async def main():
|
|||||||
DAOProvider(),
|
DAOProvider(),
|
||||||
RepositoryProvider(),
|
RepositoryProvider(),
|
||||||
ServiceProvider(),
|
ServiceProvider(),
|
||||||
|
context={Bot: bot}
|
||||||
)
|
)
|
||||||
|
|
||||||
dp.include_router(user_router)
|
dp.include_router(user_router)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
from aiogram import Bot
|
||||||
from aiogram.types import Message, CallbackQuery
|
from aiogram.types import Message, CallbackQuery
|
||||||
|
from aiogram.exceptions import TelegramForbiddenError
|
||||||
from aiogram_dialog import Window, DialogManager
|
from aiogram_dialog import Window, DialogManager
|
||||||
from aiogram_dialog.widgets.text import Format, Const
|
from aiogram_dialog.widgets.text import Format, Const
|
||||||
from aiogram_dialog.widgets.kbd import Row, SwitchTo, Button, Select, Group
|
from aiogram_dialog.widgets.kbd import Row, SwitchTo, Button, Select, Group
|
||||||
@@ -13,6 +15,9 @@ from dutylog.infrastructure.database.repositories.residents_repository import (
|
|||||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
||||||
HoursTransactionsRepository,
|
HoursTransactionsRepository,
|
||||||
)
|
)
|
||||||
|
from dutylog.infrastructure.database.repositories.users_repository import (
|
||||||
|
UsersRepository,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def on_add_hours_click(
|
async def on_add_hours_click(
|
||||||
@@ -145,6 +150,9 @@ async def on_add_hours_confirm(
|
|||||||
button: Button,
|
button: Button,
|
||||||
dialog_manager: DialogManager,
|
dialog_manager: DialogManager,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
|
residents_repository: FromDishka[ResidentsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
|
bot: FromDishka[Bot],
|
||||||
):
|
):
|
||||||
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
|
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
|
||||||
hours = dialog_manager.dialog_data.get("selected_hours")
|
hours = dialog_manager.dialog_data.get("selected_hours")
|
||||||
@@ -159,6 +167,24 @@ async def on_add_hours_confirm(
|
|||||||
is_active=True,
|
is_active=True,
|
||||||
remark=remark,
|
remark=remark,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
resident = await residents_repository.get_resident_by_id(resident_id)
|
||||||
|
if resident and resident.user_entity:
|
||||||
|
admin = await users_repository.get_user_by_id(admin_id)
|
||||||
|
admin_username = f"@{admin.username}" if admin and admin.username else "Администратор"
|
||||||
|
|
||||||
|
notification_text = (
|
||||||
|
f"<blockquote>➕ <b>Начислены часы</b></blockquote>\n\n"
|
||||||
|
f"<b>Количество:</b> <code>{hours}</code> ч\n"
|
||||||
|
f"<b>Причина:</b> {remark}\n"
|
||||||
|
f"<b>Администратор:</b> {admin_username}\n\n"
|
||||||
|
f"<b>Всего неотработанных часов:</b> <code>{resident.active_hours}</code> ч"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await bot.send_message(resident.user_entity, notification_text)
|
||||||
|
except TelegramForbiddenError:
|
||||||
|
pass
|
||||||
|
|
||||||
await dialog_manager.switch_to(AdminMenuSG.resident_info)
|
await dialog_manager.switch_to(AdminMenuSG.resident_info)
|
||||||
|
|
||||||
@@ -170,6 +196,8 @@ async def on_remove_hours_confirm(
|
|||||||
dialog_manager: DialogManager,
|
dialog_manager: DialogManager,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
residents_repository: FromDishka[ResidentsRepository],
|
residents_repository: FromDishka[ResidentsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
|
bot: FromDishka[Bot],
|
||||||
):
|
):
|
||||||
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
|
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
|
||||||
hours = dialog_manager.dialog_data.get("selected_hours")
|
hours = dialog_manager.dialog_data.get("selected_hours")
|
||||||
@@ -192,6 +220,37 @@ async def on_remove_hours_confirm(
|
|||||||
admin_id=admin_id,
|
admin_id=admin_id,
|
||||||
remark=remark,
|
remark=remark,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
resident = await residents_repository.get_resident_by_id(resident_id)
|
||||||
|
if resident and resident.user_entity:
|
||||||
|
admin = await users_repository.get_user_by_id(admin_id)
|
||||||
|
admin_username = f"@{admin.username}" if admin and admin.username else "Администратор"
|
||||||
|
|
||||||
|
if resident.active_hours == 0:
|
||||||
|
notification_text = (
|
||||||
|
f"<blockquote>🎉 <b>Поздравляем!</b></blockquote>\n\n"
|
||||||
|
f"Вы отработали все часы! Теперь у вас <code>0</code> неотработанных часов.\n\n"
|
||||||
|
f"<b>Списано:</b> <code>{hours}</code> ч\n"
|
||||||
|
)
|
||||||
|
if remark:
|
||||||
|
notification_text += f"<b>Причина:</b> {remark}\n"
|
||||||
|
notification_text += f"<b>Администратор:</b> {admin_username}"
|
||||||
|
else:
|
||||||
|
notification_text = (
|
||||||
|
f"<blockquote>➖ <b>Списаны часы</b></blockquote>\n\n"
|
||||||
|
f"<b>Количество:</b> <code>{hours}</code> ч\n"
|
||||||
|
)
|
||||||
|
if remark:
|
||||||
|
notification_text += f"<b>Причина:</b> {remark}\n"
|
||||||
|
notification_text += (
|
||||||
|
f"<b>Администратор:</b> {admin_username}\n\n"
|
||||||
|
f"<b>Осталось неотработанных часов:</b> <code>{resident.active_hours}</code> ч"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await bot.send_message(resident.user_entity, notification_text)
|
||||||
|
except TelegramForbiddenError:
|
||||||
|
pass
|
||||||
|
|
||||||
await dialog_manager.switch_to(AdminMenuSG.resident_info)
|
await dialog_manager.switch_to(AdminMenuSG.resident_info)
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ faq_window = Window(
|
|||||||
⏳ <b>Неотработанные</b> — текущий долг, который нужно закрыть.</blockquote>
|
⏳ <b>Неотработанные</b> — текущий долг, который нужно закрыть.</blockquote>
|
||||||
|
|
||||||
👨💻 <b>Как найти администратора?</b>
|
👨💻 <b>Как найти администратора?</b>
|
||||||
<blockquote>Обычно это староста этажа или комендант. Если возникла техническая ошибка в боте — пиши в чат общежития.</blockquote>
|
<blockquote>Обычно это воспитатель или член совета общежития. Если возникла техническая ошибка в боте — пиши в группу общежития.</blockquote>
|
||||||
""")
|
""")
|
||||||
,
|
,
|
||||||
SwitchTo(Const("◀️ Назад"), id="back_to_main", state=MainMenuSG.main),
|
SwitchTo(Const("◀️ Назад"), id="back_to_main", state=MainMenuSG.main),
|
||||||
|
|||||||
Reference in New Issue
Block a user