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

+2
View File
@@ -126,6 +126,8 @@ bot.when(
## Raw Action
动画系统表情可通过 `face(id, { resultId: '0' })` 指定结果,收到的结果保留在 `face.data.resultId` 中。不传时沿用默认选择;有效结果取决于具体表情,不能与 `large: false` 同用。
`await bot.getStatus()` 的 `time` 为当前账号服务实例的运行秒数,与 `#sl` 使用相同计时起点;实例重建后重新计时。
高频接口提供 camelCase 方法;其它 SnowLuma action 可以用 `raw` 或 `rawResponse`:
+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', {
+9
View File
@@ -11,6 +11,15 @@ import {
} from '../src';
describe('MessageChain', () => {
it.each([undefined, true])('preserves animation results through builders and CQ with large=%s', (large) => {
const options = { resultId: '0', ...(large !== undefined ? { large } : {}) };
const expected = [{ type: 'face', data: { id: '114', ...options } }];
expect(face(114, options).toSegments()).toEqual(expected);
expect(chain().face(114, options).toSegments()).toEqual(expected);
expect(message.face(114, options)).toEqual(expected[0]);
expect(parseSegments(toCQString(face(114, options)))).toEqual(expected);
});
it.each([false, true])('preserves face animation selection through builders and CQ, large=%s', (large) => {
const expected = [{ type: 'face', data: { id: '451', large } }];
const built = face(451, { large });