mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-23 05:16:07 +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
|
ntchat/wc/*.dat
|
||||||
wheelhouse/
|
wheelhouse/
|
||||||
setup_conf.py
|
setup_conf.py
|
||||||
upload.bat
|
upload.bat
|
||||||
|
download/
|
|
@ -1,6 +1,6 @@
|
||||||
<h1 align="center">NtChat</h1>
|
<h1 align="center">NtChat</h1>
|
||||||
<p align="center">
|
<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>
|
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg?" alt="License"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
VERSION = '0.1.12'
|
VERSION = '0.1.13'
|
||||||
|
|
||||||
LOG_LEVEL = "DEBUG"
|
LOG_LEVEL = "DEBUG"
|
||||||
LOG_KEY = 'NTCHAT_LOG'
|
LOG_KEY = 'NTCHAT_LOG'
|
||||||
|
|
|
@ -46,6 +46,9 @@ MT_SEND_GIF_MSG = 11043
|
||||||
# 发送xml消息
|
# 发送xml消息
|
||||||
MT_SEND_XML_MSG = 11113
|
MT_SEND_XML_MSG = 11113
|
||||||
|
|
||||||
|
# 修改好友备注
|
||||||
|
MT_MODIFY_FRIEND_REMARK = 11063
|
||||||
|
|
||||||
# 接受新好友请求
|
# 接受新好友请求
|
||||||
MT_ACCEPT_FRIEND_MSG = 11065
|
MT_ACCEPT_FRIEND_MSG = 11065
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,17 @@ class ReqData:
|
||||||
return self.__response_message["data"]
|
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:
|
class WeChat:
|
||||||
client_id: int = 0
|
client_id: int = 0
|
||||||
pid: int = 0
|
pid: int = 0
|
||||||
|
@ -55,7 +66,7 @@ class WeChat:
|
||||||
self.__login_info = {}
|
self.__login_info = {}
|
||||||
|
|
||||||
def on(self, msg_type, f):
|
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]]):
|
def msg_register(self, msg_type: Union[int, List[int], Tuple[int]]):
|
||||||
if not (isinstance(msg_type, list) or isinstance(msg_type, tuple)):
|
if not (isinstance(msg_type, list) or isinstance(msg_type, tuple)):
|
||||||
|
@ -64,7 +75,7 @@ class WeChat:
|
||||||
def wrapper(f):
|
def wrapper(f):
|
||||||
wraps(f)
|
wraps(f)
|
||||||
for event in msg_type:
|
for event in msg_type:
|
||||||
self.on(event, f)
|
self.on(event, RaiseExceptionFunc(f))
|
||||||
return f
|
return f
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -457,3 +468,13 @@ class WeChat:
|
||||||
"room_wxid": room_wxid
|
"room_wxid": room_wxid
|
||||||
}
|
}
|
||||||
return self.__send(send_type.MT_QUIT_DEL_ROOM_MSG, data)
|
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)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -194,7 +194,7 @@ extension.extra_compile_cpp_args = extra_compile_cpp_args[target_os]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='ntchat',
|
name='ntchat',
|
||||||
version='0.1.12',
|
version='0.1.13',
|
||||||
description='About Conversational RPA SDK for Chatbot Makers',
|
description='About Conversational RPA SDK for Chatbot Makers',
|
||||||
long_description="",
|
long_description="",
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user