mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-08-08 18:11:14 +03:00
send photo/media group with detail text as caption, not separately
This commit is contained in:
@@ -627,18 +627,31 @@ async def on_transaction_selected(
|
|||||||
dialog_manager: DialogManager,
|
dialog_manager: DialogManager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
):
|
):
|
||||||
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
||||||
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
||||||
if tx:
|
if tx:
|
||||||
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
||||||
if photo_file_ids:
|
if photo_file_ids:
|
||||||
|
operation = "Начислено" if tx.transaction_type == "increase" else "Списано"
|
||||||
|
emoji = "+" if tx.transaction_type == "increase" else "−"
|
||||||
|
msk_time = tx.created_at.astimezone(msk_now().tzinfo).replace(tzinfo=None)
|
||||||
|
date_str = msk_time.strftime("%d.%m.%Y %H:%M")
|
||||||
|
remark_text = f"\n💬 <i>{tx.remark}</i>" if tx.remark else ""
|
||||||
|
admin_info = ""
|
||||||
|
if tx.admin_id:
|
||||||
|
admin = await users_repository.get_user_by_id(tx.admin_id)
|
||||||
|
if admin:
|
||||||
|
admin_name = f"@{admin.username}" if admin.username else admin.first_name or f"ID: {admin.id}"
|
||||||
|
admin_info = f"\n👨💼 <b>Администратор:</b> {admin_name}"
|
||||||
|
caption = f"📋 <b>Детали транзакции</b>\n\n⚙️ <b>Операция:</b> {operation}\n🔢 <b>Количество:</b> {emoji}<code>{tx.amount}</code> ч\n📅 <b>Дата:</b> {date_str}{remark_text}{admin_info}"
|
||||||
bot: Bot = dialog_manager.middleware_data.get("bot")
|
bot: Bot = dialog_manager.middleware_data.get("bot")
|
||||||
try:
|
try:
|
||||||
if len(photo_file_ids) == 1:
|
if len(photo_file_ids) == 1:
|
||||||
await bot.send_photo(callback.message.chat.id, photo_file_ids[0])
|
await bot.send_photo(callback.message.chat.id, photo_file_ids[0], caption=caption)
|
||||||
else:
|
else:
|
||||||
media = [InputMediaPhoto(media=fid) for fid in photo_file_ids]
|
media = [InputMediaPhoto(media=fid, caption=caption if i == 0 else None) for i, fid in enumerate(photo_file_ids)]
|
||||||
await bot.send_media_group(callback.message.chat.id, media=media)
|
await bot.send_media_group(callback.message.chat.id, media=media)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -508,18 +508,31 @@ async def on_room_transaction_selected(
|
|||||||
dialog_manager: DialogManager,
|
dialog_manager: DialogManager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
):
|
):
|
||||||
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
||||||
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
||||||
if tx:
|
if tx:
|
||||||
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
||||||
if photo_file_ids:
|
if photo_file_ids:
|
||||||
|
operation = "Начислено" if tx.transaction_type == "increase" else "Списано"
|
||||||
|
emoji = "+" if tx.transaction_type == "increase" else "−"
|
||||||
|
msk_time = tx.created_at.astimezone(msk_now().tzinfo).replace(tzinfo=None)
|
||||||
|
date_str = msk_time.strftime("%d.%m.%Y %H:%M")
|
||||||
|
remark_text = f"\n💬 <i>{tx.remark}</i>" if tx.remark else ""
|
||||||
|
admin_info = ""
|
||||||
|
if tx.admin_id:
|
||||||
|
admin = await users_repository.get_user_by_id(tx.admin_id)
|
||||||
|
if admin:
|
||||||
|
admin_name = f"@{admin.username}" if admin.username else admin.first_name or f"ID: {admin.id}"
|
||||||
|
admin_info = f"\n👨💼 <b>Администратор:</b> {admin_name}"
|
||||||
|
caption = f"📋 <b>Детали транзакции</b>\n\n⚙️ <b>Операция:</b> {operation}\n🔢 <b>Количество:</b> {emoji}<code>{tx.amount}</code> ч\n📅 <b>Дата:</b> {date_str}{remark_text}{admin_info}"
|
||||||
bot: Bot = dialog_manager.middleware_data.get("bot")
|
bot: Bot = dialog_manager.middleware_data.get("bot")
|
||||||
try:
|
try:
|
||||||
if len(photo_file_ids) == 1:
|
if len(photo_file_ids) == 1:
|
||||||
await bot.send_photo(callback.message.chat.id, photo_file_ids[0])
|
await bot.send_photo(callback.message.chat.id, photo_file_ids[0], caption=caption)
|
||||||
else:
|
else:
|
||||||
media = [InputMediaPhoto(media=fid) for fid in photo_file_ids]
|
media = [InputMediaPhoto(media=fid, caption=caption if i == 0 else None) for i, fid in enumerate(photo_file_ids)]
|
||||||
await bot.send_media_group(callback.message.chat.id, media=media)
|
await bot.send_media_group(callback.message.chat.id, media=media)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -75,18 +75,38 @@ async def on_creator_transaction_selected(
|
|||||||
dialog_manager,
|
dialog_manager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
|
residents_repository: FromDishka[ResidentsRepository],
|
||||||
|
rooms_repository: FromDishka[RoomsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
):
|
):
|
||||||
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
||||||
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
||||||
if tx:
|
if tx:
|
||||||
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
||||||
if photo_file_ids:
|
if photo_file_ids:
|
||||||
|
operation = "Начислено" if tx.transaction_type == "increase" else "Списано"
|
||||||
|
emoji = "+" if tx.transaction_type == "increase" else "−"
|
||||||
|
room_mark = " 🚪" if tx.per_room else ""
|
||||||
|
msk_time = tx.created_at.astimezone(msk_now().tzinfo).replace(tzinfo=None)
|
||||||
|
date_str = msk_time.strftime("%d.%m.%Y %H:%M")
|
||||||
|
resident = await residents_repository.get_by_id(tx.resident_id)
|
||||||
|
resident_name = resident.real_name if resident and resident.real_name else "Без имени"
|
||||||
|
room = await rooms_repository.get_by_id(resident.room) if resident else None
|
||||||
|
room_number = room.number if room else "???"
|
||||||
|
admin_info = ""
|
||||||
|
if tx.admin_id:
|
||||||
|
admin = await users_repository.get_user_by_id(tx.admin_id)
|
||||||
|
if admin:
|
||||||
|
admin_name = f"@{admin.username}" if admin.username else admin.first_name or f"ID: {admin.id}"
|
||||||
|
admin_info = f"\n👨💼 <b>Администратор:</b> {admin_name}"
|
||||||
|
remark_text = f"\n💬 <i>{tx.remark}</i>" if tx.remark else ""
|
||||||
|
caption = f"📋 <b>Детали транзакции</b>\n\n⚙️ <b>Операция:</b> {operation}\n🔢 <b>Количество:</b> {emoji}<code>{tx.amount}</code> ч{room_mark}\n👤 <b>Резидент:</b> {resident_name} (к. {room_number}){admin_info}\n📅 <b>Дата:</b> {date_str}{remark_text}"
|
||||||
bot: Bot = dialog_manager.middleware_data.get("bot")
|
bot: Bot = dialog_manager.middleware_data.get("bot")
|
||||||
try:
|
try:
|
||||||
if len(photo_file_ids) == 1:
|
if len(photo_file_ids) == 1:
|
||||||
await bot.send_photo(callback.message.chat.id, photo_file_ids[0])
|
await bot.send_photo(callback.message.chat.id, photo_file_ids[0], caption=caption)
|
||||||
else:
|
else:
|
||||||
media = [InputMediaPhoto(media=fid) for fid in photo_file_ids]
|
media = [InputMediaPhoto(media=fid, caption=caption if i == 0 else None) for i, fid in enumerate(photo_file_ids)]
|
||||||
await bot.send_media_group(callback.message.chat.id, media=media)
|
await bot.send_media_group(callback.message.chat.id, media=media)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -69,18 +69,31 @@ async def on_user_transaction_selected(
|
|||||||
dialog_manager,
|
dialog_manager,
|
||||||
item_id: str,
|
item_id: str,
|
||||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||||
|
users_repository: FromDishka[UsersRepository],
|
||||||
):
|
):
|
||||||
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
dialog_manager.dialog_data["selected_transaction_id"] = int(item_id)
|
||||||
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
tx = await transactions_repository.get_transaction_by_id(int(item_id))
|
||||||
if tx:
|
if tx:
|
||||||
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
photo_file_ids = HoursTransactionsRepository.get_photo_file_ids(tx)
|
||||||
if photo_file_ids:
|
if photo_file_ids:
|
||||||
|
operation = "Начислено" if tx.transaction_type == "increase" else "Списано"
|
||||||
|
emoji = "+" if tx.transaction_type == "increase" else "−"
|
||||||
|
msk_time = tx.created_at.astimezone(msk_now().tzinfo).replace(tzinfo=None)
|
||||||
|
date_str = msk_time.strftime("%d.%m.%Y %H:%M")
|
||||||
|
remark_text = f"\n💬 <i>{tx.remark}</i>" if tx.remark else ""
|
||||||
|
admin_info = ""
|
||||||
|
if tx.admin_id:
|
||||||
|
admin = await users_repository.get_user_by_id(tx.admin_id)
|
||||||
|
if admin:
|
||||||
|
admin_name = f"@{admin.username}" if admin.username else admin.first_name or f"ID: {admin.id}"
|
||||||
|
admin_info = f"\n👨💼 <b>Администратор:</b> {admin_name}"
|
||||||
|
caption = f"📋 <b>Детали транзакции</b>\n\n⚙️ <b>Операция:</b> {operation}\n🔢 <b>Количество:</b> {emoji}<code>{tx.amount}</code> ч\n📅 <b>Дата:</b> {date_str}{remark_text}{admin_info}"
|
||||||
bot: Bot = dialog_manager.middleware_data.get("bot")
|
bot: Bot = dialog_manager.middleware_data.get("bot")
|
||||||
try:
|
try:
|
||||||
if len(photo_file_ids) == 1:
|
if len(photo_file_ids) == 1:
|
||||||
await bot.send_photo(callback.message.chat.id, photo_file_ids[0])
|
await bot.send_photo(callback.message.chat.id, photo_file_ids[0], caption=caption)
|
||||||
else:
|
else:
|
||||||
media = [InputMediaPhoto(media=fid) for fid in photo_file_ids]
|
media = [InputMediaPhoto(media=fid, caption=caption if i == 0 else None) for i, fid in enumerate(photo_file_ids)]
|
||||||
await bot.send_media_group(callback.message.chat.id, media=media)
|
await bot.send_media_group(callback.message.chat.id, media=media)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user