@qzhuli/qzhuli-cli 0.5.3 → 0.5.4
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/cmd.js +57 -23
- package/package.json +1 -1
package/dist/cmd.js
CHANGED
|
@@ -12727,11 +12727,24 @@ async function searchByName(factory, name) {
|
|
|
12727
12727
|
const profileResults = await Promise.all(
|
|
12728
12728
|
conversations3.map((c) => factory.repos.conversation.getProfile(c.id))
|
|
12729
12729
|
);
|
|
12730
|
-
const
|
|
12730
|
+
const queryLower = name.toLowerCase();
|
|
12731
|
+
const scored = profileResults.filter((r) => r.ok).flatMap((r) => {
|
|
12732
|
+
const p = r.data;
|
|
12731
12733
|
const convName = p.conversation.name ?? "";
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
|
|
12734
|
+
const teamName = p.conversation.team_name ?? "";
|
|
12735
|
+
const fields = [convName, teamName].filter(Boolean);
|
|
12736
|
+
if (fields.length === 0) return [];
|
|
12737
|
+
let best = 0;
|
|
12738
|
+
for (const f of fields) {
|
|
12739
|
+
const lower = f.toLowerCase();
|
|
12740
|
+
if (lower === queryLower) best = Math.max(best, 3);
|
|
12741
|
+
else if (lower.startsWith(queryLower)) best = Math.max(best, 2);
|
|
12742
|
+
else if (lower.includes(queryLower)) best = Math.max(best, 1);
|
|
12743
|
+
}
|
|
12744
|
+
if (best === 0) return [];
|
|
12745
|
+
return [{ profile: p, score: best }];
|
|
12746
|
+
}).sort((a, b) => b.score - a.score);
|
|
12747
|
+
if (scored.length === 0) {
|
|
12735
12748
|
return {
|
|
12736
12749
|
status: "success",
|
|
12737
12750
|
code: "NOT_FOUND" /* NOT_FOUND */,
|
|
@@ -12739,7 +12752,7 @@ async function searchByName(factory, name) {
|
|
|
12739
12752
|
data: null
|
|
12740
12753
|
};
|
|
12741
12754
|
}
|
|
12742
|
-
const items =
|
|
12755
|
+
const items = scored.map((s) => profileToItem(s.profile));
|
|
12743
12756
|
const groupedByUid = /* @__PURE__ */ new Map();
|
|
12744
12757
|
for (const item of items) {
|
|
12745
12758
|
const primaryUser = item.users[0];
|
|
@@ -12757,7 +12770,19 @@ async function searchByName(factory, name) {
|
|
|
12757
12770
|
});
|
|
12758
12771
|
}
|
|
12759
12772
|
}
|
|
12760
|
-
const results = [...groupedByUid.values()]
|
|
12773
|
+
const results = [...groupedByUid.values()].sort((a, b) => {
|
|
12774
|
+
const maxScoreA = Math.max(
|
|
12775
|
+
...a.conversations.map(
|
|
12776
|
+
(c) => scored.find((s) => s.profile.conversation.conversation_id === c.conversationId)?.score ?? 0
|
|
12777
|
+
)
|
|
12778
|
+
);
|
|
12779
|
+
const maxScoreB = Math.max(
|
|
12780
|
+
...b.conversations.map(
|
|
12781
|
+
(c) => scored.find((s) => s.profile.conversation.conversation_id === c.conversationId)?.score ?? 0
|
|
12782
|
+
)
|
|
12783
|
+
);
|
|
12784
|
+
return maxScoreB - maxScoreA;
|
|
12785
|
+
});
|
|
12761
12786
|
if (results.length === 0) {
|
|
12762
12787
|
return {
|
|
12763
12788
|
status: "success",
|
|
@@ -12846,6 +12871,14 @@ async function friendListRun(factory) {
|
|
|
12846
12871
|
|
|
12847
12872
|
// src/commands/friend/profile.ts
|
|
12848
12873
|
init_cjs_shims();
|
|
12874
|
+
function matchScore(text, queryLower) {
|
|
12875
|
+
if (!text) return 0;
|
|
12876
|
+
const lower = text.toLowerCase();
|
|
12877
|
+
if (lower === queryLower) return 3;
|
|
12878
|
+
if (lower.startsWith(queryLower)) return 2;
|
|
12879
|
+
if (lower.includes(queryLower)) return 1;
|
|
12880
|
+
return 0;
|
|
12881
|
+
}
|
|
12849
12882
|
async function friendProfileRun(factory, opts) {
|
|
12850
12883
|
const listResult = await factory.repos.contact.getLinksContacts();
|
|
12851
12884
|
if (!listResult.ok) {
|
|
@@ -12886,17 +12919,17 @@ async function friendProfileRun(factory, opts) {
|
|
|
12886
12919
|
friend_name: team.name
|
|
12887
12920
|
}))
|
|
12888
12921
|
];
|
|
12889
|
-
const
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
}
|
|
12899
|
-
if (
|
|
12922
|
+
const queryLower = opts.query.toLowerCase();
|
|
12923
|
+
let scored;
|
|
12924
|
+
if (opts.byUid) {
|
|
12925
|
+
scored = allEntries.filter((e) => e.uid?.toLowerCase() === queryLower).map((e) => ({ ...e, score: 3 }));
|
|
12926
|
+
} else {
|
|
12927
|
+
scored = allEntries.map((e) => {
|
|
12928
|
+
const field = opts.byRemark ? e.friend_name : e.nickname;
|
|
12929
|
+
return { ...e, score: matchScore(field, queryLower) };
|
|
12930
|
+
}).filter((e) => e.score > 0).sort((a, b) => b.score - a.score);
|
|
12931
|
+
}
|
|
12932
|
+
if (scored.length === 0) {
|
|
12900
12933
|
return {
|
|
12901
12934
|
status: "error",
|
|
12902
12935
|
code: "NOT_FOUND" /* NOT_FOUND */,
|
|
@@ -12904,12 +12937,13 @@ async function friendProfileRun(factory, opts) {
|
|
|
12904
12937
|
data: null
|
|
12905
12938
|
};
|
|
12906
12939
|
}
|
|
12907
|
-
if (
|
|
12908
|
-
const suggestions =
|
|
12940
|
+
if (scored.length > 1) {
|
|
12941
|
+
const suggestions = scored.map((m) => ({
|
|
12909
12942
|
uid: m.uid,
|
|
12910
12943
|
nickname: m.nickname ?? "",
|
|
12911
12944
|
remark: m.friend_name ?? "",
|
|
12912
|
-
type: m._type
|
|
12945
|
+
type: m._type,
|
|
12946
|
+
score: m.score
|
|
12913
12947
|
}));
|
|
12914
12948
|
return {
|
|
12915
12949
|
status: "needs_resolution",
|
|
@@ -12918,12 +12952,12 @@ async function friendProfileRun(factory, opts) {
|
|
|
12918
12952
|
data: suggestions
|
|
12919
12953
|
};
|
|
12920
12954
|
}
|
|
12921
|
-
const match =
|
|
12955
|
+
const match = scored[0];
|
|
12922
12956
|
if (match._type !== "link") {
|
|
12923
12957
|
return {
|
|
12924
12958
|
status: "success",
|
|
12925
12959
|
code: "USER_FOUND" /* USER_FOUND */,
|
|
12926
|
-
message: t("messages.found").replace("{name}", match.nickname ?? match.friend_name),
|
|
12960
|
+
message: t("messages.found").replace("{name}", match.nickname ?? match.friend_name ?? ""),
|
|
12927
12961
|
data: {
|
|
12928
12962
|
uid: match.uid,
|
|
12929
12963
|
nickname: match.nickname ?? match.friend_name,
|
|
@@ -15109,7 +15143,7 @@ async function main() {
|
|
|
15109
15143
|
${t("cli.banner")}` : t("cli.banner");
|
|
15110
15144
|
program.addHelpText("beforeAll", `${banner}
|
|
15111
15145
|
`);
|
|
15112
|
-
program.name("qz").version(`v${"0.5.
|
|
15146
|
+
program.name("qz").version(`v${"0.5.4"}`, "-v, --version", t("options.version")).helpOption("-h, --help", t("options.help")).option("-q, --jq <expr>", t("options.jq")).option("--dry-run", t("options.dryRun"));
|
|
15113
15147
|
program.usage("<command> [subcommand] [options]");
|
|
15114
15148
|
program.hook("preAction", () => {
|
|
15115
15149
|
const opts = program.opts();
|