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