From 600ac123e001af222890f00c349a1e62003f96d6 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: Tue, 16 Apr 2024 14:10:31 +0800 Subject: [PATCH 1/7] limit:workflow --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5663385c..4ff73003 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,8 @@ name: "Build" on: push: + branches: + - main jobs: build-linux: From 1ed5dc6a1f66e8a05c1df4c43a2061c8822d84f9 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: Tue, 16 Apr 2024 14:13:22 +0800 Subject: [PATCH 2/7] Revert "chore:version change" This reverts commit 37923d6f2536c2a646664cd21d69a5f8201cfac8. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2cf6ccf9..cdc6e7e0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "1.0.3", + "version": "1.0.2", "scripts": { "watch:dev": "vite --mode development", "watch:prod": "vite --mode production", From d8faa7e303151827fad57f691a068a2309c6a65d 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: Tue, 16 Apr 2024 18:26:50 +0800 Subject: [PATCH 3/7] fix --- .../action/go-cqhttp/GetFriendMsgHistory.ts | 52 +++++++++++++++++++ src/onebot11/action/index.ts | 3 +- src/onebot11/action/types.ts | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts new file mode 100644 index 00000000..cb51ca33 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -0,0 +1,52 @@ +import BaseAction from '../BaseAction'; +import { OB11Message, OB11User } from '../../types'; +import { getFriend, friends, uid2UinMap } from '@/common/data'; +import { ActionName } from '../types'; +import { ChatType } from '@/core/qqnt/entities'; +import { dbUtil } from '@/common/utils/db'; +import { NTQQMsgApi } from '@/core/qqnt/apis/msg'; +import { OB11Constructor } from '../../constructor'; + + +interface Payload { + user_id: number + message_seq: number, + count: number +} + +interface Response { + messages: OB11Message[]; +} + +export default class GetFriendMsgHistory extends BaseAction { + actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; + protected async _handle(payload: Payload): Promise { + if (!uid2UinMap?.[payload.user_id]) { + throw `记录${payload.user_id}不存在`; + } + const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0'; + // log("startMsgId", startMsgId) + + let friend = await getFriend(uid2UinMap?.[payload.user_id].toString()) + let historyResult = undefined; + if (friend) { + historyResult = (await NTQQMsgApi.getMsgHistory({ + chatType: ChatType.friend, + peerUid: uid2UinMap?.[payload.user_id] + }, startMsgId, parseInt(payload.count?.toString()) || 20)); + + } else { + historyResult = (await NTQQMsgApi.getMsgHistory({ + chatType: ChatType.temp, + peerUid: uid2UinMap?.[payload.user_id] + }, startMsgId, parseInt(payload.count?.toString()) || 20)); + } + console.log(historyResult); + const msgList = historyResult.msgList; + await Promise.all(msgList.map(async msg => { + msg.id = await dbUtil.addMsg(msg); + })); + const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg))); + return { 'messages': ob11MsgList }; + } +} diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 0fac5dba..76807e18 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -44,6 +44,7 @@ import GoCQHTTPDownloadFile from './go-cqhttp/DownloadFile'; import GoCQHTTPGetGroupMsgHistory from './go-cqhttp/GetGroupMsgHistory'; import GetFile from './file/GetFile'; import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg'; +import GetFriendMsgHistory from './go-cqhttp/GetFriendMsgHistory'; export const actionHandlers = [ new GetFile(), @@ -89,7 +90,7 @@ export const actionHandlers = [ new GoCQHTTPUploadGroupFile(), new GoCQHTTPGetGroupMsgHistory(), new GoCQHTTGetForwardMsgAction(), - + new GetFriendMsgHistory() ]; function initActionMap() { diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 8fb5df7d..ca4beb0e 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -61,4 +61,5 @@ export enum ActionName { GoCQHTTP_DownloadFile = 'download_file', GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history', GoCQHTTP_GetForwardMsg = 'get_forward_msg', + GetFriendMsgHistory = 'get_friend_msg_history' } \ No newline at end of file From 6722da761fd7a51f65fcfbeefd51f541761c96fd 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: Tue, 16 Apr 2024 18:32:02 +0800 Subject: [PATCH 4/7] fix --- .../action/go-cqhttp/GetFriendMsgHistory.ts | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index cb51ca33..6fae23d3 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -1,6 +1,6 @@ import BaseAction from '../BaseAction'; import { OB11Message, OB11User } from '../../types'; -import { getFriend, friends, uid2UinMap } from '@/common/data'; +import { getFriend, friends, uid2UinMap, getUidByUin } from '@/common/data'; import { ActionName } from '../types'; import { ChatType } from '@/core/qqnt/entities'; import { dbUtil } from '@/common/utils/db'; @@ -21,26 +21,16 @@ interface Response { export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; protected async _handle(payload: Payload): Promise { - if (!uid2UinMap?.[payload.user_id]) { + let uin = getUidByUin(payload.user_id.toString()) + if (!uin) { throw `记录${payload.user_id}不存在`; } const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0'; - // log("startMsgId", startMsgId) - let friend = await getFriend(uid2UinMap?.[payload.user_id].toString()) - let historyResult = undefined; - if (friend) { - historyResult = (await NTQQMsgApi.getMsgHistory({ - chatType: ChatType.friend, - peerUid: uid2UinMap?.[payload.user_id] - }, startMsgId, parseInt(payload.count?.toString()) || 20)); - - } else { - historyResult = (await NTQQMsgApi.getMsgHistory({ - chatType: ChatType.temp, - peerUid: uid2UinMap?.[payload.user_id] - }, startMsgId, parseInt(payload.count?.toString()) || 20)); - } + let historyResult = (await NTQQMsgApi.getMsgHistory({ + chatType: friend ? ChatType.friend : ChatType.temp, + peerUid: uin + }, startMsgId, parseInt(payload.count?.toString()) || 20)); console.log(historyResult); const msgList = historyResult.msgList; await Promise.all(msgList.map(async msg => { From 7eaf7c0fdbc2d818a8bc30f22aed55b1b2864d17 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: Tue, 16 Apr 2024 18:36:51 +0800 Subject: [PATCH 5/7] fix --- src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index 6fae23d3..85083b81 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -21,15 +21,15 @@ interface Response { export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; protected async _handle(payload: Payload): Promise { - let uin = getUidByUin(payload.user_id.toString()) - if (!uin) { + let uid = getUidByUin(payload.user_id.toString()) + if (!uid) { throw `记录${payload.user_id}不存在`; } const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0'; - let friend = await getFriend(uid2UinMap?.[payload.user_id].toString()) + let friend = await getFriend(uid); let historyResult = (await NTQQMsgApi.getMsgHistory({ chatType: friend ? ChatType.friend : ChatType.temp, - peerUid: uin + peerUid: uid }, startMsgId, parseInt(payload.count?.toString()) || 20)); console.log(historyResult); const msgList = historyResult.msgList; From 19fe7d09d3707831965a69e9ac4aaea611cd0542 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: Tue, 16 Apr 2024 18:39:15 +0800 Subject: [PATCH 6/7] fix --- src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index 85083b81..6537542f 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -19,7 +19,7 @@ interface Response { } export default class GetFriendMsgHistory extends BaseAction { - actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; + actionName = ActionName.GetFriendMsgHistory; protected async _handle(payload: Payload): Promise { let uid = getUidByUin(payload.user_id.toString()) if (!uid) { From f3d82e869dd256ea8bd65d5581ecbb1f5b21a701 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: Tue, 16 Apr 2024 18:50:39 +0800 Subject: [PATCH 7/7] build:friend history --- src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index 6537542f..bc259a19 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -20,6 +20,7 @@ interface Response { export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GetFriendMsgHistory; + protected async _handle(payload: Payload): Promise { let uid = getUidByUin(payload.user_id.toString()) if (!uid) {