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:
13 files changed
+185
-15
No files matched your search
@@ -150,12 +150,27 @@ export const ELEMENT_CODECS = {
|
||||
|
||||
face: {
|
||||
async toSegment(element) {
|
||||
return { type: 'face', data: { id: String(element.faceId ?? 0) } };
|
||||
return {
|
||||
type: 'face',
|
||||
data: {
|
||||
id: String(element.faceId ?? 0),
|
||||
...(element.resultId !== undefined ? { resultId: element.resultId } : {}),
|
||||
},
|
||||
};
|
||||
},
|
||||
async fromSegment(data) {
|
||||
const id = intOr(data.id, -1);
|
||||
if (id < 0) return null;
|
||||
const element: MessageElementOf<'face'> = { type: 'face', faceId: id };
|
||||
if (data.resultId !== undefined) {
|
||||
if (typeof data.resultId === 'string') {
|
||||
element.resultId = data.resultId;
|
||||
} else if (typeof data.resultId === 'number' && Number.isSafeInteger(data.resultId) && data.resultId >= 0) {
|
||||
element.resultId = String(data.resultId);
|
||||
} else {
|
||||
throw new MessageElementValidationError('INVALID_FIELD', 'face.resultId must be a string or non-negative safe integer', 'face', 'resultId');
|
||||
}
|
||||
}
|
||||
if (data.large !== undefined) {
|
||||
if (data.large === true || data.large === 'true' || data.large === 1 || data.large === '1') {
|
||||
element.large = true;
|
||||
|
||||
@@ -10,7 +10,7 @@ export function segmentToCQ(seg: JsonObject): string {
|
||||
case 'text':
|
||||
return cqEscape(String(data.text ?? ''));
|
||||
case 'face':
|
||||
return `[CQ:face,id=${data.id ?? 0}]`;
|
||||
return `[CQ:face,id=${data.id ?? 0}${data.resultId !== undefined ? `,resultId=${cqEscape(String(data.resultId))}` : ''}]`;
|
||||
case 'image':
|
||||
return `[CQ:image,file=${cqEscape(String(data.file ?? ''))},url=${cqEscape(String(data.url ?? ''))}]`;
|
||||
case 'at':
|
||||
@@ -77,4 +77,3 @@ export async function parseFromCQString(message: string, options?: ParseMessageO
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user