+ api
This commit is contained in:
@@ -7,6 +7,7 @@ from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.types import *
|
||||
from aiogram import Router, F, Bot
|
||||
|
||||
from models.Asset import Asset, AssetType
|
||||
from models.Character import Character
|
||||
from repos.dao import DAO
|
||||
|
||||
@@ -53,6 +54,7 @@ async def new_char_bio(message: Message, state: FSMContext, dao: DAO, bot: Bot):
|
||||
file_io = await bot.download(file_id)
|
||||
# photo_bytes = file_io.getvalue() # Получаем байты
|
||||
|
||||
|
||||
# Создаем модель
|
||||
char = Character(
|
||||
id=None,
|
||||
@@ -65,14 +67,19 @@ async def new_char_bio(message: Message, state: FSMContext, dao: DAO, bot: Bot):
|
||||
file_io.close()
|
||||
|
||||
# Сохраняем через DAO
|
||||
|
||||
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)
|
||||
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))
|
||||
char.avatar_image = avatar_asset.link
|
||||
# Отправляем подтверждение
|
||||
# Используем байты для отправки обратно
|
||||
photo_msg = await message.answer_photo(
|
||||
photo=BufferedInputFile(file_bytes.read(),
|
||||
filename="char.jpg") if not char.character_image_tg_id else char.character_image_tg_id,
|
||||
filename="char.jpg") if not char.character_image_tg_id else char.character_image_tg_id,
|
||||
caption=(
|
||||
"🎉 <b>Персонаж создан!</b>\n\n"
|
||||
f"👤 <b>Имя:</b> {char.name}\n"
|
||||
@@ -80,6 +87,7 @@ async def new_char_bio(message: Message, state: FSMContext, dao: DAO, bot: Bot):
|
||||
)
|
||||
)
|
||||
char.character_image_tg_id = photo_msg.photo[0].file_id
|
||||
|
||||
await dao.chars.update_char(char.id, char)
|
||||
await wait_msg.delete()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user