release:1.8.2

This commit is contained in:
手瓜一十雪
2024-08-06 20:10:01 +08:00
parent c01e493bd2
commit 9a64b8bdb6
8 changed files with 53 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
import BaseAction from '../BaseAction';
import { OB11Message, OB11User } from '../../types';
import { ActionName } from '../types';
import { ChatType } from '@/core/entities';
import { ChatType, RawMessage } from '@/core/entities';
import { NTQQMsgApi } from '@/core/apis/msg';
import { OB11Constructor } from '../../constructor';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -17,9 +17,10 @@ const SchemaData = {
properties: {
user_id: { type: ['number', 'string'] },
message_seq: { type: 'number' },
count: { type: 'number' }
count: { type: 'number' },
reverseOrder: { type: 'boolean' }
},
required: ['user_id', 'message_seq', 'count']
required: ['user_id']
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -28,21 +29,28 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GetFriendMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
//处理参数
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if (!uid) {
throw `记录${payload.user_id}不存在`;
}
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq))?.MsgId || '0';
const MsgCount = payload.count || 20;
const isReverseOrder = payload.reverseOrder || true;
if (!uid) throw `记录${payload.user_id}不存在`;
const friend = await NTQQFriendApi.isBuddy(uid);
const historyResult = (await NTQQMsgApi.getMsgHistory({
chatType: friend ? ChatType.friend : ChatType.temp,
peerUid: uid
}, startMsgId, parseInt(payload.count?.toString()) || 20));
//logDebug(historyResult);
const msgList = historyResult.msgList;
const peer = { chatType: friend ? ChatType.friend : ChatType.temp, peerUid: uid };
//拉取消息
let msgList: RawMessage[];
if (!payload.message_seq || payload.message_seq == 0) {
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
} else {
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
}
if(isReverseOrder) msgList.reverse();
await Promise.all(msgList.map(async msg => {
msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
}));
//转换消息
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
return { 'messages': ob11MsgList };
}

View File

@@ -2,7 +2,7 @@ import BaseAction from '../BaseAction';
import { OB11Message, OB11User } from '../../types';
import { getGroup, groups } from '@/core/data';
import { ActionName } from '../types';
import { ChatType, RawMessage } from '@/core/entities';
import { ChatType, Peer, RawMessage } from '@/core/entities';
import { NTQQMsgApi } from '@/core/apis/msg';
import { OB11Constructor } from '../../constructor';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -16,7 +16,8 @@ const SchemaData = {
properties: {
group_id: { type: ['number', 'string'] },
message_seq: { type: 'number' },
count: { type: 'number' }
count: { type: 'number' },
reverseOrder: { type: 'boolean' }
},
required: ['group_id']
} as const satisfies JSONSchema;
@@ -27,25 +28,28 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
//处理参数
const group = await getGroup(payload.group_id.toString());
if (!group) {
throw `${payload.group_id}不存在`;
}
let targetMsgShortId, count = parseInt(payload.count?.toString() ?? '20');
const peer = {
chatType: ChatType.group,
peerUid: group.groupCode
};
const isReverseOrder = payload.reverseOrder || true;
const MsgCount = payload.count || 20;
const peer: Peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() };
if (!group) throw `${payload.group_id}不存在`;
//拉取消息
let msgList: RawMessage[];
if (!payload.message_seq || payload.message_seq === 0) {
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, count)).msgList;
if (!payload.message_seq || payload.message_seq == 0) {
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
} else {
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(targetMsgShortId ?? (payload.message_seq ?? 0)))?.MsgId || '0';
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, count)).msgList;
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
}
if(isReverseOrder) msgList.reverse();
await Promise.all(msgList.map(async msg => {
msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
}));
//转换消息
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
return { 'messages': ob11MsgList };
}

View File

@@ -1 +1 @@
export const version = '1.8.1';
export const version = '1.8.2';