Enhance bot functionality and refactor database interactions
- Added `ca-certificates` installation to Dockerfile for improved network security. - Updated health check command in Dockerfile to include better timeout handling. - Refactored `run_helper.py` to implement proper signal handling and logging during shutdown. - Transitioned database operations to an asynchronous model in `async_db.py`, improving performance and responsiveness. - Updated database schema to support new foreign key relationships and optimized indexing for better query performance. - Enhanced various bot handlers to utilize async database methods, improving overall efficiency and user experience. - Removed obsolete database and fix scripts to streamline the project structure.
This commit is contained in:
@@ -70,26 +70,30 @@ def plural_time(type: int, n: float) -> str:
|
||||
return str(new_number) + ' ' + word[p]
|
||||
|
||||
|
||||
def get_last_message_text(bot_db) -> Optional[str]:
|
||||
async def get_last_message_text(bot_db) -> Optional[str]:
|
||||
"""Получить текст сообщения о времени последней записи"""
|
||||
try:
|
||||
date_from_db = bot_db.last_date_audio()
|
||||
return format_time_ago(date_from_db)
|
||||
date_from_db = await bot_db.last_date_audio()
|
||||
if date_from_db is None:
|
||||
return None
|
||||
# Преобразуем UNIX timestamp в строку для format_time_ago
|
||||
date_string = datetime.fromtimestamp(date_from_db).strftime("%Y-%m-%d %H:%M:%S")
|
||||
return format_time_ago(date_string)
|
||||
except Exception as e:
|
||||
logger.error(f"Не удалось получить дату последнего сообщения - {e}")
|
||||
return None
|
||||
|
||||
|
||||
def validate_voice_message(message) -> bool:
|
||||
async def validate_voice_message(message) -> bool:
|
||||
"""Проверить валидность голосового сообщения"""
|
||||
return message.content_type == 'voice'
|
||||
|
||||
|
||||
def get_user_emoji_safe(bot_db, user_id: int) -> str:
|
||||
async def get_user_emoji_safe(bot_db, user_id: int) -> str:
|
||||
"""Безопасно получить эмодзи пользователя"""
|
||||
try:
|
||||
user_emoji = bot_db.check_emoji_for_user(user_id)
|
||||
return user_emoji if user_emoji else "😊"
|
||||
user_emoji = await bot_db.get_user_emoji(user_id)
|
||||
return user_emoji if user_emoji and user_emoji != "Смайл еще не определен" else "😊"
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка при получении эмодзи пользователя {user_id}: {e}")
|
||||
return "😊"
|
||||
|
||||
Reference in New Issue
Block a user