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
44 changes: 36 additions & 8 deletions src/milky/api/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ const SendPrivateMessage = defineApi(

let result: RawMessage
if (payload.message[0].type === 'forward') {
const forwardData = payload.message[0].data as {
messages: OutgoingForwardedMessage[]
title?: string
preview?: { text: string }[]
summary?: string
prompt?: string
}
const raw = await transformOutgoingForwardMessages(
ctx,
payload.message[0].data.messages as OutgoingForwardedMessage[],
peer
forwardData.messages,
peer,
{
title: forwardData.title,
preview: forwardData.preview,
summary: forwardData.summary,
prompt: forwardData.prompt
}
)
const resid = await ctx.app.pmhq.uploadForward(peer, raw.multiMsgItems)
const uuid = randomUUID()
const prompt = raw.prompt
result = await ctx.app.sendMessage(ctx, peer, [{
elementType: 10,
elementId: '',
Expand All @@ -64,7 +78,7 @@ const SendPrivateMessage = defineApi(
type: 'normal',
width: 300,
},
desc: '[聊天记录]',
desc: prompt,
extra: JSON.stringify({
filename: uuid,
tsum: raw.tsum,
Expand All @@ -78,7 +92,7 @@ const SendPrivateMessage = defineApi(
uniseq: uuid,
},
},
prompt: '[聊天记录]',
prompt,
ver: '0.0.0.5',
view: 'contact',
}),
Expand Down Expand Up @@ -117,13 +131,27 @@ const SendGroupMessage = defineApi(

let result: RawMessage
if (payload.message[0].type === 'forward') {
const forwardData = payload.message[0].data as {
messages: OutgoingForwardedMessage[]
title?: string
preview?: { text: string }[]
summary?: string
prompt?: string
}
const raw = await transformOutgoingForwardMessages(
ctx,
payload.message[0].data.messages as OutgoingForwardedMessage[],
peer
forwardData.messages,
peer,
{
title: forwardData.title,
preview: forwardData.preview,
summary: forwardData.summary,
prompt: forwardData.prompt
}
)
const resid = await ctx.app.pmhq.uploadForward(peer, raw.multiMsgItems)
const uuid = randomUUID()
const prompt = raw.prompt
result = await ctx.app.sendMessage(ctx, peer, [{
elementType: 10,
elementId: '',
Expand All @@ -137,7 +165,7 @@ const SendGroupMessage = defineApi(
type: 'normal',
width: 300,
},
desc: '[聊天记录]',
desc: prompt,
extra: JSON.stringify({
filename: uuid,
tsum: raw.tsum,
Expand All @@ -151,7 +179,7 @@ const SendGroupMessage = defineApi(
uniseq: uuid,
},
},
prompt: '[聊天记录]',
prompt,
ver: '0.0.0.5',
view: 'contact',
}),
Expand Down
24 changes: 18 additions & 6 deletions src/milky/transform/message/outgoing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ export async function transformOutgoingMessage(
export async function transformOutgoingForwardMessages(
ctx: Context,
messages: OutgoingForwardedMessage[],
peer: Peer
peer: Peer,
options?: {
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 {
Expand Down Expand Up @@ -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: [{
Expand All @@ -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 ?? '[聊天记录]'
}
}
}
30 changes: 23 additions & 7 deletions src/onebot11/action/go-cqhttp/SendForwardMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ interface Payload {
messages?: OB11MessageNode[]
message?: OB11MessageNode[]
message_type?: 'group' | 'private'
// 合并转发自定义外显
source?: string
news?: { text: string }[]
summary?: string
prompt?: string
}

interface Response {
Expand All @@ -35,8 +40,8 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
})

protected async _handle(payload: Payload) {
const messages = payload.messages ?? payload.message
if (!messages) {
const messages = (payload.messages?.length ? payload.messages : null) ?? payload.message
if (!messages || messages.length === 0) {
throw new Error('未指定消息内容')
}
let contextMode = CreatePeerMode.Normal
Expand Down Expand Up @@ -122,7 +127,12 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
}
}

return fake ? await this.handleFakeForwardNode(peer, nodes) : await this.handleForwardNode(peer, nodes, msgInfos)
return fake ? await this.handleFakeForwardNode(peer, nodes, {
source: payload.source,
news: payload.news,
summary: payload.summary,
prompt: payload.prompt
}) : await this.handleForwardNode(peer, nodes, msgInfos)
}

private async getMessageNode(msgInfo: MsgInfo) {
Expand Down Expand Up @@ -162,11 +172,17 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
})
}

private async handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[]): Promise<Response> {
private async handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[], options?: {
source?: string
news?: { text: string }[]
summary?: string
prompt?: string
}): Promise<Response> {
const encoder = new MessageEncoder(this.ctx, peer)
const raw = await encoder.generate(nodes)
const raw = await encoder.generate(nodes, options)
const resid = await this.ctx.app.pmhq.uploadForward(peer, raw.multiMsgItems)
const uuid = randomUUID()
const prompt = options?.prompt ?? '[聊天记录]'
try {
const msg = await this.ctx.app.sendMessage(this.ctx, peer, [{
elementType: 10,
Expand All @@ -181,7 +197,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
type: 'normal',
width: 300,
},
desc: '[聊天记录]',
desc: prompt,
extra: JSON.stringify({
filename: uuid,
tsum: raw.tsum,
Expand All @@ -195,7 +211,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
uniseq: uuid,
},
},
prompt: '[聊天记录]',
prompt,
ver: '0.0.0.5',
view: 'contact',
}),
Expand Down
Loading