From dc251630a46f11d577390eba86c4acdccb716e37 Mon Sep 17 00:00:00 2001 From: Charles <1140601003@qq.com> Date: Thu, 31 Aug 2023 16:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- .vscode/launch.json | 2 +- .vscode/settings.json | 11 +++++++- folder-alias.json | 32 +++++++++++++++++++++++ id.xml | 11 -------- name.session.sql | 0 tempCodeRunnerFile.py | 5 ++++ wechatbot_client/__init__.py | 1 + wechatbot_client/file_manager/manager.py | 11 +++++++- wechatbot_client/startup.py | 3 +++ wechatbot_client/wechat/adapter.py | 2 ++ "\345\244\207\345\277\230\345\275\225.py" | 4 +-- 12 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 folder-alias.json delete mode 100644 id.xml create mode 100644 name.session.sql create mode 100644 tempCodeRunnerFile.py diff --git a/.env b/.env index d25a006..09a4d0f 100644 --- a/.env +++ b/.env @@ -33,7 +33,7 @@ webhook_timeout = 5000 # - Unable 不开启websocket连接 # - Forward 正向websocket连接 # - Backward 反向websocket连接 -websocekt_type = "Unable" +websocekt_type = "Backward" # 反向 WebSocket 连接地址,使用反向websocket时生效 websocket_url = ["ws://127.0.0.1:8080/onebot/v12/ws/"] # 反向 WebSocket 重连间隔,单位:毫秒,必须大于 0 diff --git a/.vscode/launch.json b/.vscode/launch.json index 13a8c98..8ade588 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "Python: 当前文件", "type": "python", "request": "launch", - "program": "${file}", + "program": "${workspaceFolder}/main.py", // 设置为 main.py 的路径 "cwd": "${workspaceFolder}", "console": "integratedTerminal", "justMyCode": false diff --git a/.vscode/settings.json b/.vscode/settings.json index cca67ac..d0421d3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,14 @@ "[python]": { "editor.defaultFormatter": "ms-python.autopep8" }, - "python.formatting.provider": "none" + "python.formatting.provider": "none", + "sqltools.connections": [ + { + "previewLimit": 50, + "driver": "SQLite", + "database": "${workspaceFolder:ComWeChatBotClient2}/data/data.db", + "name": "name" + } + ], + "sqltools.useNodeRuntime": true } \ No newline at end of file diff --git a/folder-alias.json b/folder-alias.json new file mode 100644 index 0000000..9f293f5 --- /dev/null +++ b/folder-alias.json @@ -0,0 +1,32 @@ +{ + "wechatbot_client/action_manager/manager.py": { + "description": "这里发送请求调用com_wechat里面真正实现hook请求" + }, + "wechatbot_client/com_wechat/com_wechat.py": { + "description": "这里是接收信息和实现对微信各种接口,方便调用" + }, + "wechatbot_client/com_wechat/message.py": { + "description": "拿到信息实现onebotv12的协议-----------各种函数调用" + }, + "wechatbot_client/consts.py": { + "description": "定义的全局变量" + }, + "wechatbot_client/config.py": { + "description": "配置env文件" + }, + "wechatbot_client/startup.py": { + "description": "所有任务的启动器" + }, + "wechatbot_client/wechat/adapter.py": { + "description": "拿到已经处理后的onebotv12的信息发送给 websocket连接处理" + }, + "wechatbot_client/wechat/wechat.py": { + "description": "这里调用com_wechat的message处理形成onebov12信息后然后发送给ws端" + }, + "wechatbot_client/driver/driver.py": { + "description": "这里用来连接ws服务" + }, + "wechatbot_client/driver": { + "description": "这个driver不用研究" + } +} \ No newline at end of file diff --git a/id.xml b/id.xml deleted file mode 100644 index d459d53..0000000 --- a/id.xml +++ /dev/null @@ -1,11 +0,0 @@ -{"extrainfo":" -\\n\\t\\n\\t\\t2\\n\\t\\n\\n -\\n\\t1\\n\\t255\\n\\t - v1_OLvB7bI7\\n\\t\\n\\t\\t\\n\\t\\n\\n","filepath":"","isSendMsg":0,"message":" - - -","msgid":1808215118870293793,"pid":184400,"self":"wxid_xq2w7jl6cbi811","sender":"43228505841@chatroom","sign":"d3f4881c234df93f914937a4703ae751","thumb_path":"","time":"2023-08-16 -10:05:57","timestamp":1692151557,"type":47,"wxid":"wxid_ludsalz9bgp322"}\n \ No newline at end of file diff --git a/name.session.sql b/name.session.sql new file mode 100644 index 0000000..e69de29 diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py new file mode 100644 index 0000000..f7f4c9b --- /dev/null +++ b/tempCodeRunnerFile.py @@ -0,0 +1,5 @@ + + + +if __name__ == "__main__": + wechatbot_client.run() \ No newline at end of file diff --git a/wechatbot_client/__init__.py b/wechatbot_client/__init__.py index 5f1aedc..fc3b53e 100644 --- a/wechatbot_client/__init__.py +++ b/wechatbot_client/__init__.py @@ -24,6 +24,7 @@ def init() -> None: logger.debug(f"Loaded Config: {str(config.dict())}") _WeChat = WeChatManager(config) + #这里初始化配置文件 _WeChat.init() diff --git a/wechatbot_client/file_manager/manager.py b/wechatbot_client/file_manager/manager.py index bbe160a..7a099c2 100644 --- a/wechatbot_client/file_manager/manager.py +++ b/wechatbot_client/file_manager/manager.py @@ -5,6 +5,7 @@ from uuid import uuid4 from httpx import URL, AsyncClient +import os from wechatbot_client.consts import DOWNLOAD_TIMEOUT, FILE_CACHE from wechatbot_client.utils import logger_wrapper, run_sync @@ -154,7 +155,15 @@ def clean_tempfile(self, file_paths: list[str]) -> int: file.unlink() count += 1 return count - + async def clear_directory(self,directory_path): + try: + for root, dirs, files in os.walk(directory_path): + for file in files: + file_path = os.path.join(root, file) + os.remove(file_path) + print(f"Contents of directory '{directory_path}' have been cleared.") + except Exception as e: + print(f"Error clearing directory contents '{directory_path}': {e}") async def clean_cache(self, days: int = 3) -> int: """ 说明: diff --git a/wechatbot_client/startup.py b/wechatbot_client/startup.py index bf25f14..dae78dd 100644 --- a/wechatbot_client/startup.py +++ b/wechatbot_client/startup.py @@ -122,3 +122,6 @@ async def clean_filecache(days: int) -> None: logger.info("开始清理文件缓存任务...") nums = await wechat.file_manager.clean_cache(days) logger.success(f"清理缓存完成,共清理 {nums} 个文件...") + directory_to_clear = "file_cache" + await wechat.file_manager.clear_directory(directory_to_clear) + diff --git a/wechatbot_client/wechat/adapter.py b/wechatbot_client/wechat/adapter.py index f27afc2..3ef7b29 100644 --- a/wechatbot_client/wechat/adapter.py +++ b/wechatbot_client/wechat/adapter.py @@ -257,6 +257,8 @@ async def _backward_ws(self, url: URL) -> None: log("ERROR", f"发送connect事件失败:{e}") # 发送update事件 event = self.get_status_update_event() + g = event.json(ensure_ascii=False, cls=DataclassEncoder) + print(g) try: await websocket.send( event.json(ensure_ascii=False, cls=DataclassEncoder) diff --git "a/\345\244\207\345\277\230\345\275\225.py" "b/\345\244\207\345\277\230\345\275\225.py" index 5d14459..20adb1b 100644 --- "a/\345\244\207\345\277\230\345\275\225.py" +++ "b/\345\244\207\345\277\230\345\275\225.py" @@ -1,4 +1,4 @@ -git tag -a v0.0.4 -m "debug" -git push origin v0.0.4 \ No newline at end of file +git tag -a v0.0.6 -m "新增删除文件逻辑" +git push origin v0.0.6 \ No newline at end of file