feat(messages): support animated face results

Allow selecting animated face results and preserve received results in messages and history. Keep the default selection when no result is supplied.

Fixes #487
This commit is contained in:
DrSmoothl committed 2026-09-27 13:44:48 +08:00
1 parent 8cc5326a3a
commit 93b5c1b4bf
13 files changed
+185 -15

No files matched your search

+11 -6
View File
@@ -1,7 +1,7 @@
import { normalizeMessage, chain } from './chain';
import { escapeCqText, segmentsToCQString } from './cq-format';
import { segments } from './segments';
import type { AnyMessageSegment, OutgoingMessage } from '../types/index';
import type { AnyMessageSegment, FaceSegment, OutgoingMessage } from '../types/index';
const CQ_REGEX = /\[CQ:([a-zA-Z0-9_.-]+)(?:,([^\]]*))?\]/g;
@@ -69,11 +69,16 @@ function segmentFromCq(type: string, data: Record<string, string>): AnyMessageSe
switch (type) {
case 'text':
return segments.text(data.text ?? '');
case 'face':
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 'face': {
const options: Omit<FaceSegment['data'], 'id'> = {};
if (data.resultId !== undefined) options.resultId = data.resultId;
if (data.large !== undefined) {
if (data.large === 'true' || data.large === '1') options.large = true;
else if (data.large === 'false' || data.large === '0') options.large = false;
else throw new Error('face.large must be true, false, 1, or 0');
}
return segments.face(data.id ?? '0', options);
}
case 'at':
if (data.qq === 'all') return segments.at('all');
{
+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; large?: boolean }>;
export type FaceSegment = MessageSegment<'face', { id: string; large?: boolean; resultId?: string }>;
export type AtSegment = MessageSegment<'at', { qq: string; name?: string; uid?: string }>;
export type ReplySegment = MessageSegment<'reply', { id: string }>;
export type ImageSegment = MessageSegment<'image', {