openzca 0.1.30 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +71 -3
  2. 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;
@@ -1566,6 +1612,10 @@ function parseRecentMessageTs(value) {
1566
1612
  if (Number.isFinite(parsed)) {
1567
1613
  return Math.trunc(parsed);
1568
1614
  }
1615
+ const parsedDate = Date.parse(trimmed);
1616
+ if (Number.isFinite(parsedDate)) {
1617
+ return Math.trunc(parsedDate);
1618
+ }
1569
1619
  }
1570
1620
  return 0;
1571
1621
  }
@@ -2883,11 +2933,21 @@ auth.command("cache-clear").description("Clear local cache").action(
2883
2933
  })
2884
2934
  );
2885
2935
  var msg = program.command("msg").description("Messaging commands");
2886
- 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(
2887
2937
  wrapAction(async (threadId, message, opts, command) => {
2888
2938
  const { api } = await requireApi(command);
2889
- const response = await api.sendMessage(message, threadId, asThreadType(opts.group));
2890
- output(response, false);
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
+ }
2891
2951
  })
2892
2952
  );
2893
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(
@@ -3269,10 +3329,18 @@ msg.command("recent <threadId>").option("-g, --group", "List recent messages for
3269
3329
  const rows = messages.map((message) => ({
3270
3330
  msgId: message.data.msgId,
3271
3331
  cliMsgId: message.data.cliMsgId,
3332
+ threadId: message.threadId || threadId,
3333
+ threadType: message.type === ThreadType.Group ? "group" : "user",
3272
3334
  senderId: message.data.uidFrom,
3273
3335
  senderName: message.data.dName,
3274
3336
  ts: message.data.ts,
3275
3337
  msgType: message.data.msgType,
3338
+ undo: {
3339
+ msgId: message.data.msgId,
3340
+ cliMsgId: message.data.cliMsgId,
3341
+ threadId: message.threadId || threadId,
3342
+ group: message.type === ThreadType.Group
3343
+ },
3276
3344
  content: typeof message.data.content === "string" ? message.data.content : JSON.stringify(message.data.content)
3277
3345
  }));
3278
3346
  if (opts.json) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzca",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Open-source zca-compatible CLI to integrate Zalo with OpenClaw",
5
5
  "type": "module",
6
6
  "bin": {