refactor: unify inline directives and media fetch
This commit is contained in:
49
src/auto-reply/reply/reply-directives.ts
Normal file
49
src/auto-reply/reply/reply-directives.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { splitMediaFromOutput } from "../../media/parse.js";
|
||||
import { parseInlineDirectives } from "../../utils/directive-tags.js";
|
||||
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js";
|
||||
|
||||
export type ReplyDirectiveParseResult = {
|
||||
text: string;
|
||||
mediaUrls?: string[];
|
||||
mediaUrl?: string;
|
||||
replyToId?: string;
|
||||
replyToCurrent: boolean;
|
||||
replyToTag: boolean;
|
||||
audioAsVoice?: boolean;
|
||||
isSilent: boolean;
|
||||
};
|
||||
|
||||
export function parseReplyDirectives(
|
||||
raw: string,
|
||||
options: { currentMessageId?: string; silentToken?: string } = {},
|
||||
): ReplyDirectiveParseResult {
|
||||
const split = splitMediaFromOutput(raw);
|
||||
let text = split.text ?? "";
|
||||
|
||||
const replyParsed = parseInlineDirectives(text, {
|
||||
currentMessageId: options.currentMessageId,
|
||||
stripAudioTag: false,
|
||||
stripReplyTags: true,
|
||||
});
|
||||
|
||||
if (replyParsed.hasReplyTag) {
|
||||
text = replyParsed.text;
|
||||
}
|
||||
|
||||
const silentToken = options.silentToken ?? SILENT_REPLY_TOKEN;
|
||||
const isSilent = isSilentReplyText(text, silentToken);
|
||||
if (isSilent) {
|
||||
text = "";
|
||||
}
|
||||
|
||||
return {
|
||||
text,
|
||||
mediaUrls: split.mediaUrls,
|
||||
mediaUrl: split.mediaUrl,
|
||||
replyToId: replyParsed.replyToId,
|
||||
replyToCurrent: replyParsed.replyToCurrent,
|
||||
replyToTag: replyParsed.hasReplyTag,
|
||||
audioAsVoice: split.audioAsVoice,
|
||||
isSilent,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user