diff --git a/README.md b/README.md index de89654..4b4cd56 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## 简介 -WxHook是一个基于dll注入实现的python微信机器人框架,支持多种接口、高扩展性、多线程事件高并发,让你轻松应对海量消息,为你的需求实现提供便捷灵活的支持。 +WxHook是一个基于dll注入实现的python微信机器人框架,支持多种接口、高扩展性、多线程消息处理,让你轻松应对海量消息,为你的需求实现提供便捷灵活的支持。 支持的接口 1. hook同步消息 diff --git a/setup.py b/setup.py index 7de1967..83a22ed 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ URL = 'https://github.com/miloira/wxhook' EMAIL = '690126048@qq.com' AUTHOR = 'Msky' REQUIRES_PYTHON = '>=3.8.0' -VERSION = '0.0.1' +VERSION = '0.0.2' # What packages are required for this module to be executed? REQUIRED = [ diff --git a/wxhook/__init__.py b/wxhook/__init__.py index 284c3dd..9c5f821 100644 --- a/wxhook/__init__.py +++ b/wxhook/__init__.py @@ -1,3 +1,3 @@ from .core import Bot -version = "0.0.1" +version = "0.0.2" diff --git a/wxhook/core.py b/wxhook/core.py index f1e393c..7ed1fdf 100644 --- a/wxhook/core.py +++ b/wxhook/core.py @@ -1,12 +1,12 @@ import os import json import typing +import traceback +import socketserver +from functools import lru_cache import psutil import pyee -import traceback -import socketserver - import requests from .events import ALL_MESSAGE, SYSTEM_MESSAGE @@ -62,8 +62,8 @@ class Bot: self.remote_port, self.server_port = self.wechat_manager.get_port() self.BASE_URL = f"http://{self.remote_host}:{self.remote_port}" self.webhook_url = None - self.info = None self.DATA_SAVE_PATH = None + self.WXHELPER_PATH = None self.FILE_SAVE_PATH = None self.IMAGE_SAVE_PATH = None self.VIDEO_SAVE_PATH = None @@ -93,12 +93,11 @@ class Bot: def init_bot(self, bot: "Bot", event: Event) -> None: if event.content["sysmsg"]["@type"] == "SafeModuleCfg": - bot.info = bot.get_self_info() self.DATA_SAVE_PATH = bot.info.dataSavePath - self.FILE_SAVE_PATH = os.path.join(self.DATA_SAVE_PATH, "wxhelper/file") - self.IMAGE_SAVE_PATH = os.path.join(self.DATA_SAVE_PATH, "wxhelper/image") - self.VIDEO_SAVE_PATH = os.path.join(self.DATA_SAVE_PATH, "wxhelper/video") - logger.info(bot.info) + self.WXHELPER_PATH = os.path.join(self.DATA_SAVE_PATH, "wxhelper") + self.FILE_SAVE_PATH = os.path.join(self.WXHELPER_PATH, "file") + self.IMAGE_SAVE_PATH = os.path.join(self.WXHELPER_PATH, "image") + self.VIDEO_SAVE_PATH = os.path.join(self.WXHELPER_PATH, "video") self.call_hook_func(self.on_login, bot) def set_webhook_url(self, webhook_url: str) -> None: @@ -115,12 +114,12 @@ class Bot: return requests.request("POST", self.BASE_URL + api, *args, **kwargs).json() def hook_sync_msg( - self, - ip: str, - port: int, - enable_http: int = 0, - url: str = "http://127.0.0.1:8000", - timeout: int = 30 + self, + ip: str, + port: int, + enable_http: int = 0, + url: str = "http://127.0.0.1:8000", + timeout: int = 30 ) -> Response: """hook同步消息""" data = { @@ -148,6 +147,7 @@ class Bot: """检查登录状态""" return Response(**self.call_api("/api/checkLogin")) + @lru_cache def get_self_info(self) -> Account: """获取用户信息""" return Account(**self.call_api("/api/userInfo")["data"]) @@ -234,7 +234,7 @@ class Bot: data = { "wxid": wxid } - return ContactDetail(self.call_api("/api/getContactProfile", json=data)["data"]) + return ContactDetail(**self.call_api("/api/getContactProfile", json=data)["data"]) def create_room(self, member_ids: list[str]) -> Response: """创建群聊""" @@ -423,6 +423,10 @@ class Bot: """测试""" return Response(**self.call_api("/api/test")) + @property + def info(self) -> Account: + return self.get_self_info() + def on_event(self, raw_data: bytes): try: data = json.loads(raw_data)