Мелкие фиксы от игоря
This commit is contained in:
@@ -26,34 +26,60 @@ async def call_api(method, endpoint, data=None):
|
|||||||
logger.debug(f"Ответ JSON: {result}")
|
logger.debug(f"Ответ JSON: {result}")
|
||||||
return result
|
return result
|
||||||
if response.status in {404,400}:
|
if response.status in {404,400}:
|
||||||
logger.debug(f"Код {response.status}, возвращаю ничего")
|
result = await response.json()
|
||||||
return await response.json()
|
logger.debug(f"Код {response.status}, возвращаю {result}")
|
||||||
|
return result
|
||||||
logger.error(f"Ошибка в запросе: статус {response.status}, причина {response.reason}")
|
logger.error(f"Ошибка в запросе: статус {response.status}, причина {response.reason}")
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Исключение при выполнении запроса к {url}: {e}")
|
logger.exception(f"Исключение при выполнении запроса к {url}: {e}")
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
|
|
||||||
|
def escape_markdown_v2(text: str) -> str:
|
||||||
|
"""
|
||||||
|
Экранирует специальные символы для Markdown_V2.
|
||||||
|
"""
|
||||||
|
special_chars = r"_*[]()~`>#+-=|{}.!"
|
||||||
|
for char in special_chars:
|
||||||
|
text = text.replace(char, f"\\{char}")
|
||||||
|
return text
|
||||||
|
|
||||||
@router.message(Command("subscriptions"))
|
@router.message(Command("subscriptions"))
|
||||||
async def supp(message: types.Message):
|
async def supp(message: types.Message):
|
||||||
"""
|
"""
|
||||||
Меню сапп системы
|
Меню системы подписок
|
||||||
"""
|
"""
|
||||||
text = ""
|
text = ""
|
||||||
|
uri = None # Инициализация переменной
|
||||||
|
try:
|
||||||
|
# Вызов API для получения URI
|
||||||
result = await call_api("GET", f"/uri?telegram_id={message.from_user.id}")
|
result = await call_api("GET", f"/uri?telegram_id={message.from_user.id}")
|
||||||
uri = result.get('detail',"Error")
|
uri = result.get('detail', "Error") # Получаем URI из ответа или "Error", если ключ отсутствует
|
||||||
if uri == "SUB_ERROR":
|
|
||||||
text = f"Вы ещё не приобрели подписки!!"
|
# Проверка результата
|
||||||
|
if uri == "Error":
|
||||||
|
text = escape_markdown_v2("Произошла ошибка при получении URI")
|
||||||
|
elif uri == "SUB_ERROR":
|
||||||
|
text = escape_markdown_v2("Вы ещё не приобрели подписки!!")
|
||||||
elif "vless" in uri:
|
elif "vless" in uri:
|
||||||
text = f"Ваша подписка:```{uri}```"
|
escaped_uri = escape_markdown_v2(uri) # Экранирование URI
|
||||||
|
text = f"Ваша подписка: ```{escaped_uri}```"
|
||||||
else:
|
else:
|
||||||
text = "Произошла ошибка при получении URI"
|
text = escape_markdown_v2("Произошла ошибка при обработке URI")
|
||||||
|
except Exception as e:
|
||||||
|
# Логирование ошибок
|
||||||
|
logger.error(f"Ошибка при вызове API для подписки: {e}")
|
||||||
|
text = escape_markdown_v2("Произошла неожиданная ошибка при получении подписки.")
|
||||||
|
|
||||||
|
# Ответ пользователю
|
||||||
await message.answer(
|
await message.answer(
|
||||||
text,
|
text,
|
||||||
parse_mode=ParseMode.MARKDOWN_V2
|
parse_mode=ParseMode.MARKDOWN_V2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.callback_query(lambda callback: callback.data == "buy_subscription")
|
@router.callback_query(lambda callback: callback.data == "buy_subscription")
|
||||||
async def buy_subscription_callback_handler(callback: types.CallbackQuery):
|
async def buy_subscription_callback_handler(callback: types.CallbackQuery):
|
||||||
"""
|
"""
|
||||||
|
|||||||
2
main.py
2
main.py
@@ -23,7 +23,7 @@ dp.message.middleware(AntiSpamMiddleware(rate_limit=1))
|
|||||||
async def set_commands():
|
async def set_commands():
|
||||||
"""Устанавливает команды для бота."""
|
"""Устанавливает команды для бота."""
|
||||||
commands = [
|
commands = [
|
||||||
BotCommand(command="/start", description="🥚Запустить бота"),
|
BotCommand(command="/start", description="🥚Главное меню"),
|
||||||
BotCommand(command="/subscriptions", description="🦴Мои подписки"),
|
BotCommand(command="/subscriptions", description="🦴Мои подписки"),
|
||||||
BotCommand(command="/support", description="❕Поддержка❕"),
|
BotCommand(command="/support", description="❕Поддержка❕"),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user