koishi-plugin-lili-hub 0.2.1 → 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 +44 -8
- 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
|
}
|
|
@@ -749,8 +749,19 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
749
749
|
const textLen = normalizedText.length;
|
|
750
750
|
const botId = session.bot.userId || session.bot.selfId;
|
|
751
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
|
+
}
|
|
752
764
|
if (config.dedup.enabled && isGroupAllowed(gid, config.dedup.groups)) {
|
|
753
|
-
const isFwd = isForwardMessage(session);
|
|
754
765
|
dbg("\u67E5\u91CD-\u4E2D\u95F4\u4EF6\u5165\u53E3", {
|
|
755
766
|
gid,
|
|
756
767
|
userId: session.userId,
|
|
@@ -758,10 +769,9 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
758
769
|
dedupEnabled: true,
|
|
759
770
|
isForward: isFwd,
|
|
760
771
|
contentPreview: normalizedText.substring(0, 50),
|
|
761
|
-
|
|
772
|
+
forwardTextsCount: forwardTexts.length
|
|
762
773
|
});
|
|
763
774
|
if (isFwd) {
|
|
764
|
-
const forwardTexts = extractForwardTexts(session);
|
|
765
775
|
const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1e3;
|
|
766
776
|
dbg("\u67E5\u91CD\u68C0\u6D4B", { gid, forwardTextsCount: forwardTexts.length });
|
|
767
777
|
for (const fwdText of forwardTexts) {
|
|
@@ -781,7 +791,7 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
781
791
|
if (forwardTexts.length === 0 && session.elements) {
|
|
782
792
|
const nodeIds = [];
|
|
783
793
|
for (const el of session.elements) {
|
|
784
|
-
if (el.type === "node" && el.attrs?.id && !el.attrs?.content) {
|
|
794
|
+
if ((el.type === "node" || el.type === "forward") && el.attrs?.id && !el.attrs?.content) {
|
|
785
795
|
nodeIds.push(el.attrs.id);
|
|
786
796
|
}
|
|
787
797
|
}
|
|
@@ -824,6 +834,7 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
824
834
|
userId: session.userId,
|
|
825
835
|
textLen,
|
|
826
836
|
normalizedText: normalizedText.substring(0, 30),
|
|
837
|
+
forwardTextsCount: forwardTexts.length,
|
|
827
838
|
shouldRecordAll,
|
|
828
839
|
foldInGroup,
|
|
829
840
|
dedupInGroup,
|
|
@@ -831,9 +842,34 @@ ${import_koishi.segment.at(targetId)} \u5DF2\u88AB\u89E3\u9664\u7981\u8A00\u3002
|
|
|
831
842
|
inRecordGroups: recordGroups.size === 0 || recordGroups.has(gid),
|
|
832
843
|
shouldRecord
|
|
833
844
|
});
|
|
834
|
-
if (shouldRecord &&
|
|
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) {
|
|
835
864
|
try {
|
|
836
|
-
await ctx.database.create("lili_message", {
|
|
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
|
+
});
|
|
837
873
|
dbg("\u6D88\u606F\u5DF2\u5165\u5E93", { gid, userId: session.userId, contentLen: normalizedText.length, messageId: session.messageId });
|
|
838
874
|
} catch (e) {
|
|
839
875
|
dbg("\u6D88\u606F\u5165\u5E93\u5931\u8D25", { gid, error: String(e) });
|