Update voice bot functionality and clean up project structure

- Added voice message handling capabilities, including saving and deleting audio messages via callback queries.
- Refactored audio record management in the database to remove unnecessary fields and streamline operations.
- Introduced new keyboard options for voice interactions in the bot.
- Updated `.gitignore` to include voice user files for better project organization.
- Removed obsolete voice bot handler files to simplify the codebase.
This commit is contained in:
2025-09-01 19:17:05 +03:00
parent d128e54694
commit 2d40f4496e
29 changed files with 757 additions and 724 deletions

View File

@@ -725,15 +725,15 @@ class AsyncBotDB:
await conn.close()
# Методы для работы с аудио
async def add_audio_record(self, file_name: str, author_id: int, file_id: str):
async def add_audio_record(self, file_name: str, author_id: int):
"""Добавление аудио записи."""
conn = None
try:
date_added = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
conn = await self._get_connection()
await conn.execute(
"INSERT INTO audio_message_reference (file_name, author_id, date_added, file_id) VALUES (?, ?, ?, ?)",
(file_name, author_id, date_added, file_id)
"INSERT INTO audio_message_reference (file_name, author_id, date_added) VALUES (?, ?, ?)",
(file_name, author_id, date_added)
)
await conn.commit()
except Exception as e:
@@ -778,23 +778,7 @@ class AsyncBotDB:
if conn:
await conn.close()
async def get_audio_file_id(self, user_id: int) -> Optional[str]:
"""Получение file_id последнего аудио пользователя."""
conn = None
try:
conn = await self._get_connection()
async with conn.execute(
"SELECT file_id FROM audio_message_reference WHERE author_id = ? ORDER BY date_added DESC LIMIT 1",
(user_id,)
) as cursor:
result = await cursor.fetchone()
return result[0] if result else None
except Exception as e:
self.logger.error(f"Ошибка при получении file_id аудио: {e}")
raise
finally:
if conn:
await conn.close()
async def get_audio_file_name(self, user_id: int) -> Optional[str]:
"""Получение имени файла последнего аудио пользователя."""

View File

@@ -1337,21 +1337,20 @@ class BotDB:
self.close()
def get_id_for_audio_record(self, user_id):
"""Получает ID аудио сообщения пользователя"""
"""Получает следующий номер аудио сообщения пользователя"""
self.logger.info(
f"Запуск функции get_id_for_audio_record. user_id={user_id}")
try:
self.connect()
r = self.cursor.execute(
"SELECT `file_id` FROM `audio_message_reference` WHERE `author_id` = ? "
"ORDER BY date_added DESC LIMIT 1",
"SELECT COUNT(*) FROM `audio_message_reference` WHERE `author_id` = ?",
(user_id,))
result = r.fetchone()[0]
self.logger.info(
f"Результат функции get_id_for_audio_record: {result}")
return result
except sqlite3.Error as error:
self.logger.error(f"Ошибка получения последней даты войса: {error}")
self.logger.error(f"Ошибка получения количества аудио: {error}")
raise
finally:
self.close()

View File

@@ -17,8 +17,7 @@ CREATE TABLE IF NOT EXISTS audio_message_reference (
file_name TEXT NOT NULL UNIQUE,
author_id INTEGER NOT NULL,
date_added DATE NOT NULL,
listen_count INTEGER NOT NULL DEFAULT 0,
file_id INTEGER NOT NULL
listen_count INTEGER NOT NULL DEFAULT 0
);
-- Database migrations tracking