Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

转发消息:消息上下文相关功能补全 #434

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions lib/internal/contactable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export abstract class Contactable {
let cnt = 0
for (const fake of msglist) {
const maker = new Converter(fake.message, { dm: this.dm, cachedir: this.c.config.data_dir })
if (fake.source) maker.quote(fake.source)
makers.push(maker)
const seq = randomBytes(2).readInt16BE()
const rand = randomBytes(4).readInt32BE()
Expand Down
1 change: 1 addition & 0 deletions lib/message/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface Forwardable {
message: Sendable,
nickname?: string,
time?: number,
source?: Quotable
}

/** 可组合发送的元素 */
Expand Down
16 changes: 16 additions & 0 deletions lib/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,11 @@ export class ForwardMessage implements Forwardable {
nickname: string
group_id?: number
time: number
seq: number
rand: number
message: MessageElem[]
raw_message: string
source?: Quotable

/** 反序列化一条转发消息 */
static deserialize(serialized: Buffer) {
Expand All @@ -381,12 +384,25 @@ export class ForwardMessage implements Forwardable {
this.proto = proto
const head = proto[1]
this.time = head[6] || 0
// TODO: seq不确定这样处理合适不合适
this.seq = (head[5] >>> 16) === 0xffff? head[5] & 0xffff: head[5]
this.rand = proto[3]?.[1]?.[1]?.[3] || uuid2rand(head[7])
this.user_id = head[1] || 0
this.nickname = head[14]?.toString() || head[9]?.[4]?.toString() || ""
this.group_id = head[9]?.[1]
this.parsed = parse(proto[3][1])
this.message = this.parsed.message
this.raw_message = this.parsed.brief
if (this.parsed.quotation) {
const q = this.parsed.quotation
this.source = {
user_id: q[2],
time: q[3],
seq: q[1]?.[0] || q[1],
rand: uuid2rand(q[8]?.[3] || 0),
message: parse(Array.isArray(q[5]) ? q[5] : [q[5]]).brief,
}
}
lock(this, "proto")
lock(this, "parsed")
}
Expand Down