fix:Fix the issue where quoting a message in replies was ineffective
Previous behavior: Replies visually displayed a quote block, but the quoted content was blank or invalid, and clicking to jump to the original message also failed. Fixed behavior: The quote now correctly references the original message, displaying its actual content and enabling a functional jump to the quoted message.
This commit is contained in:
1 parent
4a92292e49
commit
de7533ca81
8 files changed
+407
-27
No files matched your search
@@ -12,6 +12,9 @@ import type { JsonObject, MessageMeta, OneBotConfig } from './types';
|
||||
import { HttpTransport } from './http-transport';
|
||||
import { HttpPostTransport } from './http-post-transport';
|
||||
import { WsTransport } from './ws-transport';
|
||||
import { createLogger } from '../utils/logger';
|
||||
|
||||
const log = createLogger('Event');
|
||||
|
||||
export class OneBotInstance {
|
||||
readonly uin: string;
|
||||
@@ -153,10 +156,62 @@ export class OneBotInstance {
|
||||
|
||||
private dispatchEvent(event: JsonObject): void {
|
||||
this.cacheMessageEvent(event);
|
||||
this.logReceivedMessage(event);
|
||||
this.wsTransport.publishEvent(event);
|
||||
this.httpPostTransport.publishEvent(event);
|
||||
}
|
||||
|
||||
private logReceivedMessage(event: JsonObject): void {
|
||||
if (event.post_type !== 'message') return;
|
||||
|
||||
const messageId = toInt(event.message_id);
|
||||
const isGroup = event.message_type === 'group';
|
||||
|
||||
// Build message preview
|
||||
const parts: string[] = [];
|
||||
const message = event.message;
|
||||
|
||||
if (Array.isArray(message)) {
|
||||
for (const seg of message) {
|
||||
if (seg.type === 'text' && seg.data?.text) {
|
||||
const text = String(seg.data.text);
|
||||
const preview = text.length > 50 ? text.substring(0, 50) + '...' : text;
|
||||
parts.push(preview);
|
||||
} else if (seg.type === 'image') {
|
||||
parts.push('[图片]');
|
||||
} else if (seg.type === 'face') {
|
||||
parts.push('[表情]');
|
||||
} else if (seg.type === 'at') {
|
||||
parts.push(`@${seg.data?.qq || ''}`);
|
||||
} else if (seg.type === 'reply') {
|
||||
parts.push(`[回复:${seg.data?.id || ''}]`);
|
||||
} else if (seg.type === 'record') {
|
||||
parts.push('[语音]');
|
||||
} else if (seg.type === 'video') {
|
||||
parts.push('[视频]');
|
||||
} else {
|
||||
parts.push(`[${seg.type}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const content = parts.join(' ').trim() || '[空消息]';
|
||||
const idStr = `ID:${messageId}`;
|
||||
|
||||
if (isGroup) {
|
||||
const groupId = toInt(event.group_id);
|
||||
const userId = toInt(event.user_id);
|
||||
const sender = event.sender as any;
|
||||
const nickname = sender?.card || sender?.nickname || String(userId);
|
||||
log.success(`群 ${groupId} | ${nickname}(${userId}): ${idStr} ${content}`);
|
||||
} else {
|
||||
const userId = toInt(event.user_id);
|
||||
const sender = event.sender as any;
|
||||
const nickname = sender?.nickname || String(userId);
|
||||
log.success(`私聊 ${nickname}(${userId}): ${idStr} ${content}`);
|
||||
}
|
||||
}
|
||||
|
||||
private cacheMessageEvent(event: JsonObject): void {
|
||||
if (event.post_type !== 'message') return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user