fix(network): forzar IPv4, aumentar timeouts y configurar DNS en casaos.yaml para resolver problemas de conectividad en producción
This commit is contained in:
@@ -6,6 +6,15 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import socket
|
||||
|
||||
# Forzar IPv4 a nivel global para evitar problemas de conectividad en Docker/ZimaOS
|
||||
orig_getaddrinfo = socket.getaddrinfo
|
||||
def patched_getaddrinfo(*args, **kwargs):
|
||||
responses = orig_getaddrinfo(*args, **kwargs)
|
||||
return [res for res in responses if res[0] == socket.AF_INET]
|
||||
socket.getaddrinfo = patched_getaddrinfo
|
||||
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import Application, CommandHandler, MessageHandler, CallbackQueryHandler, ContextTypes, filters
|
||||
|
||||
@@ -283,15 +292,34 @@ async def handle_video_note(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
return
|
||||
|
||||
def run_telegram_bot():
|
||||
from botdiscord.database import init_db
|
||||
init_db()
|
||||
try:
|
||||
from botdiscord.database import init_db
|
||||
init_db()
|
||||
except Exception as e:
|
||||
print(f"⚠️ Advertencia: Error al inicializar DB (reintentando luego): {e}")
|
||||
|
||||
token = get_telegram_token()
|
||||
if not token or token == "TU_TELEGRAM_BOT_TOKEN":
|
||||
print("ERROR: Configura el token de Telegram en config.yaml")
|
||||
print("ERROR: Configura el token de Telegram en config.yaml o .env")
|
||||
return
|
||||
|
||||
application = Application.builder().token(token).build()
|
||||
# Configuración de red de máxima compatibilidad (Forzar IPv4 y HTTP/1.1)
|
||||
from telegram.request import HTTPXRequest
|
||||
import httpx
|
||||
import socket
|
||||
|
||||
# Creamos un pool que ignore IPv6 si es posible
|
||||
limits = httpx.Limits(max_connections=10, max_keepalive_connections=5)
|
||||
|
||||
request = HTTPXRequest(
|
||||
connect_timeout=30.0,
|
||||
read_timeout=30.0,
|
||||
write_timeout=30.0,
|
||||
pool_timeout=30.0,
|
||||
http_version="1.1"
|
||||
)
|
||||
|
||||
application = Application.builder().token(token).request(request).build()
|
||||
|
||||
application.add_handler(CommandHandler("start", start))
|
||||
application.add_handler(CommandHandler("idiomas", languages_command))
|
||||
|
||||
Reference in New Issue
Block a user