koishi-plugin-lili-hub 0.2.0 → 0.2.2
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 +73 -11
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -308,7 +308,7 @@ function getRandomMuteDuration(cfg) {
|
|
|
308
308
|
function isForwardMessage(session) {
|
|
309
309
|
if (session.elements) {
|
|
310
310
|
for (const el of session.elements) {
|
|
311
|
-
if (el.type === "node") return true;
|
|
311
|
+
if (el.type === "node" || el.type === "forward") return true;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
return false;
|
|
@@ -330,7 +330,7 @@ function extractForwardTexts(session) {
|
|
|
330
330
|
const results = [];
|
|
331
331
|
if (session.elements) {
|
|
332
332
|
for (const el of session.elements) {
|
|
333
|
-
if (el.type === "node") {
|
|
333
|
+
if (el.type === "node" || el.type === "forward") {
|
|
334
334
|
const text = extractNodeText(el.attrs);
|
|
335
335
|
if (text) results.push(text);
|
|
336
336
|
}
|
|
@@ -747,9 +747,31 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
747
747
|
const plainText = session.elements ? session.elements.filter((el) => el.type === "text").map((el) => el.attrs?.content || "").join("").trim() : content.replace(/<[^>]+>/g, "").trim();
|
|
748
748
|
const normalizedText = normalizeText(plainText);
|
|
749
749
|
const textLen = normalizedText.length;
|
|
750
|
+
const botId = session.bot.userId || session.bot.selfId;
|
|
751
|
+
if (botId && String(session.userId) === String(botId)) return next();
|
|
752
|
+
const isFwd = isForwardMessage(session);
|
|
753
|
+
let forwardTexts = [];
|
|
754
|
+
if (isFwd) {
|
|
755
|
+
forwardTexts = extractForwardTexts(session);
|
|
756
|
+
dbg("\u8F6C\u53D1\u6D88\u606F\u68C0\u6D4B", {
|
|
757
|
+
gid,
|
|
758
|
+
userId: session.userId,
|
|
759
|
+
elementTypes: session.elements?.map((e) => e.type) || [],
|
|
760
|
+
forwardTextsCount: forwardTexts.length,
|
|
761
|
+
forwardTextsPreview: forwardTexts.slice(0, 3).map((t) => t.substring(0, 30))
|
|
762
|
+
});
|
|
763
|
+
}
|
|
750
764
|
if (config.dedup.enabled && isGroupAllowed(gid, config.dedup.groups)) {
|
|
751
|
-
|
|
752
|
-
|
|
765
|
+
dbg("\u67E5\u91CD-\u4E2D\u95F4\u4EF6\u5165\u53E3", {
|
|
766
|
+
gid,
|
|
767
|
+
userId: session.userId,
|
|
768
|
+
textLen,
|
|
769
|
+
dedupEnabled: true,
|
|
770
|
+
isForward: isFwd,
|
|
771
|
+
contentPreview: normalizedText.substring(0, 50),
|
|
772
|
+
forwardTextsCount: forwardTexts.length
|
|
773
|
+
});
|
|
774
|
+
if (isFwd) {
|
|
753
775
|
const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
|
|
754
776
|
dbg("\u67E5\u91CD\u68C0\u6D4B", { gid, forwardTextsCount: forwardTexts.length });
|
|
755
777
|
for (const fwdText of forwardTexts) {
|
|
@@ -769,7 +791,7 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
769
791
|
if (forwardTexts.length === 0 && session.elements) {
|
|
770
792
|
const nodeIds = [];
|
|
771
793
|
for (const el of session.elements) {
|
|
772
|
-
if (el.type === "node" && el.attrs?.id && !el.attrs?.content) {
|
|
794
|
+
if ((el.type === "node" || el.type === "forward") && el.attrs?.id && !el.attrs?.content) {
|
|
773
795
|
nodeIds.push(el.attrs.id);
|
|
774
796
|
}
|
|
775
797
|
}
|
|
@@ -798,19 +820,59 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
798
820
|
}
|
|
799
821
|
}
|
|
800
822
|
}
|
|
801
|
-
const botId = session.bot.userId || session.bot.selfId;
|
|
802
|
-
if (botId && String(session.userId) === String(botId)) return next();
|
|
803
823
|
const imitationGroups = parseGroupList(config.imitation.groups);
|
|
804
824
|
const dedupGroups = parseGroupList(config.dedup.groups);
|
|
805
825
|
const foldGroups = config.fold.enabled ? parseGroupList(config.fold.groups) : [];
|
|
806
|
-
const
|
|
826
|
+
const dedupInGroup = config.dedup.enabled && isGroupAllowed(gid, config.dedup.groups);
|
|
827
|
+
const foldInGroup = config.fold.enabled && isGroupAllowed(gid, config.fold.groups);
|
|
828
|
+
const shouldRecordAll = foldInGroup || dedupInGroup;
|
|
807
829
|
const shouldRecordLimited = textLen >= 15 && textLen <= 60 && normalizedText;
|
|
808
830
|
const recordGroups = /* @__PURE__ */ new Set([...imitationGroups, ...dedupGroups, ...foldGroups]);
|
|
809
831
|
const shouldRecord = shouldRecordAll || shouldRecordLimited && (recordGroups.size === 0 || recordGroups.has(gid));
|
|
810
|
-
|
|
832
|
+
dbg("\u8BB0\u5F55\u6D88\u606F\u5224\u5B9A", {
|
|
833
|
+
gid,
|
|
834
|
+
userId: session.userId,
|
|
835
|
+
textLen,
|
|
836
|
+
normalizedText: normalizedText.substring(0, 30),
|
|
837
|
+
forwardTextsCount: forwardTexts.length,
|
|
838
|
+
shouldRecordAll,
|
|
839
|
+
foldInGroup,
|
|
840
|
+
dedupInGroup,
|
|
841
|
+
shouldRecordLimited,
|
|
842
|
+
inRecordGroups: recordGroups.size === 0 || recordGroups.has(gid),
|
|
843
|
+
shouldRecord
|
|
844
|
+
});
|
|
845
|
+
if (shouldRecord && isFwd && forwardTexts.length > 0) {
|
|
846
|
+
for (const fwdText of forwardTexts) {
|
|
847
|
+
if (!fwdText) continue;
|
|
848
|
+
try {
|
|
849
|
+
await ctx.database.create("lili_message", {
|
|
850
|
+
gid,
|
|
851
|
+
userId: session.userId,
|
|
852
|
+
userName: session.username || session.userId,
|
|
853
|
+
content: fwdText,
|
|
854
|
+
timestamp: Date.now(),
|
|
855
|
+
messageId: session.messageId || ""
|
|
856
|
+
});
|
|
857
|
+
dbg("\u8F6C\u53D1\u6D88\u606F\u6587\u5B57\u5DF2\u5165\u5E93", { gid, userId: session.userId, contentLen: fwdText.length });
|
|
858
|
+
} catch (e) {
|
|
859
|
+
dbg("\u8F6C\u53D1\u6D88\u606F\u5165\u5E93\u5931\u8D25", { gid, error: String(e) });
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (shouldRecord && !isFwd && normalizedText) {
|
|
811
864
|
try {
|
|
812
|
-
await ctx.database.create("lili_message", {
|
|
813
|
-
|
|
865
|
+
await ctx.database.create("lili_message", {
|
|
866
|
+
gid,
|
|
867
|
+
userId: session.userId,
|
|
868
|
+
userName: session.username || session.userId,
|
|
869
|
+
content: normalizedText,
|
|
870
|
+
timestamp: Date.now(),
|
|
871
|
+
messageId: session.messageId || ""
|
|
872
|
+
});
|
|
873
|
+
dbg("\u6D88\u606F\u5DF2\u5165\u5E93", { gid, userId: session.userId, contentLen: normalizedText.length, messageId: session.messageId });
|
|
874
|
+
} catch (e) {
|
|
875
|
+
dbg("\u6D88\u606F\u5165\u5E93\u5931\u8D25", { gid, error: String(e) });
|
|
814
876
|
}
|
|
815
877
|
}
|
|
816
878
|
if (config.imitation.enabled && isGroupAllowed(gid, config.imitation.groups)) {
|