@@ -43,6 +43,8 @@ def __init__(self):
4343 self .admin_ignore = plugin_config ["admin_ignore" ]
4444 self .whitelist_ignore = plugin_config ["whitelist_ignore" ]
4545
46+ self .http_proxy = plugin_config ["http-proxy" ]
47+
4648 self .db = BotDatabase ()
4749
4850 @on_text_message
@@ -174,7 +176,7 @@ async def dify(self, bot: WechatAPIClient, message: dict, query: str, files=None
174176 url = f"{ self .base_url } /chat-messages"
175177
176178 ai_resp = ""
177- async with aiohttp .ClientSession () as session :
179+ async with aiohttp .ClientSession (proxy = self . http_proxy ) as session :
178180 async with session .post (url = url , headers = headers , data = payload ) as resp :
179181 if resp .status == 200 :
180182 # 读取响应
@@ -238,7 +240,7 @@ async def upload_file(self, user: str, file: bytes):
238240
239241 url = f"{ self .base_url } /files/upload"
240242
241- async with aiohttp .ClientSession () as session :
243+ async with aiohttp .ClientSession (proxy = self . http_proxy ) as session :
242244 async with session .post (url , headers = headers , data = formdata ) as resp :
243245 resp_json = await resp .json ()
244246
@@ -267,16 +269,14 @@ async def dify_handle_text(self, bot: WechatAPIClient, message: dict, text: str)
267269 if text :
268270 await bot .send_at_message (message ["FromWxid" ], "\n " + text , [message ["SenderWxid" ]])
269271
270- @staticmethod
271- async def download_file (url : str ) -> bytes :
272- async with aiohttp .ClientSession () as session :
272+ async def download_file (self , url : str ) -> bytes :
273+ async with aiohttp .ClientSession (proxy = self .http_proxy ) as session :
273274 async with session .get (url ) as resp :
274275 return await resp .read ()
275276
276- @staticmethod
277- async def dify_handle_image (bot : WechatAPIClient , message : dict , image : Union [str , bytes ]):
277+ async def dify_handle_image (self , bot : WechatAPIClient , message : dict , image : Union [str , bytes ]):
278278 if isinstance (image , str ) and image .startswith ("http" ):
279- async with aiohttp .ClientSession () as session :
279+ async with aiohttp .ClientSession (proxy = self . http_proxy ) as session :
280280 async with session .get (image ) as resp :
281281 image = bot .byte_to_base64 (await resp .read ())
282282 elif isinstance (image , bytes ):
0 commit comments