mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
01ab40bf4a
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -1,6 +1,8 @@
|
||||
name: "Build"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
|
@ -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",
|
||||
|
43
src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts
Normal file
43
src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts
Normal file
@ -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<Payload, Response> {
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
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 };
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
@ -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'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user