Chronocat发送时没有配置群号或个人消息号发送出错

This commit is contained in:
child 2023-10-11 16:08:39 +08:00
parent 2f32452e75
commit bbac6aba4b

View File

@ -1192,80 +1192,83 @@ function PushMeNotify(text, desp, params = {}) {
} }
function ChronocatNotify(title, desp) { function ChronocatNotify(title, desp) {
// 检查 CHRONOCAT 的配置是否完整 return new Promise((resolve) => {
if (!CHRONOCAT_TOKEN || !CHRONOCAT_QQ || !CHRONOCAT_URL) { // 检查 CHRONOCAT 的配置是否完整
console.log("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送"); if (!CHRONOCAT_TOKEN || !CHRONOCAT_QQ || !CHRONOCAT_URL) {
return; console.log("CHRONOCAT 服务的 CHRONOCAT_URL 或 CHRONOCAT_QQ 未设置!!\n取消推送");
} return;
}
console.log("CHRONOCAT 服务启动"); console.log("CHRONOCAT 服务启动");
// 提取 user_id 和 group_id // 提取 user_id 和 group_id
const user_ids = CHRONOCAT_QQ.match(/user_id=(\d+)/g).map(match => match.split("=")[1]); 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 group_ids = CHRONOCAT_QQ.match(/group_id=(\d+)/g)?.map(match => match.split("=")[1]);
// 设置请求的 URL 和 Headers // 设置请求的 URL 和 Headers
const url = `${CHRONOCAT_URL}/api/message/send`; const url = `${CHRONOCAT_URL}/api/message/send`;
const headers = { const headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': `Bearer ${CHRONOCAT_TOKEN}` 'Authorization': `Bearer ${CHRONOCAT_TOKEN}`
}; };
// 发送消息 // 发送消息
for (const [chat_type, ids] of [[1, user_ids], [2, group_ids]]) { for (const [chat_type, ids] of [[1, user_ids], [2, group_ids]]) {
if (!ids) { if (!ids) {
continue; 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}`
}
}
]
};
const options = {
url: url,
json:JSON.stringify(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);
} }
}); 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);
}
});
}
}
})
} }
module.exports = { module.exports = {
sendNotify, sendNotify,
BARK_PUSH, BARK_PUSH,