telebot proxy

This commit is contained in:
jxxghp 2023-06-10 17:30:00 +08:00
parent 183f9afff2
commit c5e3a7fa97

View File

@ -4,6 +4,7 @@ from threading import Event
from typing import Optional, List from typing import Optional, List
import telebot import telebot
from telebot import apihelper
from telebot.types import InputFile from telebot.types import InputFile
from app.core.config import settings from app.core.config import settings
@ -13,6 +14,9 @@ from app.utils.http import RequestUtils
from app.utils.singleton import Singleton from app.utils.singleton import Singleton
apihelper.proxy = settings.PROXY
class Telegram(metaclass=Singleton): class Telegram(metaclass=Singleton):
_ds_url = f"http://127.0.0.1:{settings.PORT}/api/v1/messages?token={settings.API_TOKEN}" _ds_url = f"http://127.0.0.1:{settings.PORT}/api/v1/messages?token={settings.API_TOKEN}"
_event = Event() _event = Event()
@ -154,7 +158,7 @@ class Telegram(metaclass=Singleton):
""" """
if image: if image:
req = RequestUtils().get_res(image) req = RequestUtils(proxies=settings.PROXY).get_res(image)
if req and req.content: if req and req.content:
image_file = Path(settings.TEMP_PATH) / Path(image).name image_file = Path(settings.TEMP_PATH) / Path(image).name
image_file.write_bytes(req.content) image_file.write_bytes(req.content)