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 asyncio
|
||||||
import aiohttp
|
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 import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
from telegram.ext import Application, CommandHandler, MessageHandler, CallbackQueryHandler, ContextTypes, filters
|
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
|
return
|
||||||
|
|
||||||
def run_telegram_bot():
|
def run_telegram_bot():
|
||||||
|
try:
|
||||||
from botdiscord.database import init_db
|
from botdiscord.database import init_db
|
||||||
init_db()
|
init_db()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Advertencia: Error al inicializar DB (reintentando luego): {e}")
|
||||||
|
|
||||||
token = get_telegram_token()
|
token = get_telegram_token()
|
||||||
if not token or token == "TU_TELEGRAM_BOT_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
|
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("start", start))
|
||||||
application.add_handler(CommandHandler("idiomas", languages_command))
|
application.add_handler(CommandHandler("idiomas", languages_command))
|
||||||
|
|||||||
12
casaos.yaml
12
casaos.yaml
@@ -13,7 +13,7 @@ services:
|
|||||||
- ADMIN_USERNAME=nickpons666
|
- ADMIN_USERNAME=nickpons666
|
||||||
- DATABASE_PATH=/app/data/bots_config.db
|
- DATABASE_PATH=/app/data/bots_config.db
|
||||||
- DB_HOST=10.10.4.17
|
- DB_HOST=10.10.4.17
|
||||||
- DB_NAME=mi_red
|
- DB_NAME=traductor_bots
|
||||||
- DB_PASSWORD=MiPo6425@@
|
- DB_PASSWORD=MiPo6425@@
|
||||||
- DB_PORT=3390
|
- DB_PORT=3390
|
||||||
- DB_TYPE=mysql
|
- DB_TYPE=mysql
|
||||||
@@ -25,8 +25,11 @@ services:
|
|||||||
- WEB_PORT=8000
|
- WEB_PORT=8000
|
||||||
hostname: bots-translation
|
hostname: bots-translation
|
||||||
image: registry-pons.duckdns.org/bots-translation:v1
|
image: registry-pons.duckdns.org/bots-translation:v1
|
||||||
|
dns:
|
||||||
|
- 8.8.8.8
|
||||||
|
- 1.1.1.1
|
||||||
labels:
|
labels:
|
||||||
icon: https://raw.githubusercontent.com/istomes/casaos-icons/main/icons/bot.png
|
icon: https://www.ruthlessreviews.com/wp-content/uploads/2025/12/last-war-image.jpg
|
||||||
ports:
|
ports:
|
||||||
- target: 8000
|
- target: 8000
|
||||||
published: "8091"
|
published: "8091"
|
||||||
@@ -36,6 +39,9 @@ services:
|
|||||||
- type: bind
|
- type: bind
|
||||||
source: /DATA/AppData/bots-translation/data
|
source: /DATA/AppData/bots-translation/data
|
||||||
target: /app/data
|
target: /app/data
|
||||||
|
- type: bind
|
||||||
|
source: /DATA/AppData/bots-translation/data/logs
|
||||||
|
target: /app/data/logs
|
||||||
x-casaos:
|
x-casaos:
|
||||||
envs:
|
envs:
|
||||||
- container: DISCORD_TOKEN
|
- container: DISCORD_TOKEN
|
||||||
@@ -95,7 +101,7 @@ x-casaos:
|
|||||||
en_us: Bots de traducción para Discord y Telegram con panel web
|
en_us: Bots de traducción para Discord y Telegram con panel web
|
||||||
developer: nickpons666
|
developer: nickpons666
|
||||||
hostname: ""
|
hostname: ""
|
||||||
icon: https://raw.githubusercontent.com/istomes/casaos-icons/main/icons/bot.png
|
icon: https://www.ruthlessreviews.com/wp-content/uploads/2025/12/last-war-image.jpg
|
||||||
index: /
|
index: /
|
||||||
is_uncontrolled: false
|
is_uncontrolled: false
|
||||||
main: bots-translation
|
main: bots-translation
|
||||||
|
|||||||
Reference in New Issue
Block a user