-
Notifications
You must be signed in to change notification settings - Fork 228
feat: milky 合并转发外显 #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: milky 合并转发外显 #683
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,10 +90,16 @@ export async function transformOutgoingMessage( | |
| export async function transformOutgoingForwardMessages( | ||
| ctx: Context, | ||
| messages: OutgoingForwardedMessage[], | ||
| peer: Peer | ||
| peer: Peer, | ||
| options?: { | ||
|
Comment on lines
90
to
+94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion:
推荐实现方式: type ForwardRenderOptions = {
title?: string
preview?: { text: string }[]
summary?: string
prompt?: string
}
export async function transformOutgoingForwardMessages(
ctx: Context,
messages: OutgoingForwardedMessage[],
peer: Peer,
options?: ForwardRenderOptions
) {
const encoder = new ForwardMessageEncoder(ctx, peer)
return await encoder.generate(messages, options)
}
class ForwardMessageEncoder {请在本文件中相应地更新
Original comment in Englishsuggestion: The The Suggested implementation: type ForwardRenderOptions = {
title?: string
preview?: { text: string }[]
summary?: string
prompt?: string
}
export async function transformOutgoingForwardMessages(
ctx: Context,
messages: OutgoingForwardedMessage[],
peer: Peer,
options?: ForwardRenderOptions
) {
const encoder = new ForwardMessageEncoder(ctx, peer)
return await encoder.generate(messages, options)
}
class ForwardMessageEncoder {Update the
|
||
| title?: string | ||
| preview?: { text: string }[] | ||
| summary?: string | ||
| prompt?: string | ||
| } | ||
| ) { | ||
| const encoder = new ForwardMessageEncoder(ctx, peer) | ||
| return await encoder.generate(messages) | ||
| return await encoder.generate(messages, options) | ||
| } | ||
|
|
||
| class ForwardMessageEncoder { | ||
|
|
@@ -304,7 +310,12 @@ class ForwardMessageEncoder { | |
| } | ||
| } | ||
|
|
||
| async generate(content: OutgoingForwardedMessage[]) { | ||
| async generate(content: OutgoingForwardedMessage[], options?: { | ||
| title?: string | ||
| preview?: { text: string }[] | ||
| summary?: string | ||
| prompt?: string | ||
| }) { | ||
| await this.render(content) | ||
| return { | ||
| multiMsgItems: [{ | ||
|
|
@@ -314,9 +325,10 @@ class ForwardMessageEncoder { | |
| } | ||
| }], | ||
| tsum: this.tsum, | ||
| source: this.isGroup ? '群聊的聊天记录' : '聊天记录', | ||
| summary: `查看${this.tsum}条转发消息`, | ||
| news: this.news | ||
| source: options?.title ?? (this.isGroup ? '群聊的聊天记录' : '聊天记录'), | ||
| summary: options?.summary ?? `查看${this.tsum}条转发消息`, | ||
| news: options?.preview ?? this.news, | ||
| prompt: options?.prompt ?? '[聊天记录]' | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: 转发消息 payload 的结构在私聊和群聊处理器中都被重复并手动类型断言;建议提取一个共享的类型/辅助方法。
payload.message[0].data的这个结构性类型断言现在在SendPrivateMessage和SendGroupMessage中都出现了一次,因此只要转发 payload 的结构发生变更(例如新增字段),就必须在多个地方同步修改。定义一个共享的ForwardPayload类型和辅助方法(例如getForwardPayload(payload.message[0]))可以把这部分结构集中管理,降低两个处理器实现产生不一致的风险。推荐实现方式:
你提到这个结构性类型断言在
SendPrivateMessage和SendGroupMessage中都被重复使用。请在群聊处理器中做同样的替换:payload.message[0].type === 'forward'并对payload.message[0].data进行相同结构的内联类型断言的地方。const forwardData = getForwardPayload(payload.message[0])来替换这段内联断言,其余使用方式保持不变(例如forwardData.messages、forwardData.title等)。由于
ForwardPayload和getForwardPayload只在第一次使用附近定义一次,它们会被这两个处理器共享,而无需在其他地方再做额外修改。Original comment in English
suggestion: The forward message payload shape is duplicated and manually cast in both private and group handlers; consider extracting a shared type/helper.
This structural cast of
payload.message[0].datais now duplicated in bothSendPrivateMessageandSendGroupMessage, so any change to the forward payload (e.g., new fields) must be updated in multiple places. A sharedForwardPayloadtype and helper (e.g.,getForwardPayload(payload.message[0])) would centralize this shape and reduce the risk of the handlers drifting out of sync.Suggested implementation:
You mentioned this structural cast is duplicated in both
SendPrivateMessageandSendGroupMessage. Apply the same replacement in the group handler:payload.message[0].type === 'forward'is checked andpayload.message[0].datais cast inline to the same shape.const forwardData = getForwardPayload(payload.message[0])and keep the rest of the usage (forwardData.messages,forwardData.title, etc.) the same.Because
ForwardPayloadandgetForwardPayloadare defined once near the first usage, they will be shared by both handlers without further changes.