Files
ai-char-bot/routers/char_router.py
2026-02-02 16:15:17 +03:00

49 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import State, StatesGroup
from aiogram.types import *
from aiogram import Router, F
from models.Character import Character
from repos.dao import DAO
router = Router()
class States(StatesGroup):
char_wait_name = State()
char_wait_bio = State()
@router.message(F.document, Command("add_char"))
async def add_char(message: Message, state: FSMContext, dao: DAO):
await state.set_data({"photo": bot.download(file=message.document.file_id)})
await state.set_state(States.char_wait_name)
await message.answer("Кайф, теперь напиши ее имя")
@router.callback_query(States.char_wait_name)
async def new_char_name(message: Message, state: FSMContext, dao: DAO):
await state.set_data({"name": message.text})
await state.set_state(States.char_wait_bio)
await message.answer("А теперь напиши био. Хоть чуть чуть.")
@router.callback_query(States.char_wait_bio)
async def new_char_bio(message: Message, state: FSMContext, dao: DAO):
data = await state.get_data()
photo = data["photo"]
name = data["name"]
char = Character(id=None, name=name, character_image=photo, character_bio=message.text)
await dao.chars.add_character(char)
await message.answer_photo(photo=BufferedInputFile(char.character_image, "img.png"), caption="Персонаж создан!\n"
f"Имя:{char.name}\n"
f"Био: {char.character_bio}\n"
)
@router.message(Command("add_char"))
async def add_char_cmd(message: Message):
await message.answer(
"Добавление персонажа производится через отправку документа-фото исходного изображения персонажа.")