From 1663c1945d1fc6184f6dd992a8e41db3fb00c4e5 Mon Sep 17 00:00:00 2001 From: Bluemangoo Date: Sun, 5 Jul 2026 18:40:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91nonebot=E5=AF=B9=E9=BD=90=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 6 +++++- lib.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index e7e6f46..d22730c 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ import nonebot -from nonebot import require +from nonebot import require, logger require("nonebot_plugin_apscheduler") @@ -19,6 +19,10 @@ def startup(): rlib.set_proxy(pconfig.proxy) if pconfig.github_token: rlib.set_ghp(pconfig.github_token) + try: + rlib.set_log_level(logger._core.extra.get("nonebot_log_level", "INFO")) + except Exception as e: + logger.error(f"设置日志等级失败: {e}") rlib.boot(str(Path.cwd()), "nonebot_plugin_sekai_update_notify", pconfig.assets_studio_path) scheduler.add_job(sync, "interval", seconds=10, id="sekai_update_sync", replace_existing=True) diff --git a/lib.py b/lib.py index ce2cecc..64bcedc 100644 --- a/lib.py +++ b/lib.py @@ -25,6 +25,7 @@ class FetchData: instance.card_paths = data.get("card_paths", []) return instance + class SekaiSyncLib: def __init__(self): self.lib = ctypes.CDLL(os.path.join(os.path.dirname(__file__), get_lib_filename("sekai_sync_lib"))) @@ -39,6 +40,10 @@ class SekaiSyncLib: self.lib.ghp.argtypes = [ctypes.c_char_p] self.lib.ghp.restype = None + # ghp(x: *const c_char) + self.lib.log_level.argtypes = [ctypes.c_char_p] + self.lib.log_level.restype = None + # boot(cwd: *const c_char, name: *const c_char, as_path: *const c_char) -> c_int self.lib.boot.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p] self.lib.boot.restype = ctypes.c_int @@ -71,6 +76,10 @@ class SekaiSyncLib: """设置 GitHub Token,传 None 或空字符串可清除""" self.lib.ghp(self._str_to_bytes(token)) + def set_log_level(self, log_evel: Optional[str]): + """设置 Log level,传 None 或空字符串可清除""" + self.lib.log_level(self._str_to_bytes(log_evel)) + def boot(self, cwd: str, name: str, as_path: str) -> int: """ 启动主循环与初始化状态 @@ -109,4 +118,5 @@ class SekaiSyncLib: # 4. 无论是否发生 JSON 解析异常,绝对保证释放 Rust 内存! self.lib.free_string(ptr) -rlib = SekaiSyncLib() \ No newline at end of file + +rlib = SekaiSyncLib()