diff --git a/src/common/utils/MessageUnique.ts b/src/common/utils/MessageUnique.ts index 30c4d09d..ac6190ed 100644 --- a/src/common/utils/MessageUnique.ts +++ b/src/common/utils/MessageUnique.ts @@ -61,6 +61,10 @@ class LimitedHashTable { this.valueToKey.delete(value); } } + + getKeyList(): K[] { + return Array.from(this.keyToValue.keys()); + } } class MessageUniqueWrapper { @@ -111,6 +115,25 @@ class MessageUniqueWrapper { this.msgIdMap.resize(maxSize); this.msgDataMap.resize(maxSize); } + getNthLatestShortIdByPeer(peer: Peer, index: number = 1): number | undefined { + const peerUid = peer.peerUid; + const chatType = peer.chatType; + const keys = this.msgDataMap.getKeyList(); + const matches: number[] = []; + for (const key of keys) { + const [msgId, chatTypeStr, peerUidStr] = key.split('|'); + if (peerUidStr === peerUid && chatTypeStr === chatType.toString()) { + const shortId = this.msgDataMap.getValue(key); + if (shortId) { + matches.push(shortId); + } + } + } + if (matches.length >= index) { + return matches[matches.length - index]; + } + return undefined; + } } export const MessageUnique: MessageUniqueWrapper = new MessageUniqueWrapper(); \ No newline at end of file diff --git a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts index c1f43021..a2e051af 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts @@ -18,7 +18,7 @@ const SchemaData = { message_seq: { type: 'number' }, count: { type: 'number' } }, - required: ['group_id', 'count'] + required: [ 'group_id' ] } as const satisfies JSONSchema; type Payload = FromSchema; @@ -31,13 +31,16 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);