mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix
This commit is contained in:
parent
4d10b8cdee
commit
f6bc8f0a1f
52
src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts
Normal file
52
src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts
Normal file
@ -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<Payload, Response> {
|
||||||
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||||
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,7 @@ import GoCQHTTPDownloadFile from './go-cqhttp/DownloadFile';
|
|||||||
import GoCQHTTPGetGroupMsgHistory from './go-cqhttp/GetGroupMsgHistory';
|
import GoCQHTTPGetGroupMsgHistory from './go-cqhttp/GetGroupMsgHistory';
|
||||||
import GetFile from './file/GetFile';
|
import GetFile from './file/GetFile';
|
||||||
import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg';
|
import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg';
|
||||||
|
import GetFriendMsgHistory from './go-cqhttp/GetFriendMsgHistory';
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
@ -89,7 +90,7 @@ export const actionHandlers = [
|
|||||||
new GoCQHTTPUploadGroupFile(),
|
new GoCQHTTPUploadGroupFile(),
|
||||||
new GoCQHTTPGetGroupMsgHistory(),
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
new GoCQHTTGetForwardMsgAction(),
|
new GoCQHTTGetForwardMsgAction(),
|
||||||
|
new GetFriendMsgHistory()
|
||||||
];
|
];
|
||||||
|
|
||||||
function initActionMap() {
|
function initActionMap() {
|
||||||
|
@ -61,4 +61,5 @@ export enum ActionName {
|
|||||||
GoCQHTTP_DownloadFile = 'download_file',
|
GoCQHTTP_DownloadFile = 'download_file',
|
||||||
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',
|
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',
|
||||||
GoCQHTTP_GetForwardMsg = 'get_forward_msg',
|
GoCQHTTP_GetForwardMsg = 'get_forward_msg',
|
||||||
|
GetFriendMsgHistory = 'get_friend_msg_history'
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user