feat: add FSM handlers and admin interface
- Add all user FSM states (INTRO through CONFIRM_SAVE) - Add replica re-recording by number (ASK_REPLICA_NUMBER, REPEAT_REPLICA) - Add admin interface with stats and scenario upload - Add voice message handling and storage
This commit is contained in:
31
src/audio.py
Normal file
31
src/audio.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from telegram import Bot
|
||||
|
||||
from src.config import DATA_PARTIAL_DIR
|
||||
from src.database import upsert_recording
|
||||
from src.logger import logger
|
||||
from src.scenarios import get_audio_filename
|
||||
|
||||
|
||||
async def save_voice_message(
|
||||
bot: Bot,
|
||||
file_id: str,
|
||||
user_id: int,
|
||||
scenario_id: str,
|
||||
replica_index: int,
|
||||
) -> None:
|
||||
"""Сохраняет голосовое сообщение в data_partial/."""
|
||||
# Создаём директорию если нужно
|
||||
scenario_dir = DATA_PARTIAL_DIR / scenario_id
|
||||
scenario_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Скачиваем файл
|
||||
file = await bot.get_file(file_id)
|
||||
filename = get_audio_filename(replica_index, user_id)
|
||||
filepath = scenario_dir / filename
|
||||
|
||||
await file.download_to_drive(filepath)
|
||||
|
||||
# Записываем в БД
|
||||
upsert_recording(user_id, scenario_id, replica_index)
|
||||
|
||||
logger.debug(f"Saved voice: {filepath}")
|
||||
Reference in New Issue
Block a user