Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/napcat-core/types/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,16 @@ export interface StructLongMsgElement {
resId: string;
}

export interface ReplyTextElem {
replyAbsElemType?: number;
textElemContent?: string;
faceElem?: unknown;
picElem?: unknown;
}

export interface ReplyElement {
sourceMsgIdInRecords?: string;
sourceMsgTextElems?: ReplyTextElem[];
replayMsgSeq: string;
replayMsgId: string;
senderUin: string;
Expand Down
16 changes: 12 additions & 4 deletions packages/napcat-onebot/api/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,27 @@ export class OneBotMsgApi {
};

// 创建回复数据的通用方法
const createReplyData = (msgId: string): OB11MessageData => ({
const createReplyData = (msgId: string, text?: string): OB11MessageData => ({
type: OB11MessageDataType.reply,
data: {
id: MessageUnique.createUniqueMsgId(peer, msgId).toString(),
...(text ? { text } : {}),
},
});

// 查找记录
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.sourceMsgIdInRecords);

// 特定账号的特殊处理
if (records && (records.peerUin === '284840486' || records.peerUin === '1094950020')) {
return createReplyData(records.msgId);
// 记录命中时直接用记录中的 msgId 构造 reply 段。
// 原实现只对特定账号(开发者测试号)走此捷径,其余账号走下方 seq 查询链;
// 但私聊中引用消息的 replayMsgSeq 常被解析为 0(引用 bot 或自己发的消息时尤甚),
// 查询链必然全部失败 → reply 段被静默丢弃(参见 #1508)。
// records.msgId 即被引用消息的真实 msgId,直接使用无需再查询。
if (records && records.msgId && records.msgId !== '0') {
const quotedText = (element?.sourceMsgTextElems || [])
.map(el => el.textElemContent ?? '')
.join('');
return createReplyData(records.msgId, quotedText);
}

// 获取消息的通用方法组
Expand Down
1 change: 1 addition & 0 deletions packages/napcat-onebot/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const OB11MessageReplySchema = Type.Object({
data: Type.Object({
id: Type.Optional(Type.String({ description: '消息ID的短ID映射' })),
seq: Type.Optional(Type.Number({ description: '消息序列号,优先使用' })),
text: Type.Optional(Type.String({ description: '被引用消息文本(记录命中时直接携带,避免二次查询)' })),
}),
}, { $id: 'OB11MessageReply', description: '回复消息段' });

Expand Down
Loading