openzca 0.1.31 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +59 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
Gender,
|
|
16
16
|
Reactions,
|
|
17
17
|
ReviewPendingMemberRequestStatus,
|
|
18
|
+
TextStyle,
|
|
18
19
|
ThreadType
|
|
19
20
|
} from "zca-js";
|
|
20
21
|
|
|
@@ -704,6 +705,51 @@ function output(value, asJson = false) {
|
|
|
704
705
|
function asThreadType(groupFlag) {
|
|
705
706
|
return groupFlag ? ThreadType.Group : ThreadType.User;
|
|
706
707
|
}
|
|
708
|
+
function parseTextStyles(input) {
|
|
709
|
+
const styles = [];
|
|
710
|
+
const markers = [
|
|
711
|
+
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold },
|
|
712
|
+
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
713
|
+
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
714
|
+
{ pattern: /__(.+?)__/g, style: TextStyle.Underline },
|
|
715
|
+
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
716
|
+
];
|
|
717
|
+
let segments = [{ text: input, styles: [] }];
|
|
718
|
+
for (const { pattern, style } of markers) {
|
|
719
|
+
const next = [];
|
|
720
|
+
for (const seg of segments) {
|
|
721
|
+
let lastIndex = 0;
|
|
722
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
723
|
+
let m;
|
|
724
|
+
while ((m = regex.exec(seg.text)) !== null) {
|
|
725
|
+
if (m.index > lastIndex) {
|
|
726
|
+
next.push({ text: seg.text.slice(lastIndex, m.index), styles: [...seg.styles] });
|
|
727
|
+
}
|
|
728
|
+
const combined = [...seg.styles, style];
|
|
729
|
+
if (pattern.source.startsWith("\\*\\*\\*")) {
|
|
730
|
+
combined.push(TextStyle.Italic);
|
|
731
|
+
}
|
|
732
|
+
next.push({ text: m[1], styles: combined });
|
|
733
|
+
lastIndex = regex.lastIndex;
|
|
734
|
+
}
|
|
735
|
+
if (lastIndex < seg.text.length) {
|
|
736
|
+
next.push({ text: seg.text.slice(lastIndex), styles: [...seg.styles] });
|
|
737
|
+
} else if (lastIndex === 0) {
|
|
738
|
+
next.push(seg);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
segments = next;
|
|
742
|
+
}
|
|
743
|
+
let plainText = "";
|
|
744
|
+
for (const seg of segments) {
|
|
745
|
+
const start = plainText.length;
|
|
746
|
+
plainText += seg.text;
|
|
747
|
+
for (const st of seg.styles) {
|
|
748
|
+
styles.push({ start, len: seg.text.length, st });
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return { text: plainText, styles };
|
|
752
|
+
}
|
|
707
753
|
function parseBooleanFromEnv(name, fallback) {
|
|
708
754
|
const raw = process.env[name]?.trim();
|
|
709
755
|
if (!raw) return fallback;
|
|
@@ -2887,11 +2933,21 @@ auth.command("cache-clear").description("Clear local cache").action(
|
|
|
2887
2933
|
})
|
|
2888
2934
|
);
|
|
2889
2935
|
var msg = program.command("msg").description("Messaging commands");
|
|
2890
|
-
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").description("Send text message").action(
|
|
2936
|
+
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").option("--raw", "Send raw text without parsing formatting markers").description("Send text message (supports **bold** *italic* __underline__ ~~strikethrough~~)").action(
|
|
2891
2937
|
wrapAction(async (threadId, message, opts, command) => {
|
|
2892
2938
|
const { api } = await requireApi(command);
|
|
2893
|
-
|
|
2894
|
-
|
|
2939
|
+
if (opts.raw) {
|
|
2940
|
+
const response = await api.sendMessage(message, threadId, asThreadType(opts.group));
|
|
2941
|
+
output(response, false);
|
|
2942
|
+
} else {
|
|
2943
|
+
const { text, styles } = parseTextStyles(message);
|
|
2944
|
+
const response = await api.sendMessage(
|
|
2945
|
+
{ msg: text, styles: styles.length > 0 ? styles : void 0 },
|
|
2946
|
+
threadId,
|
|
2947
|
+
asThreadType(opts.group)
|
|
2948
|
+
);
|
|
2949
|
+
output(response, false);
|
|
2950
|
+
}
|
|
2895
2951
|
})
|
|
2896
2952
|
);
|
|
2897
2953
|
msg.command("image <threadId> [file]").option("-u, --url <url>", "Image URL (repeatable)", collectValues, []).option("-m, --message <message>", "Caption").option("-g, --group", "Send to group").description("Send image(s) from file or URL").action(
|