Added socks5 proxy support

This commit is contained in:
Joan
2024-03-24 18:17:11 +01:00
parent b48db482f2
commit 8af20ad7e9
4 changed files with 23 additions and 4 deletions

View File

@@ -1,4 +1,9 @@
TELEGRAM_TOKEN=
ADMIN_IDS=
GROUP_CHAT_ID=
SPREADSHEET_ID=
SPREADSHEET_ID=
TELEGRAM_PROXY=
TELEGRAM_SOCKS_USER=
TELEGRAM_SOCKS_PASSWORD=
TELEGRAM_SOCKS_SERVER=
TELEGRAM_SOCKS_PORT=

View File

@@ -7,7 +7,7 @@ import gspread
from oauth2client.service_account import ServiceAccountCredentials
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ConversationHandler, CallbackContext, CallbackQueryHandler
from telegram.ext import Application, ApplicationBuilder, CommandHandler, MessageHandler, filters, ConversationHandler, CallbackContext, CallbackQueryHandler
from telegram.constants import ParseMode
PRODUCT_NAME, PRODUCT_DESCRIPTION, PRICE_MEMBER, PRICE, PRODUCT_IMAGE, LIMIT, LIMIT_PER_USER, UNLIMITED, LIMITED = range(9)
@@ -28,6 +28,13 @@ general_group_chat_id = os.environ.get("GENERAL_GROUP_CHAT_ID")
vip_group_chat_id = os.environ.get("VIP_GROUP_CHAT_ID")
bot_token = os.environ.get("TELEGRAM_TOKEN")
spreadsheet_id = os.environ.get("SPREADSHEET_ID")
telegram_proxy = os.environ.get("TELEGRAM_PROXY")
if telegram_proxy:
telegram_socks_user = os.environ.get("TELEGRAM_SOCKS_USER")
telegram_socks_password = os.environ.get("TELEGRAM_SOCKS_PASSWORD")
telegram_socks_server = os.environ.get("TELEGRAM_SOCKS_SERVER")
telegram_socks_port = os.environ.get("TELEGRAM_SOCKS_PORT")
proxy_url = f"socks5://{telegram_socks_user}:{telegram_socks_password}@{telegram_socks_server}:{telegram_socks_port}"
# Configura la base de datos SQLite
conn = sqlite3.connect('/app/data/conjuntas.db')
@@ -757,7 +764,10 @@ async def help(update: Update, context: CallbackContext):
await update.message.reply_text(text=message, parse_mode=ParseMode.HTML)
def main()->None:
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(bot_token).build()
if telegram_proxy:
application = ApplicationBuilder().get_updates_http_version('1.1').http_version('1.1').token(bot_token).proxy(proxy_url).get_updates_proxy(proxy_url).build()
else:
application = ApplicationBuilder().get_updates_http_version('1.1').http_version('1.1').token(bot_token).build()
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start_conjunta', start_conjunta),

View File

@@ -1,3 +1,3 @@
python-telegram-bot==20.4
python-telegram-bot[socks]==21.0.1
gspread==5.12.0
oauth2client==4.1.3

View File

@@ -15,5 +15,9 @@ services:
- GENERAL_GROUP_CHAT_ID=${GENERAL_GROUP_CHAT_ID}
- VIP_GROUP_CHAT_ID=${VIP_GROUP_CHAT_ID}
- SPREADSHEET_ID=${SPREADSHEET_ID}
- TELEGRAM_SOCKS_USER=${TELEGRAM_SOCKS_USER}
- TELEGRAM_SOCKS_PASSWORD=${TELEGRAM_SOCKS_PASSWORD}
- TELEGRAM_SOCKS_SERVER=${TELEGRAM_SOCKS_SERVER}
- TELEGRAM_SOCKS_PORT=${TELEGRAM_SOCKS_PORT}
dns:
- 8.8.8.8