增加系统通知、去除注释

This commit is contained in:
child
2023-10-12 13:24:13 +08:00
parent bbac6aba4b
commit cd50156f5d
3 changed files with 130 additions and 94 deletions
+68 -71
View File
@@ -374,7 +374,7 @@ async function sendNotify(
fsBotNotify(text, desp), //飞书机器人
smtpNotify(text, desp), //SMTP 邮件
PushMeNotify(text, desp, params), //PushMe
ChronocatNotify(text, desp) // Chronocat
ChronocatNotify(text, desp), // Chronocat
]);
}
@@ -1192,83 +1192,80 @@ function PushMeNotify(text, desp, params = {}) {
}
function ChronocatNotify(title, desp) {
return new Promise((resolve) => {
// 检查 CHRONOCAT 的配置是否完整
if (!CHRONOCAT_TOKEN || !CHRONOCAT_QQ || !CHRONOCAT_URL) {
console.log("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送");
return;
}
return new Promise((resolve) => {
if (!CHRONOCAT_TOKEN || !CHRONOCAT_QQ || !CHRONOCAT_URL) {
console.log(
'CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送',
);
return;
}
console.log("CHRONOCAT 服务启动");
console.log('CHRONOCAT 服务启动');
const user_ids = CHRONOCAT_QQ.match(/user_id=(\d+)/g)?.map(
(match) => match.split('=')[1],
);
const group_ids = CHRONOCAT_QQ.match(/group_id=(\d+)/g)?.map(
(match) => match.split('=')[1],
);
// 提取 user_id 和 group_id
const user_ids = CHRONOCAT_QQ.match(/user_id=(\d+)/g)?.map(match => match.split("=")[1]);
const group_ids = CHRONOCAT_QQ.match(/group_id=(\d+)/g)?.map(match => match.split("=")[1]);
const url = `${CHRONOCAT_URL}/api/message/send`;
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${CHRONOCAT_TOKEN}`,
};
// 设置请求的 URL 和 Headers
const url = `${CHRONOCAT_URL}/api/message/send`;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${CHRONOCAT_TOKEN}`
for (const [chat_type, ids] of [
[1, user_ids],
[2, group_ids],
]) {
if (!ids) {
continue;
}
for (const chat_id of ids) {
const data = {
peer: {
chatType: chat_type,
peerUin: chat_id,
},
elements: [
{
elementType: 1,
textElement: {
content: `${title}\n\n${desp}`,
},
},
],
};
// 发送消息
for (const [chat_type, ids] of [[1, user_ids], [2, group_ids]]) {
if (!ids) {
continue;
const options = {
url: url,
json: data,
headers,
timeout,
};
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('Chronocat发送QQ通知消息失败!!\n');
console.log(err);
} else {
data = JSON.parse(data);
if (chat_type === 1) {
console.log(`QQ个人消息:${ids}推送成功!`);
} else {
console.log(`QQ群消息:${ids}推送成功!`);
}
}
for (const chat_id of ids) {
const data = {
"peer": {
"chatType": chat_type,
"peerUin": chat_id
},
"elements": [
{
"elementType": 1,
"textElement": {
"content": `${title}\n\n${desp}`
}
}
]
};
const options = {
url: url,
json: data,
headers,
timeout,
};
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('Chronocat发送QQ通知消息失败!!\n');
console.log(err);
} else {
data = JSON.parse(data);
if (chat_type === 1) {
console.log(`QQ个人消息:${ids}推送成功!`);
} else {
console.log(`QQ群消息:${ids}推送成功!`);
}
// if (data.code === 0) {
// console.log('智能微秘书发送通知消息成功🎉。\n');
// } else {
// console.log(`${data.error}\n`);
// }
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
});
}
}
})
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
});
}
}
});
}
module.exports = {
sendNotify,
BARK_PUSH,
-4
View File
@@ -671,7 +671,6 @@ def chronocat(title: str, content: str) -> None:
"""
使用 CHRONOCAT 推送消息。
"""
# 检查 CHRONOCAT 的配置是否完整
if not push_config.get("CHRONOCAT_URL") or not push_config.get("CHRONOCAT_QQ") or not push_config.get(
"CHRONOCAT_TOKEN"):
print("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送")
@@ -679,18 +678,15 @@ def chronocat(title: str, content: str) -> None:
print("CHRONOCAT 服务启动")
# 提取 user_id 和 group_id
user_ids = re.findall(r"user_id=(\d+)", push_config.get("CHRONOCAT_QQ"))
group_ids = re.findall(r"group_id=(\d+)", push_config.get("CHRONOCAT_QQ"))
# 设置请求的 URL 和 Headers
url = f'{push_config.get("CHRONOCAT_URL")}/api/message/send'
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {push_config.get("CHRONOCAT_TOKEN")}'
}
# 发送消息
for chat_type, ids in [(1, user_ids), (2, group_ids)]:
if not ids:
continue