修改通知文件未设置变量提示

This commit is contained in:
whyour 2024-12-22 22:15:09 +08:00
parent bdc45c538c
commit 75f91e1473
2 changed files with 83 additions and 83 deletions

View File

@ -43,12 +43,11 @@ const push_config = {
// 官方文档https://www.pushplus.plus/ // 官方文档https://www.pushplus.plus/
PUSH_PLUS_TOKEN: '', // pushplus 推送的用户令牌 PUSH_PLUS_TOKEN: '', // pushplus 推送的用户令牌
PUSH_PLUS_USER: '', // pushplus 推送的群组编码 PUSH_PLUS_USER: '', // pushplus 推送的群组编码
PUSH_PLUS_TEMPLATE: 'html', // pushplus 发送模板支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay PUSH_PLUS_TEMPLATE: 'html', // pushplus 发送模板支持html,txt,json,markdown,cloudMonitor,jenkins,route,pay
PUSH_PLUS_CHANNEL: 'wechat', // pushplus 发送渠道支持wechat,webhook,cp,mail,sms PUSH_PLUS_CHANNEL: 'wechat', // pushplus 发送渠道支持wechat,webhook,cp,mail,sms
PUSH_PLUS_WEBHOOK: '', // pushplus webhook编码可在pushplus公众号上扩展配置出更多渠道 PUSH_PLUS_WEBHOOK: '', // pushplus webhook编码可在pushplus公众号上扩展配置出更多渠道
PUSH_PLUS_CALLBACKURL: '', // pushplus 发送结果回调地址,会把推送最终结果通知到这个地址上 PUSH_PLUS_CALLBACKURL: '', // pushplus 发送结果回调地址,会把推送最终结果通知到这个地址上
PUSH_PLUS_TO: '', // pushplus 好友令牌微信公众号渠道填写好友令牌企业微信渠道填写企业微信用户id PUSH_PLUS_TO: '', // pushplus 好友令牌微信公众号渠道填写好友令牌企业微信渠道填写企业微信用户id
// 微加机器人官方网站https://www.weplusbot.com/ // 微加机器人官方网站https://www.weplusbot.com/
WE_PLUS_BOT_TOKEN: '', // 微加机器人的用户令牌 WE_PLUS_BOT_TOKEN: '', // 微加机器人的用户令牌
@ -243,10 +242,13 @@ function serverNotify(text, desp) {
const matchResult = PUSH_KEY.match(/^sctp(\d+)t/i); const matchResult = PUSH_KEY.match(/^sctp(\d+)t/i);
const options = { const options = {
url: matchResult && matchResult[1] url:
? `https://${matchResult[1]}.push.ft07.com/send/${PUSH_KEY}.send` matchResult && matchResult[1]
: `https://sctapi.ftqq.com/${PUSH_KEY}.send`, ? `https://${matchResult[1]}.push.ft07.com/send/${PUSH_KEY}.send`
body: `text=${encodeURIComponent(text)}&desp=${encodeURIComponent(desp)}`, : `https://sctapi.ftqq.com/${PUSH_KEY}.send`,
body: `text=${encodeURIComponent(text)}&desp=${encodeURIComponent(
desp,
)}`,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, },
@ -777,7 +779,15 @@ function iGotNotify(text, desp, params = {}) {
function pushPlusNotify(text, desp) { function pushPlusNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { PUSH_PLUS_TOKEN, PUSH_PLUS_USER, PUSH_PLUS_TEMPLATE, PUSH_PLUS_CHANNEL, PUSH_PLUS_WEBHOOK, PUSH_PLUS_CALLBACKURL, PUSH_PLUS_TO } = push_config; const {
PUSH_PLUS_TOKEN,
PUSH_PLUS_USER,
PUSH_PLUS_TEMPLATE,
PUSH_PLUS_CHANNEL,
PUSH_PLUS_WEBHOOK,
PUSH_PLUS_CALLBACKURL,
PUSH_PLUS_TO,
} = push_config;
if (PUSH_PLUS_TOKEN) { if (PUSH_PLUS_TOKEN) {
desp = desp.replace(/[\n\r]/g, '<br>'); // 默认为html, 不支持plaintext desp = desp.replace(/[\n\r]/g, '<br>'); // 默认为html, 不支持plaintext
const body = { const body = {
@ -789,7 +799,7 @@ function pushPlusNotify(text, desp) {
channel: `${PUSH_PLUS_CHANNEL}`, channel: `${PUSH_PLUS_CHANNEL}`,
webhook: `${PUSH_PLUS_WEBHOOK}`, webhook: `${PUSH_PLUS_WEBHOOK}`,
callbackUrl: `${PUSH_PLUS_CALLBACKURL}`, callbackUrl: `${PUSH_PLUS_CALLBACKURL}`,
to: `${PUSH_PLUS_TO}` to: `${PUSH_PLUS_TO}`,
}; };
const options = { const options = {
url: `https://www.pushplus.plus/send`, url: `https://www.pushplus.plus/send`,
@ -813,7 +823,9 @@ function pushPlusNotify(text, desp) {
console.log( console.log(
`pushplus 发送${ `pushplus 发送${
PUSH_PLUS_USER ? '一对多' : '一对一' PUSH_PLUS_USER ? '一对多' : '一对一'
}通知请求成功🎉可根据流水号查询推送结果${data.data}\n注意请求成功并不代表推送成功如未收到消息请到pushplus官网使用流水号查询推送最终结果`, }通知请求成功🎉可根据流水号查询推送结果${
data.data
}\n注意请求成功并不代表推送成功如未收到消息请到pushplus官网使用流水号查询推送最终结果`,
); );
} else { } else {
console.log( console.log(
@ -1222,10 +1234,10 @@ function ntfyNotify(text, desp) {
if (NTFY_TOPIC) { if (NTFY_TOPIC) {
const options = { const options = {
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`, url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
body: `${desp}`, body: `${desp}`,
headers: { headers: {
'Title': `${encodeRFC2047(text)}`, Title: `${encodeRFC2047(text)}`,
'Priority': NTFY_PRIORITY || '3' Priority: NTFY_PRIORITY || '3',
}, },
timeout, timeout,
}; };
@ -1254,22 +1266,29 @@ function ntfyNotify(text, desp) {
function wxPusherNotify(text, desp) { function wxPusherNotify(text, desp) {
return new Promise((resolve) => { return new Promise((resolve) => {
const { WXPUSHER_APP_TOKEN, WXPUSHER_TOPIC_IDS, WXPUSHER_UIDS } = push_config; const { WXPUSHER_APP_TOKEN, WXPUSHER_TOPIC_IDS, WXPUSHER_UIDS } =
push_config;
if (WXPUSHER_APP_TOKEN) { if (WXPUSHER_APP_TOKEN) {
// 处理topic_ids将分号分隔的字符串转为数组 // 处理topic_ids将分号分隔的字符串转为数组
const topicIds = WXPUSHER_TOPIC_IDS ? WXPUSHER_TOPIC_IDS.split(';') const topicIds = WXPUSHER_TOPIC_IDS
.map(id => id.trim()) ? WXPUSHER_TOPIC_IDS.split(';')
.filter(id => id) .map((id) => id.trim())
.map(id => parseInt(id)) : []; .filter((id) => id)
.map((id) => parseInt(id))
: [];
// 处理uids将分号分隔的字符串转为数组 // 处理uids将分号分隔的字符串转为数组
const uids = WXPUSHER_UIDS ? WXPUSHER_UIDS.split(';') const uids = WXPUSHER_UIDS
.map(uid => uid.trim()) ? WXPUSHER_UIDS.split(';')
.filter(uid => uid) : []; .map((uid) => uid.trim())
.filter((uid) => uid)
: [];
// topic_ids uids 至少有一个 // topic_ids uids 至少有一个
if (!topicIds.length && !uids.length) { if (!topicIds.length && !uids.length) {
console.log("wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!\n取消推送"); console.log(
'wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!',
);
return resolve(); return resolve();
} }
@ -1280,16 +1299,16 @@ function wxPusherNotify(text, desp) {
contentType: 2, contentType: 2,
topicIds: topicIds, topicIds: topicIds,
uids: uids, uids: uids,
verifyPayType: 0 verifyPayType: 0,
}; };
const options = { const options = {
url: 'https://wxpusher.zjiecode.com/api/send/message', url: 'https://wxpusher.zjiecode.com/api/send/message',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
}, },
timeout timeout,
}; };
$.post(options, (err, resp, data) => { $.post(options, (err, resp, data) => {
@ -1310,13 +1329,11 @@ function wxPusherNotify(text, desp) {
} }
}); });
} else { } else {
console.log('wxpusher 服务的 WXPUSHER_APP_TOKEN 未设置!!\n取消推送');
resolve(); resolve();
} }
}); });
} }
function parseString(input, valueFormatFn) { function parseString(input, valueFormatFn) {
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g; const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
const matches = {}; const matches = {};

View File

@ -144,7 +144,6 @@ def bark(title: str, content: str) -> None:
使用 bark 推送消息 使用 bark 推送消息
""" """
if not push_config.get("BARK_PUSH"): if not push_config.get("BARK_PUSH"):
print("bark 服务的 BARK_PUSH 未设置!!\n取消推送")
return return
print("bark 服务启动") print("bark 服务启动")
@ -196,7 +195,6 @@ def dingding_bot(title: str, content: str) -> None:
使用 钉钉机器人 推送消息 使用 钉钉机器人 推送消息
""" """
if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"): if not push_config.get("DD_BOT_SECRET") or not push_config.get("DD_BOT_TOKEN"):
print("钉钉机器人 服务的 DD_BOT_SECRET 或者 DD_BOT_TOKEN 未设置!!\n取消推送")
return return
print("钉钉机器人 服务启动") print("钉钉机器人 服务启动")
@ -226,7 +224,6 @@ def feishu_bot(title: str, content: str) -> None:
使用 飞书机器人 推送消息 使用 飞书机器人 推送消息
""" """
if not push_config.get("FSKEY"): if not push_config.get("FSKEY"):
print("飞书 服务的 FSKEY 未设置!!\n取消推送")
return return
print("飞书 服务启动") print("飞书 服务启动")
@ -245,7 +242,6 @@ def go_cqhttp(title: str, content: str) -> None:
使用 go_cqhttp 推送消息 使用 go_cqhttp 推送消息
""" """
if not push_config.get("GOBOT_URL") or not push_config.get("GOBOT_QQ"): if not push_config.get("GOBOT_URL") or not push_config.get("GOBOT_QQ"):
print("go-cqhttp 服务的 GOBOT_URL 或 GOBOT_QQ 未设置!!\n取消推送")
return return
print("go-cqhttp 服务启动") print("go-cqhttp 服务启动")
@ -263,7 +259,6 @@ def gotify(title: str, content: str) -> None:
使用 gotify 推送消息 使用 gotify 推送消息
""" """
if not push_config.get("GOTIFY_URL") or not push_config.get("GOTIFY_TOKEN"): if not push_config.get("GOTIFY_URL") or not push_config.get("GOTIFY_TOKEN"):
print("gotify 服务的 GOTIFY_URL 或 GOTIFY_TOKEN 未设置!!\n取消推送")
return return
print("gotify 服务启动") print("gotify 服务启动")
@ -286,7 +281,6 @@ def iGot(title: str, content: str) -> None:
使用 iGot 推送消息 使用 iGot 推送消息
""" """
if not push_config.get("IGOT_PUSH_KEY"): if not push_config.get("IGOT_PUSH_KEY"):
print("iGot 服务的 IGOT_PUSH_KEY 未设置!!\n取消推送")
return return
print("iGot 服务启动") print("iGot 服务启动")
@ -306,13 +300,12 @@ def serverJ(title: str, content: str) -> None:
通过 serverJ 推送消息 通过 serverJ 推送消息
""" """
if not push_config.get("PUSH_KEY"): if not push_config.get("PUSH_KEY"):
print("serverJ 服务的 PUSH_KEY 未设置!!\n取消推送")
return return
print("serverJ 服务启动") print("serverJ 服务启动")
data = {"text": title, "desp": content.replace("\n", "\n\n")} data = {"text": title, "desp": content.replace("\n", "\n\n")}
match = re.match(r'sctp(\d+)t', push_config.get("PUSH_KEY")) match = re.match(r"sctp(\d+)t", push_config.get("PUSH_KEY"))
if match: if match:
num = match.group(1) num = match.group(1)
url = f'https://{num}.push.ft07.com/send/{push_config.get("PUSH_KEY")}.send' url = f'https://{num}.push.ft07.com/send/{push_config.get("PUSH_KEY")}.send'
@ -332,7 +325,6 @@ def pushdeer(title: str, content: str) -> None:
通过PushDeer 推送消息 通过PushDeer 推送消息
""" """
if not push_config.get("DEER_KEY"): if not push_config.get("DEER_KEY"):
print("PushDeer 服务的 DEER_KEY 未设置!!\n取消推送")
return return
print("PushDeer 服务启动") print("PushDeer 服务启动")
data = { data = {
@ -358,7 +350,6 @@ def chat(title: str, content: str) -> None:
通过Chat 推送消息 通过Chat 推送消息
""" """
if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"): if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"):
print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送")
return return
print("chat 服务启动") print("chat 服务启动")
data = "payload=" + json.dumps({"text": title + "\n" + content}) data = "payload=" + json.dumps({"text": title + "\n" + content})
@ -376,7 +367,6 @@ def pushplus_bot(title: str, content: str) -> None:
通过 pushplus 推送消息 通过 pushplus 推送消息
""" """
if not push_config.get("PUSH_PLUS_TOKEN"): if not push_config.get("PUSH_PLUS_TOKEN"):
print("PUSHPLUS 服务的 PUSH_PLUS_TOKEN 未设置!!\n取消推送")
return return
print("PUSHPLUS 服务启动") print("PUSHPLUS 服务启动")
@ -390,7 +380,7 @@ def pushplus_bot(title: str, content: str) -> None:
"channel": push_config.get("PUSH_PLUS_CHANNEL"), "channel": push_config.get("PUSH_PLUS_CHANNEL"),
"webhook": push_config.get("PUSH_PLUS_WEBHOOK"), "webhook": push_config.get("PUSH_PLUS_WEBHOOK"),
"callbackUrl": push_config.get("PUSH_PLUS_CALLBACKURL"), "callbackUrl": push_config.get("PUSH_PLUS_CALLBACKURL"),
"to": push_config.get("PUSH_PLUS_TO") "to": push_config.get("PUSH_PLUS_TO"),
} }
body = json.dumps(data).encode(encoding="utf-8") body = json.dumps(data).encode(encoding="utf-8")
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
@ -398,9 +388,11 @@ def pushplus_bot(title: str, content: str) -> None:
code = response["code"] code = response["code"]
if code == 200: if code == 200:
print("PUSHPLUS 推送请求成功,可根据流水号查询推送结果:"+ response["data"]) print("PUSHPLUS 推送请求成功,可根据流水号查询推送结果:" + response["data"])
print("注意请求成功并不代表推送成功如未收到消息请到pushplus官网使用流水号查询推送最终结果") print(
elif code == 900 or code == 903 or code == 905 or code == 999 : "注意请求成功并不代表推送成功如未收到消息请到pushplus官网使用流水号查询推送最终结果"
)
elif code == 900 or code == 903 or code == 905 or code == 999:
print(response["msg"]) print(response["msg"])
else: else:
@ -420,7 +412,6 @@ def weplus_bot(title: str, content: str) -> None:
通过 微加机器人 推送消息 通过 微加机器人 推送消息
""" """
if not push_config.get("WE_PLUS_BOT_TOKEN"): if not push_config.get("WE_PLUS_BOT_TOKEN"):
print("微加机器人 服务的 WE_PLUS_BOT_TOKEN 未设置!!\n取消推送")
return return
print("微加机器人 服务启动") print("微加机器人 服务启动")
@ -452,7 +443,6 @@ def qmsg_bot(title: str, content: str) -> None:
使用 qmsg 推送消息 使用 qmsg 推送消息
""" """
if not push_config.get("QMSG_KEY") or not push_config.get("QMSG_TYPE"): if not push_config.get("QMSG_KEY") or not push_config.get("QMSG_TYPE"):
print("qmsg 的 QMSG_KEY 或者 QMSG_TYPE 未设置!!\n取消推送")
return return
print("qmsg 服务启动") print("qmsg 服务启动")
@ -471,11 +461,10 @@ def wecom_app(title: str, content: str) -> None:
通过 企业微信 APP 推送消息 通过 企业微信 APP 推送消息
""" """
if not push_config.get("QYWX_AM"): if not push_config.get("QYWX_AM"):
print("QYWX_AM 未设置!!\n取消推送")
return return
QYWX_AM_AY = re.split(",", push_config.get("QYWX_AM")) QYWX_AM_AY = re.split(",", push_config.get("QYWX_AM"))
if 4 < len(QYWX_AM_AY) > 5: if 4 < len(QYWX_AM_AY) > 5:
print("QYWX_AM 设置错误!!\n取消推送") print("QYWX_AM 设置错误!!")
return return
print("企业微信 APP 服务启动") print("企业微信 APP 服务启动")
@ -568,7 +557,6 @@ def wecom_bot(title: str, content: str) -> None:
通过 企业微信机器人 推送消息 通过 企业微信机器人 推送消息
""" """
if not push_config.get("QYWX_KEY"): if not push_config.get("QYWX_KEY"):
print("企业微信机器人 服务的 QYWX_KEY 未设置!!\n取消推送")
return return
print("企业微信机器人服务启动") print("企业微信机器人服务启动")
@ -594,7 +582,6 @@ def telegram_bot(title: str, content: str) -> None:
使用 telegram 机器人 推送消息 使用 telegram 机器人 推送消息
""" """
if not push_config.get("TG_BOT_TOKEN") or not push_config.get("TG_USER_ID"): if not push_config.get("TG_BOT_TOKEN") or not push_config.get("TG_USER_ID"):
print("tg 服务的 bot_token 或者 user_id 未设置!!\n取消推送")
return return
print("tg 服务启动") print("tg 服务启动")
@ -643,9 +630,6 @@ 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取消推送"
)
return return
print("智能微秘书 服务启动") print("智能微秘书 服务启动")
@ -684,9 +668,6 @@ def smtp(title: str, content: str) -> None:
or not push_config.get("SMTP_PASSWORD") or not push_config.get("SMTP_PASSWORD")
or not push_config.get("SMTP_NAME") or not push_config.get("SMTP_NAME")
): ):
print(
"SMTP 邮件 的 SMTP_SERVER 或者 SMTP_SSL 或者 SMTP_EMAIL 或者 SMTP_PASSWORD 或者 SMTP_NAME 未设置!!\n取消推送"
)
return return
print("SMTP 邮件 服务启动") print("SMTP 邮件 服务启动")
@ -730,7 +711,6 @@ def pushme(title: str, content: str) -> None:
使用 PushMe 推送消息 使用 PushMe 推送消息
""" """
if not push_config.get("PUSHME_KEY"): if not push_config.get("PUSHME_KEY"):
print("PushMe 服务的 PUSHME_KEY 未设置!!\n取消推送")
return return
print("PushMe 服务启动") print("PushMe 服务启动")
@ -763,7 +743,6 @@ def chronocat(title: str, content: str) -> None:
or not push_config.get("CHRONOCAT_QQ") or not push_config.get("CHRONOCAT_QQ")
or not push_config.get("CHRONOCAT_TOKEN") or not push_config.get("CHRONOCAT_TOKEN")
): ):
print("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送")
return return
print("CHRONOCAT 服务启动") print("CHRONOCAT 服务启动")
@ -807,31 +786,28 @@ def ntfy(title: str, content: str) -> None:
""" """
通过 Ntfy 推送消息 通过 Ntfy 推送消息
""" """
def encode_rfc2047(text: str) -> str: def encode_rfc2047(text: str) -> str:
"""将文本编码为符合 RFC 2047 标准的格式""" """将文本编码为符合 RFC 2047 标准的格式"""
encoded_bytes = base64.b64encode(text.encode('utf-8')) encoded_bytes = base64.b64encode(text.encode("utf-8"))
encoded_str = encoded_bytes.decode('utf-8') encoded_str = encoded_bytes.decode("utf-8")
return f'=?utf-8?B?{encoded_str}?=' return f"=?utf-8?B?{encoded_str}?="
if not push_config.get("NTFY_TOPIC"): if not push_config.get("NTFY_TOPIC"):
print("ntfy 服务的 NTFY_TOPIC 未设置!!\n取消推送")
return return
print("ntfy 服务启动") print("ntfy 服务启动")
priority = '3' priority = "3"
if not push_config.get("NTFY_PRIORITY"): if not push_config.get("NTFY_PRIORITY"):
print("ntfy 服务的NTFY_PRIORITY 未设置!!默认设置为3") print("ntfy 服务的NTFY_PRIORITY 未设置!!默认设置为3")
else: else:
priority = push_config.get("NTFY_PRIORITY") priority = push_config.get("NTFY_PRIORITY")
# 使用 RFC 2047 编码 title # 使用 RFC 2047 编码 title
encoded_title = encode_rfc2047(title) encoded_title = encode_rfc2047(title)
data = content.encode(encoding='utf-8') data = content.encode(encoding="utf-8")
headers = { headers = {"Title": encoded_title, "Priority": priority} # 使用编码后的 title
"Title": encoded_title, # 使用编码后的 title
"Priority": priority
}
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC") url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
response = requests.post(url, data=data, headers=headers) response = requests.post(url, data=data, headers=headers)
if response.status_code == 200: # 使用 response.status_code 进行检查 if response.status_code == 200: # 使用 response.status_code 进行检查
@ -849,24 +825,30 @@ def wxpusher_bot(title: str, content: str) -> None:
- WXPUSHER_UIDS: 用户ID, 多个用英文分号;分隔 - WXPUSHER_UIDS: 用户ID, 多个用英文分号;分隔
""" """
if not push_config.get("WXPUSHER_APP_TOKEN"): if not push_config.get("WXPUSHER_APP_TOKEN"):
print("wxpusher 服务的 WXPUSHER_APP_TOKEN 未设置!!\n取消推送")
return return
url = "https://wxpusher.zjiecode.com/api/send/message" url = "https://wxpusher.zjiecode.com/api/send/message"
# 处理topic_ids和uids将分号分隔的字符串转为数组 # 处理topic_ids和uids将分号分隔的字符串转为数组
topic_ids = [] topic_ids = []
if push_config.get("WXPUSHER_TOPIC_IDS"): if push_config.get("WXPUSHER_TOPIC_IDS"):
topic_ids = [int(id.strip()) for id in push_config.get("WXPUSHER_TOPIC_IDS").split(";") if id.strip()] topic_ids = [
int(id.strip())
for id in push_config.get("WXPUSHER_TOPIC_IDS").split(";")
if id.strip()
]
uids = [] uids = []
if push_config.get("WXPUSHER_UIDS"): if push_config.get("WXPUSHER_UIDS"):
uids = [uid.strip() for uid in push_config.get("WXPUSHER_UIDS").split(";") if uid.strip()] uids = [
uid.strip()
for uid in push_config.get("WXPUSHER_UIDS").split(";")
if uid.strip()
]
# topic_ids uids 至少有一个 # topic_ids uids 至少有一个
if not topic_ids and not uids: if not topic_ids and not uids:
print("wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!\n取消推送") print("wxpusher 服务的 WXPUSHER_TOPIC_IDS 和 WXPUSHER_UIDS 至少设置一个!!")
return return
print("wxpusher 服务启动") print("wxpusher 服务启动")
@ -878,9 +860,9 @@ def wxpusher_bot(title: str, content: str) -> None:
"contentType": 2, "contentType": 2,
"topicIds": topic_ids, "topicIds": topic_ids,
"uids": uids, "uids": uids,
"verifyPayType": 0 "verifyPayType": 0,
} }
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
response = requests.post(url=url, json=data, headers=headers).json() response = requests.post(url=url, json=data, headers=headers).json()
@ -946,7 +928,6 @@ def custom_notify(title: str, content: str) -> None:
通过 自定义通知 推送消息 通过 自定义通知 推送消息
""" """
if not push_config.get("WEBHOOK_URL") or not push_config.get("WEBHOOK_METHOD"): if not push_config.get("WEBHOOK_URL") or not push_config.get("WEBHOOK_METHOD"):
print("自定义通知的 WEBHOOK_URL 或 WEBHOOK_METHOD 未设置!!\n取消推送")
return return
print("自定义通知服务启动") print("自定义通知服务启动")
@ -1052,7 +1033,9 @@ def add_notify_function():
notify_function.append(custom_notify) notify_function.append(custom_notify)
if push_config.get("NTFY_TOPIC"): if push_config.get("NTFY_TOPIC"):
notify_function.append(ntfy) notify_function.append(ntfy)
if push_config.get("WXPUSHER_APP_TOKEN") and (push_config.get("WXPUSHER_TOPIC_IDS") or push_config.get("WXPUSHER_UIDS")): if push_config.get("WXPUSHER_APP_TOKEN") and (
push_config.get("WXPUSHER_TOPIC_IDS") or push_config.get("WXPUSHER_UIDS")
):
notify_function.append(wxpusher_bot) notify_function.append(wxpusher_bot)
if not notify_function: if not notify_function:
print(f"无推送渠道,请检查通知变量是否正确") print(f"无推送渠道,请检查通知变量是否正确")
@ -1095,4 +1078,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()