mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-12 15:20:44 +08:00
跟进 qinglong 通知模块更新
This commit is contained in:
parent
e38bc5bf24
commit
5865885e6a
@ -113,7 +113,6 @@ push_config = {
|
|||||||
'WEBHOOK_METHOD': '', # 自定义通知 请求方法
|
'WEBHOOK_METHOD': '', # 自定义通知 请求方法
|
||||||
'WEBHOOK_CONTENT_TYPE': '' # 自定义通知 content-type
|
'WEBHOOK_CONTENT_TYPE': '' # 自定义通知 content-type
|
||||||
}
|
}
|
||||||
notify_function = []
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
# 首先读取 面板变量 或者 github action 运行变量
|
# 首先读取 面板变量 或者 github action 运行变量
|
||||||
@ -578,7 +577,9 @@ def aibotk(title: str, content: str) -> None:
|
|||||||
or not push_config.get("AIBOTK_TYPE")
|
or not push_config.get("AIBOTK_TYPE")
|
||||||
or not push_config.get("AIBOTK_NAME")
|
or not push_config.get("AIBOTK_NAME")
|
||||||
):
|
):
|
||||||
print("智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送")
|
print(
|
||||||
|
"智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
print("智能微秘书 服务启动")
|
print("智能微秘书 服务启动")
|
||||||
|
|
||||||
@ -748,32 +749,28 @@ def parse_headers(headers):
|
|||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def parse_string(input_string):
|
||||||
|
matches = {}
|
||||||
|
pattern = r"(\w+):\s*((?:(?!\n\w+:).)*)"
|
||||||
|
regex = re.compile(pattern)
|
||||||
|
for match in regex.finditer(input_string):
|
||||||
|
key, value = match.group(1).strip(), match.group(2).strip()
|
||||||
|
try:
|
||||||
|
json_value = json.loads(value)
|
||||||
|
matches[key] = json_value
|
||||||
|
except:
|
||||||
|
matches[key] = value
|
||||||
|
return matches
|
||||||
|
|
||||||
|
|
||||||
def parse_body(body, content_type):
|
def parse_body(body, content_type):
|
||||||
if not body or content_type == "text/plain":
|
if not body or content_type == "text/plain":
|
||||||
return body
|
return body
|
||||||
|
|
||||||
parsed = {}
|
parsed = parse_string(body)
|
||||||
lines = body.split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
i = line.find(":")
|
|
||||||
if i == -1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
key = line[:i].strip()
|
|
||||||
val = line[i + 1 :].strip()
|
|
||||||
|
|
||||||
if not key or key in parsed:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_value = json.loads(val)
|
|
||||||
parsed[key] = json_value
|
|
||||||
except:
|
|
||||||
parsed[key] = val
|
|
||||||
|
|
||||||
if content_type == "application/x-www-form-urlencoded":
|
if content_type == "application/x-www-form-urlencoded":
|
||||||
data = urlencode(parsed, doseq=True)
|
data = urllib.parse.urlencode(parsed, doseq=True)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
if content_type == "application/json":
|
if content_type == "application/json":
|
||||||
@ -842,6 +839,7 @@ def one() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def add_notify_function():
|
def add_notify_function():
|
||||||
|
notify_function = []
|
||||||
if push_config.get("BARK_PUSH"):
|
if push_config.get("BARK_PUSH"):
|
||||||
notify_function.append(bark)
|
notify_function.append(bark)
|
||||||
if push_config.get("CONSOLE"):
|
if push_config.get("CONSOLE"):
|
||||||
@ -897,8 +895,19 @@ def add_notify_function():
|
|||||||
if push_config.get("WEBHOOK_URL") and push_config.get("WEBHOOK_METHOD"):
|
if push_config.get("WEBHOOK_URL") and push_config.get("WEBHOOK_METHOD"):
|
||||||
notify_function.append(custom_notify)
|
notify_function.append(custom_notify)
|
||||||
|
|
||||||
|
if not notify_function:
|
||||||
|
print(f"无推送渠道,请检查通知变量是否正确")
|
||||||
|
return notify_function
|
||||||
|
|
||||||
|
|
||||||
|
def send(title: str, content: str, ignore_default_config: bool = False, **kwargs):
|
||||||
|
if kwargs:
|
||||||
|
global push_config
|
||||||
|
if ignore_default_config:
|
||||||
|
push_config = kwargs # 清空从环境变量获取的配置
|
||||||
|
else:
|
||||||
|
push_config.update(kwargs)
|
||||||
|
|
||||||
def send(title: str, content: str) -> None:
|
|
||||||
if not content:
|
if not content:
|
||||||
print(f"{title} 推送内容为空!")
|
print(f"{title} 推送内容为空!")
|
||||||
return
|
return
|
||||||
@ -913,7 +922,7 @@ def send(title: str, content: str) -> None:
|
|||||||
hitokoto = push_config.get("HITOKOTO")
|
hitokoto = push_config.get("HITOKOTO")
|
||||||
content += "\n\n" + one() if hitokoto else ""
|
content += "\n\n" + one() if hitokoto else ""
|
||||||
|
|
||||||
add_notify_function()
|
notify_function = add_notify_function()
|
||||||
ts = [
|
ts = [
|
||||||
threading.Thread(target=mode, args=(title, content), name=mode.__name__)
|
threading.Thread(target=mode, args=(title, content), name=mode.__name__)
|
||||||
for mode in notify_function
|
for mode in notify_function
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user