mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-23 00:06:06 +08:00
修复消息回调函数有异常时程序会退出的问题
This commit is contained in:
parent
3f22840334
commit
f7ba8fdbbf
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -27,4 +27,5 @@ ntchat/wc/*.pyd
|
|||
ntchat/wc/*.dat
|
||||
wheelhouse/
|
||||
setup_conf.py
|
||||
upload.bat
|
||||
upload.bat
|
||||
download/
|
|
@ -1,6 +1,6 @@
|
|||
<h1 align="center">NtChat</h1>
|
||||
<p align="center">
|
||||
<a href="https://github.com/smallevilbeast/ntchat/releases"><img src="https://img.shields.io/badge/release-0.1.12-blue.svg?" alt="release"></a>
|
||||
<a href="https://github.com/smallevilbeast/ntchat/releases"><img src="https://img.shields.io/badge/release-0.1.13-blue.svg?" alt="release"></a>
|
||||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg?" alt="License"></a>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
VERSION = '0.1.12'
|
||||
VERSION = '0.1.13'
|
||||
|
||||
LOG_LEVEL = "DEBUG"
|
||||
LOG_KEY = 'NTCHAT_LOG'
|
||||
|
|
|
@ -46,6 +46,9 @@ MT_SEND_GIF_MSG = 11043
|
|||
# 发送xml消息
|
||||
MT_SEND_XML_MSG = 11113
|
||||
|
||||
# 修改好友备注
|
||||
MT_MODIFY_FRIEND_REMARK = 11063
|
||||
|
||||
# 接受新好友请求
|
||||
MT_ACCEPT_FRIEND_MSG = 11065
|
||||
|
||||
|
|
|
@ -41,6 +41,17 @@ class ReqData:
|
|||
return self.__response_message["data"]
|
||||
|
||||
|
||||
class RaiseExceptionFunc:
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
try:
|
||||
self.func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
log.error('callback error, in function `%s`, error: %s', self.func.__name__, e)
|
||||
|
||||
|
||||
class WeChat:
|
||||
client_id: int = 0
|
||||
pid: int = 0
|
||||
|
@ -55,7 +66,7 @@ class WeChat:
|
|||
self.__login_info = {}
|
||||
|
||||
def on(self, msg_type, f):
|
||||
return self.__msg_event_emitter.on(str(msg_type), f)
|
||||
return self.__msg_event_emitter.on(str(msg_type), RaiseExceptionFunc(f))
|
||||
|
||||
def msg_register(self, msg_type: Union[int, List[int], Tuple[int]]):
|
||||
if not (isinstance(msg_type, list) or isinstance(msg_type, tuple)):
|
||||
|
@ -64,7 +75,7 @@ class WeChat:
|
|||
def wrapper(f):
|
||||
wraps(f)
|
||||
for event in msg_type:
|
||||
self.on(event, f)
|
||||
self.on(event, RaiseExceptionFunc(f))
|
||||
return f
|
||||
|
||||
return wrapper
|
||||
|
@ -457,3 +468,13 @@ class WeChat:
|
|||
"room_wxid": room_wxid
|
||||
}
|
||||
return self.__send(send_type.MT_QUIT_DEL_ROOM_MSG, data)
|
||||
|
||||
def modify_friend_remark(self, wxid: str, remark: str):
|
||||
"""
|
||||
修改好友备注
|
||||
"""
|
||||
data = {
|
||||
"wxid": wxid,
|
||||
"remark": remark
|
||||
}
|
||||
return self.__send_sync(send_type.MT_MODIFY_FRIEND_REMARK, data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user