mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 13:28:11 +08:00
Merge branch 'master' of github.com:zhayujie/chatgpt-on-wechat
This commit is contained in:
@@ -509,7 +509,7 @@ class MemoryStorage:
|
|||||||
"""Destructor to ensure connection is closed"""
|
"""Destructor to ensure connection is closed"""
|
||||||
try:
|
try:
|
||||||
self.close()
|
self.close()
|
||||||
except:
|
except Exception:
|
||||||
pass # Ignore errors during cleanup
|
pass # Ignore errors during cleanup
|
||||||
|
|
||||||
# Helper methods
|
# Helper methods
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class Ls(BaseTool):
|
|||||||
results.append(entry + '/')
|
results.append(entry + '/')
|
||||||
else:
|
else:
|
||||||
results.append(entry)
|
results.append(entry)
|
||||||
except:
|
except Exception:
|
||||||
# Skip entries we can't stat
|
# Skip entries we can't stat
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class SchedulerService:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return now >= next_run
|
return now >= next_run
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _calculate_next_run(self, task: dict, from_time: datetime) -> Optional[datetime]:
|
def _calculate_next_run(self, task: dict, from_time: datetime) -> Optional[datetime]:
|
||||||
@@ -195,7 +195,7 @@ class SchedulerService:
|
|||||||
# Only return if in the future
|
# Only return if in the future
|
||||||
if run_at > from_time:
|
if run_at > from_time:
|
||||||
return run_at
|
return run_at
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ class SchedulerTool(BaseTool):
|
|||||||
try:
|
try:
|
||||||
dt = datetime.fromisoformat(run_at)
|
dt = datetime.fromisoformat(run_at)
|
||||||
return f"一次性 ({dt.strftime('%Y-%m-%d %H:%M')})"
|
return f"一次性 ({dt.strftime('%Y-%m-%d %H:%M')})"
|
||||||
except:
|
except Exception:
|
||||||
return "一次性"
|
return "一次性"
|
||||||
|
|
||||||
return "未知"
|
return "未知"
|
||||||
@@ -438,6 +438,6 @@ class SchedulerTool(BaseTool):
|
|||||||
return msg.other_user_nickname or "群聊"
|
return msg.other_user_nickname or "群聊"
|
||||||
else:
|
else:
|
||||||
return msg.from_user_nickname or "用户"
|
return msg.from_user_nickname or "用户"
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return "未知"
|
return "未知"
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class TaskStore:
|
|||||||
with open(self.store_path, 'r') as src:
|
with open(self.store_path, 'r') as src:
|
||||||
with open(backup_path, 'w') as dst:
|
with open(backup_path, 'w') as dst:
|
||||||
dst.write(src.read())
|
dst.write(src.read())
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Save tasks
|
# Save tasks
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def check_dulwich():
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
install("dulwich")
|
install("dulwich")
|
||||||
except:
|
except Exception:
|
||||||
needwait = True
|
needwait = True
|
||||||
try:
|
try:
|
||||||
import dulwich
|
import dulwich
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ def load_config():
|
|||||||
logger.info("[INIT] override config by environ args: {}={}".format(name, value))
|
logger.info("[INIT] override config by environ args: {}={}".format(name, value))
|
||||||
try:
|
try:
|
||||||
config[name] = eval(value)
|
config[name] = eval(value)
|
||||||
except:
|
except Exception:
|
||||||
if value == "false":
|
if value == "false":
|
||||||
config[name] = False
|
config[name] = False
|
||||||
elif value == "true":
|
elif value == "true":
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ def get_contact(self, update=False):
|
|||||||
'User-Agent' : config.USER_AGENT, }
|
'User-Agent' : config.USER_AGENT, }
|
||||||
try:
|
try:
|
||||||
r = self.s.get(url, headers=headers)
|
r = self.s.get(url, headers=headers)
|
||||||
except:
|
except Exception:
|
||||||
logger.info('Failed to fetch contact, that may because of the amount of your chatrooms')
|
logger.info('Failed to fetch contact, that may because of the amount of your chatrooms')
|
||||||
for chatroom in self.get_chatrooms():
|
for chatroom in self.get_chatrooms():
|
||||||
self.update_chatroom(chatroom['UserName'], detailedMember=True)
|
self.update_chatroom(chatroom['UserName'], detailedMember=True)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ async def dump_login_status(self, fileDir=None):
|
|||||||
with open(fileDir, 'w') as f:
|
with open(fileDir, 'w') as f:
|
||||||
f.write('itchat - DELETE THIS')
|
f.write('itchat - DELETE THIS')
|
||||||
os.remove(fileDir)
|
os.remove(fileDir)
|
||||||
except:
|
except Exception:
|
||||||
raise Exception('Incorrect fileDir')
|
raise Exception('Incorrect fileDir')
|
||||||
status = {
|
status = {
|
||||||
'version' : VERSION,
|
'version' : VERSION,
|
||||||
@@ -57,7 +57,7 @@ async def load_login_status(self, fileDir,
|
|||||||
self.storageClass.loads(j['storage'])
|
self.storageClass.loads(j['storage'])
|
||||||
try:
|
try:
|
||||||
msgList, contactList = self.get_msg()
|
msgList, contactList = self.get_msg()
|
||||||
except:
|
except Exception:
|
||||||
msgList = contactList = None
|
msgList = contactList = None
|
||||||
if (msgList or contactList) is None:
|
if (msgList or contactList) is None:
|
||||||
self.logout()
|
self.logout()
|
||||||
@@ -97,6 +97,6 @@ async def load_last_login_status(session, cookiesDict):
|
|||||||
'mm_lang': 'zh_CN',
|
'mm_lang': 'zh_CN',
|
||||||
'MM_WX_NOTIFY_STATE': '1',
|
'MM_WX_NOTIFY_STATE': '1',
|
||||||
'MM_WX_SOUND_STATE': '1', })
|
'MM_WX_SOUND_STATE': '1', })
|
||||||
except:
|
except Exception:
|
||||||
logger.info('Load status for push login failed, we may have experienced a cookies change.')
|
logger.info('Load status for push login failed, we may have experienced a cookies change.')
|
||||||
logger.info('If you are using the newest version of itchat, you may report a bug.')
|
logger.info('If you are using the newest version of itchat, you may report a bug.')
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ async def start_receiving(self, exitCallback=None, getReceivingFnOnly=False):
|
|||||||
retryCount = 0
|
retryCount = 0
|
||||||
except requests.exceptions.ReadTimeout:
|
except requests.exceptions.ReadTimeout:
|
||||||
pass
|
pass
|
||||||
except:
|
except Exception:
|
||||||
retryCount += 1
|
retryCount += 1
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
if self.receivingRetryCount < retryCount:
|
if self.receivingRetryCount < retryCount:
|
||||||
@@ -372,7 +372,7 @@ def sync_check(self):
|
|||||||
# 6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:a4:25:5d:12:f4:31:a5:30:f1:c6:48:5f:c3:75:6a:99:93
|
# 6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:a4:25:5d:12:f4:31:a5:30:f1:c6:48:5f:c3:75:6a:99:93
|
||||||
# seems like status of typing, but before I make further achievement code will remain like this
|
# seems like status of typing, but before I make further achievement code will remain like this
|
||||||
return '2'
|
return '2'
|
||||||
except:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
|
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ async def configured_reply(self, event_stream, payload, message_container):
|
|||||||
r = await replyFn(msg)
|
r = await replyFn(msg)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
await self.send(r, msg.get('FromUserName'))
|
await self.send(r, msg.get('FromUserName'))
|
||||||
except:
|
except Exception:
|
||||||
logger.warning(traceback.format_exc())
|
logger.warning(traceback.format_exc())
|
||||||
|
|
||||||
def msg_register(self, msgType, isFriendChat=False, isGroupChat=False, isMpChat=False):
|
def msg_register(self, msgType, isFriendChat=False, isGroupChat=False, isMpChat=False):
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ def get_contact(self, update=False):
|
|||||||
'User-Agent': config.USER_AGENT, }
|
'User-Agent': config.USER_AGENT, }
|
||||||
try:
|
try:
|
||||||
r = self.s.get(url, headers=headers)
|
r = self.s.get(url, headers=headers)
|
||||||
except:
|
except Exception:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Failed to fetch contact, that may because of the amount of your chatrooms')
|
'Failed to fetch contact, that may because of the amount of your chatrooms')
|
||||||
for chatroom in self.get_chatrooms():
|
for chatroom in self.get_chatrooms():
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def dump_login_status(self, fileDir=None):
|
|||||||
with open(fileDir, 'w') as f:
|
with open(fileDir, 'w') as f:
|
||||||
f.write('itchat - DELETE THIS')
|
f.write('itchat - DELETE THIS')
|
||||||
os.remove(fileDir)
|
os.remove(fileDir)
|
||||||
except:
|
except Exception:
|
||||||
raise Exception('Incorrect fileDir')
|
raise Exception('Incorrect fileDir')
|
||||||
status = {
|
status = {
|
||||||
'version' : VERSION,
|
'version' : VERSION,
|
||||||
@@ -57,7 +57,7 @@ def load_login_status(self, fileDir,
|
|||||||
self.storageClass.loads(j['storage'])
|
self.storageClass.loads(j['storage'])
|
||||||
try:
|
try:
|
||||||
msgList, contactList = self.get_msg()
|
msgList, contactList = self.get_msg()
|
||||||
except:
|
except Exception:
|
||||||
msgList = contactList = None
|
msgList = contactList = None
|
||||||
if (msgList or contactList) is None:
|
if (msgList or contactList) is None:
|
||||||
self.logout()
|
self.logout()
|
||||||
@@ -97,6 +97,6 @@ def load_last_login_status(session, cookiesDict):
|
|||||||
'mm_lang': 'zh_CN',
|
'mm_lang': 'zh_CN',
|
||||||
'MM_WX_NOTIFY_STATE': '1',
|
'MM_WX_NOTIFY_STATE': '1',
|
||||||
'MM_WX_SOUND_STATE': '1', })
|
'MM_WX_SOUND_STATE': '1', })
|
||||||
except:
|
except Exception:
|
||||||
logger.info('Load status for push login failed, we may have experienced a cookies change.')
|
logger.info('Load status for push login failed, we may have experienced a cookies change.')
|
||||||
logger.info('If you are using the newest version of itchat, you may report a bug.')
|
logger.info('If you are using the newest version of itchat, you may report a bug.')
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ def start_receiving(self, exitCallback=None, getReceivingFnOnly=False):
|
|||||||
retryCount = 0
|
retryCount = 0
|
||||||
except requests.exceptions.ReadTimeout:
|
except requests.exceptions.ReadTimeout:
|
||||||
pass
|
pass
|
||||||
except:
|
except Exception:
|
||||||
retryCount += 1
|
retryCount += 1
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
if self.receivingRetryCount < retryCount:
|
if self.receivingRetryCount < retryCount:
|
||||||
@@ -364,7 +364,7 @@ def sync_check(self):
|
|||||||
# 6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:a4:25:5d:12:f4:31:a5:30:f1:c6:48:5f:c3:75:6a:99:93
|
# 6f:00:8a:9c:09:74:e4:d8:e0:14:bf:96:3a:56:a0:64:1b:a4:25:5d:12:f4:31:a5:30:f1:c6:48:5f:c3:75:6a:99:93
|
||||||
# seems like status of typing, but before I make further achievement code will remain like this
|
# seems like status of typing, but before I make further achievement code will remain like this
|
||||||
return '2'
|
return '2'
|
||||||
except:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
|
regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ def configured_reply(self):
|
|||||||
r = replyFn(msg)
|
r = replyFn(msg)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
self.send(r, msg.get('FromUserName'))
|
self.send(r, msg.get('FromUserName'))
|
||||||
except:
|
except Exception:
|
||||||
logger.warning(traceback.format_exc())
|
logger.warning(traceback.format_exc())
|
||||||
|
|
||||||
def msg_register(self, msgType, isFriendChat=False, isGroupChat=False, isMpChat=False):
|
def msg_register(self, msgType, isFriendChat=False, isGroupChat=False, isMpChat=False):
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ def check_file(fileDir):
|
|||||||
with open(fileDir):
|
with open(fileDir):
|
||||||
pass
|
pass
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def print_qr(fileDir):
|
def print_qr(fileDir):
|
||||||
@@ -133,7 +133,7 @@ def test_connect(retryTime=5):
|
|||||||
try:
|
try:
|
||||||
r = requests.get(config.BASE_URL)
|
r = requests.get(config.BASE_URL)
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
if i == retryTime - 1:
|
if i == retryTime - 1:
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ class ChatGPTBot(Bot, OpenAIImage, OpenAICompatibleBot):
|
|||||||
try:
|
try:
|
||||||
os.remove(image_path)
|
os.remove(image_path)
|
||||||
logger.debug(f"[CHATGPT] Removed temp image file: {image_path}")
|
logger.debug(f"[CHATGPT] Removed temp image file: {image_path}")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return Reply(ReplyType.TEXT, content)
|
return Reply(ReplyType.TEXT, content)
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ class ClaudeAPIBot(Bot, OpenAIImage):
|
|||||||
try:
|
try:
|
||||||
error_data = json.loads(error_text)
|
error_data = json.loads(error_text)
|
||||||
error_msg = error_data.get("error", {}).get("message", error_text)
|
error_msg = error_data.get("error", {}).get("message", error_text)
|
||||||
except:
|
except Exception:
|
||||||
error_msg = error_text or "Unknown error"
|
error_msg = error_text or "Unknown error"
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ class GoogleGeminiBot(Bot):
|
|||||||
tool_result_data = json.loads(tool_content)
|
tool_result_data = json.loads(tool_content)
|
||||||
else:
|
else:
|
||||||
tool_result_data = tool_content
|
tool_result_data = tool_content
|
||||||
except:
|
except Exception:
|
||||||
tool_result_data = {"result": tool_content}
|
tool_result_data = {"result": tool_content}
|
||||||
|
|
||||||
# Find the tool name from previous messages
|
# Find the tool name from previous messages
|
||||||
|
|||||||
@@ -617,7 +617,7 @@ def _handle_linkai_stream_response(self, base_url, headers, body):
|
|||||||
try:
|
try:
|
||||||
error_data = json.loads(error_text)
|
error_data = json.loads(error_text)
|
||||||
error_msg = error_data.get("error", {}).get("message", error_text)
|
error_msg = error_data.get("error", {}).get("message", error_text)
|
||||||
except:
|
except Exception:
|
||||||
error_msg = error_text or "Unknown error"
|
error_msg = error_text or "Unknown error"
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
|
|||||||
Reference in New Issue
Block a user