feat(sdk): preserve system face animation choices

Expose large in face builders and preserve it through CQ parsing and serialization. Reject invalid animation choices instead of silently discarding them.

Fixes #483
This commit is contained in:
DrSmoothl committed 2026-09-26 16:20:55 +08:00
1 parent 0cc06b6b5e
commit ad360c8eba
5 files changed
+28 -8

No files matched your search

+5 -4
View File
@@ -1,6 +1,7 @@
import type {
AnyMessageSegment,
ContactSegment,
FaceSegment,
ImageSegment,
JsonObject,
LocationSegment,
@@ -51,8 +52,8 @@ export class MessageChain<THasReply extends boolean = false> implements MessageC
return this.text('\n');
}
face(id: number | string): MessageChain<THasReply> {
return this.addSegment(segments.face(id));
face(id: number | string, options: Omit<FaceSegment['data'], 'id'> = {}): MessageChain<THasReply> {
return this.addSegment(segments.face(id, options));
}
at(qq: number | 'all', options: { name?: string; uid?: string } = {}): MessageChain<THasReply> {
@@ -203,8 +204,8 @@ export function br(): MessageChain<false> {
return chain().br();
}
export function face(id: number | string): MessageChain<false> {
return chain().face(id);
export function face(id: number | string, options: Omit<FaceSegment['data'], 'id'> = {}): MessageChain<false> {
return chain().face(id, options);
}
export function at(qq: number | 'all', options: { name?: string; uid?: string } = {}): MessageChain<false> {
+4 -1
View File
@@ -70,7 +70,10 @@ function segmentFromCq(type: string, data: Record<string, string>): AnyMessageSe
case 'text':
return segments.text(data.text ?? '');
case 'face':
return segments.face(data.id ?? '0');
if (data.large === undefined) return segments.face(data.id ?? '0');
if (data.large === 'true' || data.large === '1') return segments.face(data.id ?? '0', { large: true });
if (data.large === 'false' || data.large === '0') return segments.face(data.id ?? '0', { large: false });
throw new Error('face.large must be true, false, 1, or 0');
case 'at':
if (data.qq === 'all') return segments.at('all');
{
+2 -2
View File
@@ -29,8 +29,8 @@ export const segments = {
return seg('text', { text });
},
face(id: number | string): FaceSegment {
return seg('face', { id: String(id) });
face(id: number | string, options: Omit<FaceSegment['data'], 'id'> = {}): FaceSegment {
return seg('face', { id: String(id), ...options });
},
at(qq: number | 'all', options: { name?: string; uid?: string } = {}): AtSegment {
+1 -1
View File
@@ -9,7 +9,7 @@ export interface MessageSegment<
}
export type TextSegment = MessageSegment<'text', { text: string }>;
export type FaceSegment = MessageSegment<'face', { id: string }>;
export type FaceSegment = MessageSegment<'face', { id: string; large?: boolean }>;
export type AtSegment = MessageSegment<'at', { qq: string; name?: string; uid?: string }>;
export type ReplySegment = MessageSegment<'reply', { id: string }>;
export type ImageSegment = MessageSegment<'image', {