Update banned users handling with async support and improved date parsing
- Modified `change_page` function in `callback_handlers.py` to use async methods for retrieving banned users and their buttons. - Enhanced `get_banned_users_list` in `helper_func.py` to handle string timestamps and various date formats, ensuring robust date parsing. - Added a new test case in `test_utils.py` to validate the handling of string timestamps in the banned users list retrieval.
This commit is contained in:
@@ -696,9 +696,22 @@ async def get_banned_users_list(offset: int, bot_db):
|
||||
if isinstance(unban_date, (int, float)):
|
||||
unban_datetime = datetime.fromtimestamp(unban_date)
|
||||
safe_unban_date = unban_datetime.strftime("%d-%m-%Y %H:%M")
|
||||
else:
|
||||
# Если это уже datetime объект
|
||||
elif isinstance(unban_date, str):
|
||||
# Если это строка, попытаемся её обработать
|
||||
try:
|
||||
# Попробуем преобразовать строку в timestamp
|
||||
timestamp = int(unban_date)
|
||||
unban_datetime = datetime.fromtimestamp(timestamp)
|
||||
safe_unban_date = unban_datetime.strftime("%d-%m-%Y %H:%M")
|
||||
except (ValueError, TypeError):
|
||||
# Если не удалось, показываем как есть
|
||||
safe_unban_date = html.escape(str(unban_date))
|
||||
elif hasattr(unban_date, 'strftime'):
|
||||
# Если это datetime объект
|
||||
safe_unban_date = unban_date.strftime("%d-%m-%Y %H:%M")
|
||||
else:
|
||||
# Для всех остальных случаев
|
||||
safe_unban_date = html.escape(str(unban_date))
|
||||
except (ValueError, TypeError, OSError):
|
||||
# В случае ошибки показываем исходное значение
|
||||
safe_unban_date = html.escape(str(unban_date))
|
||||
|
||||
Reference in New Issue
Block a user