feat(onebot): support choosing animated system faces

Send available face animations by default and accept large=false for the small representation. Preserve the sticker business type when encoding animated faces.

Fixes #483
This commit is contained in:
DrSmoothl committed 2026-09-26 16:06:52 +08:00
1 parent 953b18b5cb
commit 805665a6d6
8 files changed
+64 -22

No files matched your search

+7 -6
View File
@@ -7,7 +7,7 @@ import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { randomUUID } from 'crypto';
import { deflateSync } from 'zlib';
import type { BridgeContext } from './bridge-context';
import { sysFaceStore } from './sys-face-store';
import { sysFaceStore, type FaceWire } from './sys-face-store';
import type { MessageElement } from './events';
import {
assertVideoSendPolicy,
@@ -53,15 +53,16 @@ function makeTextElem(text: string): ProtoElem {
// renders classic small faces; newer "super" / animated faces sent that way are
// silently remapped by the server (e.g. 424→168, issue #168). The split is
// data-driven off the system-face catalog (0x9154_1, see sys-face-store):
// super (animated, aniSticker not pack (1,1)) → CommonElem 37 + QFaceExtra
// animated (unless large=false) → CommonElem 37 + QFaceExtra
// other id ≥ 260 → CommonElem 33 + QSmallFaceExtra
// classic id < 260 → legacy FaceElem
async function makeFaceElem(faceId: number, ctx?: SendContext): Promise<ProtoElem> {
async function makeFaceElem(faceId: number, large: boolean, ctx?: SendContext): Promise<ProtoElem> {
// With a live bridge, wait for the authoritative catalog. Login normally
// preloads it, while this await closes the reconnect / first-send race.
const wire = ctx
const resolved = ctx
? await sysFaceStore.resolveWire(ctx.bridge, faceId)
: sysFaceStore.classify(faceId);
const wire: FaceWire = large ? resolved : { kind: faceId < 260 ? 'classic' : 'small' };
if (wire.kind === 'super') {
return {
commonElem: {
@@ -74,7 +75,7 @@ async function makeFaceElem(faceId: number, ctx?: SendContext): Promise<ProtoEle
stickerType: wire.stickerType,
randomType: 1,
}),
businessType: 1,
businessType: wire.stickerType < 4 ? wire.stickerType : 1,
},
};
}
@@ -567,7 +568,7 @@ export async function buildSendElems(elements: MessageElement[], ctx?: SendConte
break;
case 'face':
result.push(await makeFaceElem(elem.faceId, ctx));
result.push(await makeFaceElem(elem.faceId, elem.large ?? true, ctx));
break;
case 'poke':
+2 -2
View File
@@ -141,7 +141,7 @@ export const ELEMENT_MANIFEST = {
},
face: {
directions: { D: 'yes', S: 'yes', P: 'yes', W: 'yes' },
fields: fieldsFor<'face'>()(['faceId']),
fields: fieldsFor<'face'>()(['faceId', 'large']),
requiredFields: ['faceId'],
},
reply: {
@@ -258,7 +258,7 @@ const NUMBER_FIELDS: ReadonlySet<string> = new Set([
'width', 'height', 'emojiPackageId', 'sceneType', 'forwardTSum',
'picFormat', 'videoFormat', 'voiceFormat',
]);
const BOOLEAN_FIELDS: ReadonlySet<string> = new Set(['flash', 'noByteFallback']);
const BOOLEAN_FIELDS: ReadonlySet<string> = new Set(['flash', 'noByteFallback', 'large']);
function throwValidation(
code: MessageElementValidationCode,
+2
View File
@@ -39,6 +39,8 @@ export interface AtElement {
export interface FaceElement {
type: 'face';
faceId: number;
/** Send the catalog animation when available (default true). */
large?: boolean;
}
export interface ReplyElement {
@@ -172,10 +172,9 @@ export function findFaceEntity(packs: SysFacePackEntry[], faceId: number): SysFa
return null;
}
/** True when the catalog metadata selects the existing super-face send path. */
/** True when the catalog declares an animated sticker representation. */
export function isSuperFaceEntry(emoji: SysFaceEntry): boolean {
if (emoji.aniStickerType == null || emoji.aniStickerPackId == null) return false;
return !(emoji.aniStickerType === 1 && emoji.aniStickerPackId === 1);
return emoji.aniStickerType != null && emoji.aniStickerType > 0;
}
export function isSuperFaceId(packs: SysFacePackEntry[], faceId: number): boolean {