+ api
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import io
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
@@ -71,14 +72,15 @@ async def new_char_bio(message: Message, state: FSMContext, dao: DAO, bot: Bot):
|
||||
await dao.chars.add_character(char)
|
||||
file_info = await bot.get_file(char.character_image_doc_tg_id)
|
||||
file_bytes = await bot.download_file(file_info.file_path)
|
||||
file_io = file_bytes.read()
|
||||
avatar_asset = await dao.assets.save_asset(
|
||||
Asset(name="avatar.png", type=AssetType.IMAGE, linked_char_id=char.id, data=file_bytes,
|
||||
tg_doc_file_id=message.document.file_id))
|
||||
Asset(name="avatar.png", type=AssetType.IMAGE, linked_char_id=str(char.id), data=file_io,
|
||||
tg_doc_file_id=file_id))
|
||||
char.avatar_image = avatar_asset.link
|
||||
# Отправляем подтверждение
|
||||
# Используем байты для отправки обратно
|
||||
photo_msg = await message.answer_photo(
|
||||
photo=BufferedInputFile(file_bytes.read(),
|
||||
photo=BufferedInputFile(file_io,
|
||||
filename="char.jpg") if not char.character_image_tg_id else char.character_image_tg_id,
|
||||
caption=(
|
||||
"🎉 <b>Персонаж создан!</b>\n\n"
|
||||
@@ -86,6 +88,7 @@ async def new_char_bio(message: Message, state: FSMContext, dao: DAO, bot: Bot):
|
||||
f"📝 <b>Био:</b> {char.character_bio}"
|
||||
)
|
||||
)
|
||||
file_bytes.close()
|
||||
char.character_image_tg_id = photo_msg.photo[0].file_id
|
||||
|
||||
await dao.chars.update_char(char.id, char)
|
||||
|
||||
Reference in New Issue
Block a user