From 9a64b8bdb631c027560b55cee8f55ec99eacb36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 6 Aug 2024 20:10:01 +0800 Subject: [PATCH] release:1.8.2 --- ...HANGELOG.v1.8.1.md => CHANGELOG.v1.8.2.md} | 8 ++--- package.json | 2 +- src/core/src/apis/msg.ts | 8 ++--- .../action/go-cqhttp/GetFriendMsgHistory.ts | 36 +++++++++++-------- .../action/go-cqhttp/GetGroupMsgHistory.ts | 34 ++++++++++-------- src/onebot11/version.ts | 2 +- src/webui/ui/NapCat.ts | 2 +- static/assets/renderer.js | 2 +- 8 files changed, 53 insertions(+), 41 deletions(-) rename docs/changelogs/{CHANGELOG.v1.8.1.md => CHANGELOG.v1.8.2.md} (67%) diff --git a/docs/changelogs/CHANGELOG.v1.8.1.md b/docs/changelogs/CHANGELOG.v1.8.2.md similarity index 67% rename from docs/changelogs/CHANGELOG.v1.8.1.md rename to docs/changelogs/CHANGELOG.v1.8.2.md index d7c6f01a..dcda840e 100644 --- a/docs/changelogs/CHANGELOG.v1.8.1.md +++ b/docs/changelogs/CHANGELOG.v1.8.2.md @@ -1,4 +1,4 @@ -# v1.8.1 +# v1.8.2 QQ Version: Windows 9.9.15-26702 / Linux 3.2.12-26702 @@ -6,8 +6,8 @@ QQ Version: Windows 9.9.15-26702 / Linux 3.2.12-26702 Way03/Way05 ## 新增与调整 -1. 多层转发消息解析 -2. 撤回消息附带反馈 -3. 文件上传兼容性提升 +1. 多层转发消息接收/发送 +2. 消息列表排序修正 + 新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api) diff --git a/package.json b/package.json index 688b158f..ed70a29e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "1.8.1", + "version": "1.8.2", "scripts": { "watch:dev": "vite --mode development", "watch:prod": "vite --mode production", diff --git a/src/core/src/apis/msg.ts b/src/core/src/apis/msg.ts index 1067a020..5bf86ffd 100644 --- a/src/core/src/apis/msg.ts +++ b/src/core/src/apis/msg.ts @@ -97,14 +97,14 @@ export class NTQQMsgApi { static async ForwardMsg(peer: Peer, msgIds: string[]) { return napCatCore.session.getMsgService().forwardMsg(msgIds, peer, [peer], new Map()); } - static async getLastestMsgByUids(peer: Peer, count: number = 20) { + static async getLastestMsgByUids(peer: Peer, count: number = 20, isReverseOrder: boolean = false) { let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', { chatInfo: peer, filterMsgType: [], filterSendersUid: [], filterMsgToTime: '0', filterMsgFromTime: '0', - isReverseOrder: false, + isReverseOrder: isReverseOrder, isIncludeCurrent: true, pageLimit: count, }); @@ -157,9 +157,9 @@ export class NTQQMsgApi { ); return data[1].item; } - static async getMsgHistory(peer: Peer, msgId: string, count: number) { + static async getMsgHistory(peer: Peer, msgId: string, count: number, isReverseOrder: boolean = false) { // 消息时间从旧到新 - return napCatCore.session.getMsgService().getMsgsIncludeSelf(peer, msgId, count, true); + return napCatCore.session.getMsgService().getMsgsIncludeSelf(peer, msgId, count, isReverseOrder); } static async recallMsg(peer: Peer, msgIds: string[]) { await napCatCore.session.getMsgService().recallMsg({ diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index 8d17ce80..3ca15764 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -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; @@ -28,21 +29,28 @@ export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GetFriendMsgHistory; PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { + //处理参数 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 }; } diff --git a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts index 15f1aa61..de518621 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts @@ -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 { + //处理参数 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 }; } diff --git a/src/onebot11/version.ts b/src/onebot11/version.ts index 761984cd..0751aa4d 100644 --- a/src/onebot11/version.ts +++ b/src/onebot11/version.ts @@ -1 +1 @@ -export const version = '1.8.1'; +export const version = '1.8.2'; diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index 66041ff9..35ecac62 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -29,7 +29,7 @@ async function onSettingWindowCreated(view: Element) { SettingItem( 'Napcat', undefined, - SettingButton('V1.8.1', 'napcat-update-button', 'secondary') + SettingButton('V1.8.2', 'napcat-update-button', 'secondary') ), ]), SettingList([ diff --git a/static/assets/renderer.js b/static/assets/renderer.js index ef81a71f..453ed05e 100644 --- a/static/assets/renderer.js +++ b/static/assets/renderer.js @@ -163,7 +163,7 @@ async function onSettingWindowCreated(view) { SettingItem( 'Napcat', void 0, - SettingButton("V1.8.1", "napcat-update-button", "secondary") + SettingButton("V1.8.2", "napcat-update-button", "secondary") ) ]), SettingList([