chore: fix

This commit is contained in:
手瓜一十雪 2024-08-09 19:04:14 +08:00
parent 06d2884a88
commit fedb77e304

View File

@ -67,26 +67,34 @@ export function postWsEvent(event: QuickActionEvent) {
} }
} }
export function postOB11Event(msg: QuickActionEvent, reportSelf = false, postWs = true, coreContext: NapCatCore) { export function postOB11Event(
msg: QuickActionEvent,
reportSelf = false,
postWs = true,
enablePost = true,
httpSecret: string | undefined = undefined,
coreContext: NapCatCore,
HttpPostUrl: string[]
) {
// 判断msg是否是event // 判断msg是否是event
if (!config.reportSelfMessage && !reportSelf) { if (!reportSelf) {
if (msg.post_type === 'message' && (msg as OB11Message).user_id.toString() == coreContext.selfInfo.uin) { if (msg.post_type === 'message' && (msg as OB11Message).user_id.toString() == coreContext.selfInfo.uin) {
return; return;
} }
} }
if (config.http.enablePost) { if (enablePost) {
const msgStr = JSON.stringify(msg); const msgStr = JSON.stringify(msg);
const hmac = crypto.createHmac('sha1', ob11Config.http.secret); const hmac = crypto.createHmac('sha1', (httpSecret || "").toString());
hmac.update(msgStr); hmac.update(msgStr);
const sig = hmac.digest('hex'); const sig = hmac.digest('hex');
const headers: Record<string, string> = { const headers: Record<string, string> = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-self-id': coreContext.selfInfo.uin 'x-self-id': coreContext.selfInfo.uin
}; };
if (config.http.secret) { if (httpSecret) {
headers['x-signature'] = 'sha1=' + sig; headers['x-signature'] = 'sha1=' + sig;
} }
for (const host of config.http.postUrls) { for (const host of HttpPostUrl) {
fetch(host, { fetch(host, {
method: 'POST', method: 'POST',
headers, headers,
@ -134,11 +142,11 @@ async function handleMsg(msg: OB11Message, quickAction: QuickAction, coreContext
peer.peerUid = msg.group_id!.toString(); peer.peerUid = msg.group_id!.toString();
} }
if (reply) { if (reply) {
let group: Group | undefined; let group: string | undefined;
let replyMessage: OB11MessageData[] = []; let replyMessage: OB11MessageData[] = [];
if (msg.message_type == 'group') { if (msg.message_type == 'group') {
group = await getGroup(msg.group_id!.toString()); group = msg.group_id!.toString();
replyMessage.push({ replyMessage.push({
type: 'reply', type: 'reply',
data: { data: {