Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from telegram.error import TimedOut, NetworkError, TelegramError
from telegram.ext import Application, MessageHandler, filters, ContextTypes
from telegram.constants import MessageEntityType
from telegram.request import HTTPXRequest
from logger import error, info, debug
from general_error_handler import error_handler
from permissions import inform_user_not_allowed, is_user_or_chat_not_allowed, supported_sites
Expand Down Expand Up @@ -47,8 +48,10 @@
GEMINI_MODEL = os.getenv("GEMINI_MODEL", "gemini-flash-latest")
GROK_API_KEY = os.getenv("GROK_API_KEY")
GROK_MODEL = os.getenv("GROK_MODEL", "grok-4-latest")
TELEGRAM_WRITE_TIMEOUT = 8000
TELEGRAM_READ_TIMEOUT = 8000
TELEGRAM_CONNECT_TIMEOUT = 60
TELEGRAM_POOL_TIMEOUT = 30
TELEGRAM_READ_TIMEOUT = 120
TELEGRAM_WRITE_TIMEOUT = 120

# Configure Gemini API
if GEMINI_API_KEY:
Expand Down Expand Up @@ -408,6 +411,7 @@ async def send_video(update: Update, video, has_spoiler: bool) -> None:
height=height,
has_spoiler=has_spoiler,
disable_notification=True,
connect_timeout=TELEGRAM_CONNECT_TIMEOUT,
write_timeout=TELEGRAM_WRITE_TIMEOUT,
read_timeout=TELEGRAM_READ_TIMEOUT,
reply_to_message_id=update.message.message_id,
Expand Down Expand Up @@ -436,6 +440,7 @@ async def send_video(update: Update, video, has_spoiler: bool) -> None:
await update.message.chat.send_media_group(
media=media_group,
disable_notification=True,
connect_timeout=TELEGRAM_CONNECT_TIMEOUT,
write_timeout=TELEGRAM_WRITE_TIMEOUT,
read_timeout=TELEGRAM_READ_TIMEOUT,
)
Expand Down Expand Up @@ -468,6 +473,7 @@ async def send_pic(update: Update, pic) -> None:
await update.message.chat.send_photo(
photo=pic_file,
disable_notification=True,
connect_timeout=TELEGRAM_CONNECT_TIMEOUT,
write_timeout=TELEGRAM_WRITE_TIMEOUT,
read_timeout=TELEGRAM_READ_TIMEOUT,
)
Expand All @@ -494,6 +500,7 @@ async def send_pic(update: Update, pic) -> None:
await update.message.chat.send_media_group(
media=media_group,
disable_notification=True,
connect_timeout=TELEGRAM_CONNECT_TIMEOUT,
write_timeout=TELEGRAM_WRITE_TIMEOUT,
read_timeout=TELEGRAM_READ_TIMEOUT,
)
Expand Down Expand Up @@ -947,7 +954,13 @@ def main():
None
"""
bot_token = os.getenv("BOT_TOKEN")
application = Application.builder().token(bot_token).build()
request = HTTPXRequest(
connect_timeout=TELEGRAM_CONNECT_TIMEOUT,
pool_timeout=TELEGRAM_POOL_TIMEOUT,
read_timeout=TELEGRAM_READ_TIMEOUT,
write_timeout=TELEGRAM_WRITE_TIMEOUT,
)
application = Application.builder().token(bot_token).request(request).build()
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
# This handler will receive every error which happens in your bot
application.add_error_handler(error_handler)
Expand Down
Loading