feat(bot): forward download errors to admin bot
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 51s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 51s
Notify admin (URL + error text + user info) on any download failure across all sources, and on the file-too-large case, mirroring the existing successful-download notification. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
72ba00bdcd
commit
be1acaaf2b
1 changed files with 44 additions and 2 deletions
46
bot.py
46
bot.py
|
|
@ -558,6 +558,45 @@ async def send_video_to_admin_bot(video_path: str, url: str, from_user=None):
|
|||
logger.error(f"Ошибка при отправке видео админ боту: {e}")
|
||||
|
||||
|
||||
async def notify_admin_error(url: str, error_text: str, from_user=None):
|
||||
"""Отправляет админ боту уведомление об ошибке скачивания"""
|
||||
if not ADMIN_BOT_TOKEN:
|
||||
return # Админ бот не настроен, пропускаем
|
||||
|
||||
admin_chat_id = get_admin_chat_id()
|
||||
if not admin_chat_id:
|
||||
logger.debug("Админ chat_id не найден, пропускаю отправку ошибки")
|
||||
return
|
||||
|
||||
try:
|
||||
request = HTTPXRequest(
|
||||
read_timeout=30,
|
||||
write_timeout=30,
|
||||
connect_timeout=15,
|
||||
pool_timeout=15
|
||||
)
|
||||
admin_bot = Bot(token=ADMIN_BOT_TOKEN, request=request)
|
||||
|
||||
user_info = ""
|
||||
if from_user:
|
||||
username = f"@{from_user.username}" if from_user.username else "без username"
|
||||
user_info = f"Пользователь: {username} (ID: {from_user.id})"
|
||||
if from_user.first_name:
|
||||
user_info += f", {from_user.first_name}"
|
||||
|
||||
text = f"⚠️ Ошибка скачивания\n\n🔗 URL: {url}\n\n❗ {error_text}"
|
||||
if user_info:
|
||||
text += f"\n👤 {user_info}"
|
||||
if len(text) > 4000:
|
||||
text = text[:4000] + "…"
|
||||
|
||||
await admin_bot.send_message(chat_id=admin_chat_id, text=text)
|
||||
logger.info(f"Уведомление об ошибке отправлено админ боту: {url}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка при отправке уведомления об ошибке админ боту: {e}")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# СИСТЕМА ОЧЕРЕДЕЙ
|
||||
# ============================================================================
|
||||
|
|
@ -612,9 +651,10 @@ async def process_queue_item(item: QueueItem):
|
|||
# Определяем источник и увеличиваем счетчик ошибок
|
||||
source = detect_video_source(item.url)
|
||||
increment_error_count(source)
|
||||
|
||||
|
||||
size_mb = file_size / (1024 * 1024)
|
||||
error_msg = get_text(item.locale, 'error_file_too_large', size_mb=size_mb)
|
||||
await notify_admin_error(item.url, f"Файл слишком большой: {size_mb:.1f} MB", item.original_message.from_user)
|
||||
await item.status_message.edit_text(error_msg)
|
||||
# Удаляем слишком большой файл
|
||||
try:
|
||||
|
|
@ -688,7 +728,9 @@ async def process_queue_item(item: QueueItem):
|
|||
# Определяем источник и увеличиваем счетчик ошибок
|
||||
source = detect_video_source(item.url)
|
||||
increment_error_count(source)
|
||||
|
||||
|
||||
await notify_admin_error(item.url, str(e), item.original_message.from_user)
|
||||
|
||||
error_msg = get_text(item.locale, 'error', error=str(e))
|
||||
try:
|
||||
await item.status_message.edit_text(error_msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue