From fedb77e304ee711e4695c3c61eab38be5514b8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 9 Aug 2024 19:04:14 +0800 Subject: [PATCH] chore: fix --- src/onebot/server/postOB11Event.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/onebot/server/postOB11Event.ts b/src/onebot/server/postOB11Event.ts index 5a912d86..c89e4932 100644 --- a/src/onebot/server/postOB11Event.ts +++ b/src/onebot/server/postOB11Event.ts @@ -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 - if (!config.reportSelfMessage && !reportSelf) { + if (!reportSelf) { if (msg.post_type === 'message' && (msg as OB11Message).user_id.toString() == coreContext.selfInfo.uin) { return; } } - if (config.http.enablePost) { + if (enablePost) { const msgStr = JSON.stringify(msg); - const hmac = crypto.createHmac('sha1', ob11Config.http.secret); + const hmac = crypto.createHmac('sha1', (httpSecret || "").toString()); hmac.update(msgStr); const sig = hmac.digest('hex'); const headers: Record = { 'Content-Type': 'application/json', 'x-self-id': coreContext.selfInfo.uin }; - if (config.http.secret) { + if (httpSecret) { headers['x-signature'] = 'sha1=' + sig; } - for (const host of config.http.postUrls) { + for (const host of HttpPostUrl) { fetch(host, { method: 'POST', headers, @@ -134,11 +142,11 @@ async function handleMsg(msg: OB11Message, quickAction: QuickAction, coreContext peer.peerUid = msg.group_id!.toString(); } if (reply) { - let group: Group | undefined; + let group: string | undefined; let replyMessage: OB11MessageData[] = []; if (msg.message_type == 'group') { - group = await getGroup(msg.group_id!.toString()); + group = msg.group_id!.toString(); replyMessage.push({ type: 'reply', data: {