From ef2d20f54c6bd694e7bc7a50e4ab2fec3a903ce2 Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Mon, 8 Apr 2024 21:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E4=BF=AE=E6=94=B9push=5Fconf?= =?UTF-8?q?ig=E5=AE=9E=E7=8E=B0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/notify.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sample/notify.py b/sample/notify.py index d4fffaa3..1bcd35b2 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -113,11 +113,14 @@ push_config = { 'WEBHOOK_METHOD': '', # 自定义通知 请求方法 'WEBHOOK_CONTENT_TYPE': '' # 自定义通知 content-type } + +push_config_keys = tuple(push_config.keys()) # 保存push_config的键 + notify_function = [] # fmt: on # 首先读取 面板变量 或者 github action 运行变量 -for k in push_config: +for k in push_config_keys: if os.getenv(k): v = os.getenv(k) push_config[k] = v @@ -895,8 +898,20 @@ def add_notify_function(): if push_config.get("WEBHOOK_URL") and push_config.get("WEBHOOK_METHOD"): notify_function.append(custom_notify) + if not notify_function: + print(f"无推送渠道,请检查通知变量是否正确") + + +def send(title: str, content: str, ignore_default_config: bool = False, **kwargs): + if ignore_default_config and kwargs: + global push_config + push_config = {} # 清空从环境变量获取的配置 + + if kwargs: + for k in kwargs: + if k in push_config_keys: + push_config[k] = kwargs.get(k) -def send(title: str, content: str) -> None: if not content: print(f"{title} 推送内容为空!") return