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: 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", diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts new file mode 100644 index 00000000..bc259a19 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -0,0 +1,43 @@ +import BaseAction from '../BaseAction'; +import { OB11Message, OB11User } from '../../types'; +import { getFriend, friends, uid2UinMap, getUidByUin } 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.GetFriendMsgHistory; + + protected async _handle(payload: Payload): Promise { + 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(uid); + let historyResult = (await NTQQMsgApi.getMsgHistory({ + chatType: friend ? ChatType.friend : ChatType.temp, + peerUid: uid + }, 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 2e534e3a..d5d7677b 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