koishi-plugin-lili-hub 0.2.2 → 0.3.0
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/lib/index.js +80 -64
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -313,31 +313,6 @@ function isForwardMessage(session) {
|
|
|
313
313
|
}
|
|
314
314
|
return false;
|
|
315
315
|
}
|
|
316
|
-
function extractNodeText(nodeData) {
|
|
317
|
-
if (!nodeData) return "";
|
|
318
|
-
if (nodeData.id && !nodeData.content) return "";
|
|
319
|
-
const c = nodeData.content;
|
|
320
|
-
if (!c) return "";
|
|
321
|
-
if (typeof c === "string") return normalizeText(c);
|
|
322
|
-
if (Array.isArray(c)) {
|
|
323
|
-
return normalizeText(
|
|
324
|
-
c.filter((seg) => seg.type === "text").map((seg) => seg.data?.text || "").join("")
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
return "";
|
|
328
|
-
}
|
|
329
|
-
function extractForwardTexts(session) {
|
|
330
|
-
const results = [];
|
|
331
|
-
if (session.elements) {
|
|
332
|
-
for (const el of session.elements) {
|
|
333
|
-
if (el.type === "node" || el.type === "forward") {
|
|
334
|
-
const text = extractNodeText(el.attrs);
|
|
335
|
-
if (text) results.push(text);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return results;
|
|
340
|
-
}
|
|
341
316
|
function extractTarget(session, cmdArg) {
|
|
342
317
|
if (session.elements) {
|
|
343
318
|
const atEl = session.elements.find((el) => el.type === "at" && el.attrs?.id);
|
|
@@ -504,8 +479,8 @@ function apply(ctx, config) {
|
|
|
504
479
|
try {
|
|
505
480
|
const history = await ctx.database.get("lili_roulette", { gid }, { sort: { timestamp: "desc" }, limit: config.roulette.maxHistoryRounds });
|
|
506
481
|
const allHitUsers = /* @__PURE__ */ new Set();
|
|
507
|
-
for (const
|
|
508
|
-
if (
|
|
482
|
+
for (const h2 of history) {
|
|
483
|
+
if (h2.hitUserId) allHitUsers.add(h2.hitUserId);
|
|
509
484
|
}
|
|
510
485
|
const pool = [...allHitUsers].filter((u) => u !== session.userId);
|
|
511
486
|
if (pool.length > 0) {
|
|
@@ -751,14 +726,80 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
751
726
|
if (botId && String(session.userId) === String(botId)) return next();
|
|
752
727
|
const isFwd = isForwardMessage(session);
|
|
753
728
|
let forwardTexts = [];
|
|
729
|
+
async function fetchForwardTextsRecursive(msgId, depth) {
|
|
730
|
+
if (depth > 3) return [];
|
|
731
|
+
const results = [];
|
|
732
|
+
try {
|
|
733
|
+
const resp = await (session.onebot?.internal || session.bot?.internal)?.getForwardMsg?.(msgId);
|
|
734
|
+
if (!resp) return results;
|
|
735
|
+
let nodes = [];
|
|
736
|
+
if (Array.isArray(resp)) {
|
|
737
|
+
nodes = resp;
|
|
738
|
+
} else if (resp?.messages && Array.isArray(resp.messages)) {
|
|
739
|
+
nodes = resp.messages;
|
|
740
|
+
} else if (resp?.data?.messages && Array.isArray(resp.data.messages)) {
|
|
741
|
+
nodes = resp.data.messages;
|
|
742
|
+
} else if (resp?.data && Array.isArray(resp.data)) {
|
|
743
|
+
nodes = resp.data;
|
|
744
|
+
}
|
|
745
|
+
for (const node of nodes) {
|
|
746
|
+
const content2 = node.content || node.data && node.data.content;
|
|
747
|
+
if (Array.isArray(content2)) {
|
|
748
|
+
const text = normalizeText(
|
|
749
|
+
content2.filter((seg) => seg.type === "text").map((seg) => seg.data?.text || "").join("")
|
|
750
|
+
);
|
|
751
|
+
if (text) results.push(text);
|
|
752
|
+
for (const seg of content2) {
|
|
753
|
+
if (seg.type === "image") {
|
|
754
|
+
const fileId = seg.data?.file || seg.data?.url || "";
|
|
755
|
+
if (fileId) results.push(`[img:${fileId}]`);
|
|
756
|
+
}
|
|
757
|
+
if (seg.type === "face") {
|
|
758
|
+
const faceId = seg.data?.id || "";
|
|
759
|
+
if (faceId) results.push(`[face:${faceId}]`);
|
|
760
|
+
}
|
|
761
|
+
if (seg.type === "mface") {
|
|
762
|
+
const emojiId = seg.data?.emoji_id || seg.data?.emojiId || "";
|
|
763
|
+
if (emojiId) results.push(`[mface:${emojiId}]`);
|
|
764
|
+
}
|
|
765
|
+
if ((seg.type === "forward" || seg.type === "node") && seg.data?.id) {
|
|
766
|
+
const nested = await fetchForwardTextsRecursive(String(seg.data.id), depth + 1);
|
|
767
|
+
results.push(...nested);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
} else if (typeof content2 === "string") {
|
|
771
|
+
const text = normalizeText(content2);
|
|
772
|
+
if (text) results.push(text);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
} catch (e) {
|
|
776
|
+
dbg("\u9012\u5F52\u83B7\u53D6\u8F6C\u53D1\u6D88\u606F\u5931\u8D25", { gid, msgId, error: String(e) });
|
|
777
|
+
}
|
|
778
|
+
return results;
|
|
779
|
+
}
|
|
754
780
|
if (isFwd) {
|
|
755
|
-
|
|
781
|
+
const topNodeIds = [];
|
|
782
|
+
if (session.elements) {
|
|
783
|
+
for (const el of session.elements) {
|
|
784
|
+
if ((el.type === "node" || el.type === "forward") && el.attrs?.id) {
|
|
785
|
+
topNodeIds.push(String(el.attrs.id));
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (topNodeIds.length > 0) {
|
|
790
|
+
dbg("\u8F6C\u53D1\u6D88\u606F-\u5F00\u59CB\u9012\u5F52\u83B7\u53D6", { gid, topNodeIds });
|
|
791
|
+
for (const msgId of topNodeIds) {
|
|
792
|
+
const texts = await fetchForwardTextsRecursive(msgId, 1);
|
|
793
|
+
forwardTexts.push(...texts);
|
|
794
|
+
}
|
|
795
|
+
forwardTexts = [...new Set(forwardTexts)];
|
|
796
|
+
}
|
|
756
797
|
dbg("\u8F6C\u53D1\u6D88\u606F\u68C0\u6D4B", {
|
|
757
798
|
gid,
|
|
758
799
|
userId: session.userId,
|
|
759
800
|
elementTypes: session.elements?.map((e) => e.type) || [],
|
|
760
801
|
forwardTextsCount: forwardTexts.length,
|
|
761
|
-
forwardTextsPreview: forwardTexts.slice(0,
|
|
802
|
+
forwardTextsPreview: forwardTexts.slice(0, 5).map((t) => t.substring(0, 30))
|
|
762
803
|
});
|
|
763
804
|
}
|
|
764
805
|
if (config.dedup.enabled && isGroupAllowed(gid, config.dedup.groups)) {
|
|
@@ -771,7 +812,7 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
771
812
|
contentPreview: normalizedText.substring(0, 50),
|
|
772
813
|
forwardTextsCount: forwardTexts.length
|
|
773
814
|
});
|
|
774
|
-
if (isFwd) {
|
|
815
|
+
if (isFwd && forwardTexts.length > 0) {
|
|
775
816
|
const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
|
|
776
817
|
dbg("\u67E5\u91CD\u68C0\u6D4B", { gid, forwardTextsCount: forwardTexts.length });
|
|
777
818
|
for (const fwdText of forwardTexts) {
|
|
@@ -782,40 +823,15 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
782
823
|
if (matches && matches.length > 0 && matches[0].timestamp >= sevenDaysAgo) {
|
|
783
824
|
const original = matches[0];
|
|
784
825
|
const dateStr = new Date(original.timestamp).toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
|
785
|
-
await session.send(
|
|
826
|
+
await session.send([
|
|
827
|
+
(0, import_koishi.h)("quote", { id: original.messageId }),
|
|
828
|
+
(0, import_koishi.h)("at", { id: session.userId }),
|
|
829
|
+
import_koishi.h.text(` \u{1F4A7} \u6C34\u8FC7\u4E86\uFF01\u8FD9\u6761\u6D88\u606F\u5728 ${dateStr} \u5C31\u53D1\u8FC7\u4E86\uFF01`)
|
|
830
|
+
]);
|
|
786
831
|
return next();
|
|
787
832
|
}
|
|
788
|
-
} catch {
|
|
789
|
-
|
|
790
|
-
}
|
|
791
|
-
if (forwardTexts.length === 0 && session.elements) {
|
|
792
|
-
const nodeIds = [];
|
|
793
|
-
for (const el of session.elements) {
|
|
794
|
-
if ((el.type === "node" || el.type === "forward") && el.attrs?.id && !el.attrs?.content) {
|
|
795
|
-
nodeIds.push(el.attrs.id);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
if (nodeIds.length > 0) {
|
|
799
|
-
dbg("\u67E5\u91CD-\u901A\u8FC7 get_forward_msg \u83B7\u53D6\u8282\u70B9\u5185\u5BB9", { gid, nodeIds });
|
|
800
|
-
for (const msgId of nodeIds) {
|
|
801
|
-
try {
|
|
802
|
-
const resp = await (session.onebot?.internal || session.bot?.internal)?.getForwardMsg?.(msgId);
|
|
803
|
-
if (resp?.messages) {
|
|
804
|
-
for (const node of resp.messages) {
|
|
805
|
-
const nodeText = normalizeText(typeof node.content === "string" ? node.content : "");
|
|
806
|
-
if (!nodeText) continue;
|
|
807
|
-
const matches = await ctx.database.get("lili_message", { gid, content: nodeText }, { sort: { timestamp: "asc" }, limit: 1 });
|
|
808
|
-
if (matches && matches.length > 0 && matches[0].timestamp >= sevenDaysAgo) {
|
|
809
|
-
const original = matches[0];
|
|
810
|
-
const dateStr = new Date(original.timestamp).toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
|
811
|
-
await session.send(`\u{1F4A7} \u6C34\u8FC7\u4E86\uFF01${import_koishi.segment.at(session.userId)} \u8FD9\u6761\u6D88\u606F ${import_koishi.segment.at(original.userId)} \u5728 ${dateStr} \u5C31\u53D1\u8FC7\u4E86\uFF01`);
|
|
812
|
-
return next();
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
} catch {
|
|
817
|
-
}
|
|
818
|
-
}
|
|
833
|
+
} catch (e) {
|
|
834
|
+
dbg("\u67E5\u91CD\u67E5\u8BE2\u5F02\u5E38", { gid, error: String(e) });
|
|
819
835
|
}
|
|
820
836
|
}
|
|
821
837
|
}
|
|
@@ -854,13 +870,13 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
854
870
|
timestamp: Date.now(),
|
|
855
871
|
messageId: session.messageId || ""
|
|
856
872
|
});
|
|
857
|
-
dbg("\u8F6C\u53D1\u6D88\u606F\
|
|
873
|
+
dbg("\u8F6C\u53D1\u6D88\u606F\u5185\u5BB9\u5DF2\u5165\u5E93", { gid, userId: session.userId, contentLen: fwdText.length, content: fwdText });
|
|
858
874
|
} catch (e) {
|
|
859
875
|
dbg("\u8F6C\u53D1\u6D88\u606F\u5165\u5E93\u5931\u8D25", { gid, error: String(e) });
|
|
860
876
|
}
|
|
861
877
|
}
|
|
862
878
|
}
|
|
863
|
-
if (shouldRecord && !isFwd && normalizedText) {
|
|
879
|
+
if (shouldRecord && !isFwd && normalizedText && textLen >= 15 && textLen <= 60) {
|
|
864
880
|
try {
|
|
865
881
|
await ctx.database.create("lili_message", {
|
|
866
882
|
gid,
|