fix(onebot): reject ambiguous video message combinations
Prevent ordinary messages and forwarded nodes from combining video content with visible sibling segments or additional videos. Invalid combinations now fail before parsing side effects, media work, or bridge sends, while exact empty text placeholders remain compatible with a single video. Cover group, private, temporary-session, CQ string, nested forward, cached forward, and protocol-builder paths. Preserve the existing standalone window-shake behavior and keep valid single-video messages unchanged.
This commit is contained in:
8 files changed
+371
-29
No files matched your search
@@ -67,6 +67,33 @@ export function assertWindowShakeSendPolicy(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* QQ clients treat a video as a standalone message: sibling elements remain
|
||||
* on the wire but are not rendered, and additional videos cannot be opened.
|
||||
* Reject that ambiguous wire shape instead of reporting a successful send
|
||||
* whose visible content differs from the caller's request.
|
||||
*/
|
||||
export function assertVideoSendPolicy(
|
||||
videoCount: number,
|
||||
effectiveSegmentCount: number,
|
||||
): void {
|
||||
if (videoCount === 0) return;
|
||||
if (videoCount !== 1) {
|
||||
throw new MessageElementValidationError(
|
||||
'UNSENDABLE_TYPE',
|
||||
'message element "video" may appear only once in a message',
|
||||
'video',
|
||||
);
|
||||
}
|
||||
if (effectiveSegmentCount !== 1) {
|
||||
throw new MessageElementValidationError(
|
||||
'UNSENDABLE_TYPE',
|
||||
'message element "video" must be the only segment in a message',
|
||||
'video',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
type ElementField<T extends MessageElementType> = Exclude<keyof MessageElementOf<T>, 'type'> & string;
|
||||
|
||||
export interface ElementSpec<T extends MessageElementType> {
|
||||
|
||||
Reference in new issue
Block a user