diff --git a/sample/notify.py b/sample/notify.py index 1bcd35b2..2a595308 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -113,14 +113,10 @@ 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_keys: +for k in push_config: if os.getenv(k): v = os.getenv(k) push_config[k] = v @@ -771,10 +767,10 @@ def parse_body(body, content_type): if not body or content_type == "text/plain": return body - parsed = parse_string(input_string) + parsed = parse_string(body) if content_type == "application/x-www-form-urlencoded": - data = urlencode(parsed, doseq=True) + data = urllib.parse.urlencode(parsed, doseq=True) return data if content_type == "application/json": @@ -843,6 +839,7 @@ def one() -> str: def add_notify_function(): + notify_function = [] if push_config.get("BARK_PUSH"): notify_function.append(bark) if push_config.get("CONSOLE"): @@ -900,17 +897,16 @@ def add_notify_function(): if not notify_function: print(f"无推送渠道,请检查通知变量是否正确") + return notify_function 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) + global push_config + if ignore_default_config: + push_config = kwargs # 清空从环境变量获取的配置 + else: + push_config.update(kwargs) if not content: print(f"{title} 推送内容为空!") @@ -926,7 +922,7 @@ def send(title: str, content: str, ignore_default_config: bool = False, **kwargs hitokoto = push_config.get("HITOKOTO") content += "\n\n" + one() if hitokoto else "" - add_notify_function() + notify_function = add_notify_function() ts = [ threading.Thread(target=mode, args=(title, content), name=mode.__name__) for mode in notify_function