优化异常输出

This commit is contained in:
evilbeast 2022-10-09 12:37:03 +08:00
parent 38506a0e7b
commit 330f0724f3
10 changed files with 55 additions and 11 deletions

View File

@ -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.15-blue.svg?" alt="release"></a>
<a href="https://github.com/smallevilbeast/ntchat/releases"><img src="https://img.shields.io/badge/release-0.1.16-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>

View File

@ -114,6 +114,17 @@ async def get_rooms(model: models.ClientReqModel):
return response_json(1, data)
@app.post("/room/get_name_name", summary="获取群名称", tags=["Room"],
response_model=models.ResponseModel)
@catch_exception()
async def get_rooms(model: models.GetRoomNameReqModel):
name = client_mgr.get_client(model.guid).get_room_name(model.room_wxid)
data = {
"name": name
}
return response_json(1, data)
@app.post("/room/get_room_members", summary="获取群成员列表", tags=["Room"],
response_model=models.ResponseModel)
@catch_exception()

View File

@ -87,6 +87,10 @@ class GetRoomMembersReqModel(ClientReqModel):
room_wxid: str
class GetRoomNameReqModel(ClientReqModel):
room_wxid: str
class CreateRoomReqModel(ClientReqModel):
member_list: List[str]

View File

@ -1,4 +1,4 @@
VERSION = '0.1.15'
VERSION = '0.1.16'
LOG_LEVEL = "DEBUG"
LOG_KEY = 'NTCHAT_LOG'

View File

@ -1,8 +1,8 @@
import json
import os.path
from ntchat.wc import wcprobe
from ntchat.utils.xdg import get_helper_file
from ntchat.exception import WeChatVersionNotMatchError, WeChatBindError
from ntchat.wc import wcprobe, SUPPORT_VERSIONS
from ntchat.utils.xdg import get_helper_file, is_support_version, has_helper_file
from ntchat.exception import WeChatVersionNotMatchError, WeChatBindError, WeChatRuntimeError
from ntchat.utils.singleton import Singleton
from ntchat.const import notify_type
from ntchat.utils.logger import get_logger
@ -31,9 +31,16 @@ class WeChatMgr(metaclass=Singleton):
else:
version = wechat_version
if not is_support_version(version):
raise WeChatVersionNotMatchError(f"ntchat support wechat versions: {','.join(SUPPORT_VERSIONS)}")
if not has_helper_file():
raise WeChatRuntimeError('When using pyinstaller to package exe, you need to add the '
'`--collect-data=ntchat` parameter')
helper_file = get_helper_file(version)
if not os.path.exists(helper_file):
raise WeChatVersionNotMatchError()
raise WeChatRuntimeError("missing core files")
log.info("initialize wechat, version: %s", version)

View File

@ -479,3 +479,13 @@ class WeChat:
"remark": remark
}
return self.__send_sync(send_type.MT_MODIFY_FRIEND_REMARK, data)
def get_room_name(self, room_wxid: str) -> str:
"""
获取群名
"""
sql = f"select nickname from contact where username='{room_wxid}'"
result = self.sql_query(sql, 1)["result"]
if result:
return result[0][0]
return ''

View File

@ -8,3 +8,7 @@ class WeChatBindError(Exception):
class WeChatNotLoginError(Exception):
pass
class WeChatRuntimeError(Exception):
pass

View File

@ -1,6 +1,7 @@
import os
import sys
import os.path
from ntchat.wc import SUPPORT_VERSIONS
def get_exec_dir():
@ -26,9 +27,13 @@ def get_helper_file(version):
return os.path.join(get_wc_dir(), f"helper_{version}.dat")
def get_support_download_url():
return 'https://webcdn.m.qq.com/spcmgr/download/WeChat3.6.0.18.exe'
def has_helper_file():
for name in os.listdir(get_wc_dir()):
if name.startswith("helper_"):
return True
return False
if __name__ == '__main__':
print(get_helper_file('3.6.0.18'))
def is_support_version(version):
return version in SUPPORT_VERSIONS

View File

@ -0,0 +1,3 @@
SUPPORT_VERSIONS = [
'3.6.0.18'
]

View File

@ -194,7 +194,7 @@ extension.extra_compile_cpp_args = extra_compile_cpp_args[target_os]
setup(
name='ntchat',
version='0.1.15',
version='0.1.16',
description='About Conversational RPA SDK for Chatbot Makers',
long_description="",
long_description_content_type='text/markdown',