99import os
1010import threading
1111import time
12-
1312import requests
1413
1514from bridge .context import *
2120from common .log import logger
2221from common .singleton import singleton
2322from common .time_check import time_checker
23+ from common .utils import convert_webp_to_png
2424from config import conf , get_appdata_dir
2525from lib import itchat
2626from lib .itchat .content import *
@@ -109,7 +109,7 @@ class WechatChannel(ChatChannel):
109109
110110 def __init__ (self ):
111111 super ().__init__ ()
112- self .receivedMsgs = ExpiredDict (conf ().get ("expires_in_seconds" ))
112+ self .receivedMsgs = ExpiredDict (conf ().get ("expires_in_seconds" , 3600 ))
113113 self .auto_login_times = 0
114114
115115 def startup (self ):
@@ -229,6 +229,12 @@ def send(self, reply: Reply, context: Context):
229229 image_storage .write (block )
230230 logger .info (f"[WX] download image success, size={ size } , img_url={ img_url } " )
231231 image_storage .seek (0 )
232+ if ".webp" in img_url :
233+ try :
234+ image_storage = convert_webp_to_png (image_storage )
235+ except Exception as e :
236+ logger .error (f"Failed to convert image: { e } " )
237+ return
232238 itchat .send_image (image_storage , toUserName = receiver )
233239 logger .info ("[WX] sendImage url={}, receiver={}" .format (img_url , receiver ))
234240 elif reply .type == ReplyType .IMAGE : # 从文件读取图片
@@ -266,6 +272,7 @@ def _send_login_success():
266272 except Exception as e :
267273 pass
268274
275+
269276def _send_logout ():
270277 try :
271278 from common .linkai_client import chat_client
@@ -274,10 +281,12 @@ def _send_logout():
274281 except Exception as e :
275282 pass
276283
284+
277285def _send_qr_code (qrcode_list : list ):
278286 try :
279287 from common .linkai_client import chat_client
280288 if chat_client .client_id :
281289 chat_client .send_qrcode (qrcode_list )
282290 except Exception as e :
283291 pass
292+
0 commit comments