koishi-plugin-lili-hub 0.3.2 → 0.3.3
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 +57 -19
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1207,29 +1207,67 @@ ${formatChain(chain)}`);
|
|
|
1207
1207
|
});
|
|
1208
1208
|
if (isFwd && forwardTexts.length > 0) {
|
|
1209
1209
|
dbg("\u67E5\u91CD\u68C0\u6D4B", { gid, forwardTextsCount: forwardTexts.length });
|
|
1210
|
+
const textContents = [];
|
|
1211
|
+
const imageContents = [];
|
|
1210
1212
|
for (const fwdText of forwardTexts) {
|
|
1211
1213
|
if (!fwdText) continue;
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1214
|
+
if (fwdText.startsWith("[img:")) {
|
|
1215
|
+
imageContents.push(fwdText);
|
|
1216
|
+
} else if (fwdText.startsWith("[face:") || fwdText.startsWith("[mface:")) {
|
|
1217
|
+
} else {
|
|
1218
|
+
textContents.push(fwdText);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const sevenDaysAgoMs = Date.now() - 7 * 24 * 60 * 60 * 1e3;
|
|
1222
|
+
let recentMsgs = [];
|
|
1223
|
+
try {
|
|
1224
|
+
recentMsgs = await ctx.database.get("lili_message", { gid, timestamp: { $gte: sevenDaysAgoMs } }, { sort: { timestamp: "asc" }, limit: 1e3 });
|
|
1225
|
+
} catch (e) {
|
|
1226
|
+
dbg("\u67E5\u91CD\u67E5\u8BE2\u5F02\u5E38", { gid, error: String(e) });
|
|
1227
|
+
}
|
|
1228
|
+
let matched = null;
|
|
1229
|
+
for (const fwdText of textContents) {
|
|
1230
|
+
if (fwdText.length <= 30) continue;
|
|
1231
|
+
const match = recentMsgs.find((m) => {
|
|
1232
|
+
if (m.content === fwdText) return true;
|
|
1233
|
+
return normalizeText(m.content) === fwdText;
|
|
1234
|
+
});
|
|
1235
|
+
if (match) {
|
|
1236
|
+
matched = match;
|
|
1237
|
+
dbg("\u67E5\u91CD\u547D\u4E2D-\u6587\u5B57", { gid, fwdText: fwdText.substring(0, 50), length: fwdText.length });
|
|
1238
|
+
break;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (!matched && imageContents.length >= 2) {
|
|
1242
|
+
let imageMatchCount = 0;
|
|
1243
|
+
let firstImgMatch = null;
|
|
1244
|
+
for (const imgContent of imageContents) {
|
|
1245
|
+
const found = recentMsgs.find((m) => m.content === imgContent || normalizeText(m.content) === imgContent);
|
|
1246
|
+
if (found) {
|
|
1247
|
+
imageMatchCount++;
|
|
1248
|
+
if (!firstImgMatch) firstImgMatch = found;
|
|
1229
1249
|
}
|
|
1230
|
-
} catch (e) {
|
|
1231
|
-
dbg("\u67E5\u91CD\u67E5\u8BE2\u5F02\u5E38", { gid, error: String(e) });
|
|
1232
1250
|
}
|
|
1251
|
+
if (imageMatchCount >= 2) {
|
|
1252
|
+
matched = firstImgMatch;
|
|
1253
|
+
dbg("\u67E5\u91CD\u547D\u4E2D-\u56FE\u7247", { gid, imageMatchCount, totalImages: imageContents.length });
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
dbg("\u67E5\u91CD\u7ED3\u679C", {
|
|
1257
|
+
gid,
|
|
1258
|
+
textCount: textContents.length,
|
|
1259
|
+
imageCount: imageContents.length,
|
|
1260
|
+
matched: !!matched
|
|
1261
|
+
});
|
|
1262
|
+
if (matched) {
|
|
1263
|
+
const original = matched;
|
|
1264
|
+
const dateStr = new Date(original.timestamp).toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
|
1265
|
+
await session.send([
|
|
1266
|
+
(0, import_koishi.h)("quote", { id: original.messageId }),
|
|
1267
|
+
(0, import_koishi.h)("at", { id: session.userId }),
|
|
1268
|
+
import_koishi.h.text(` \u{1F4A7} \u6C34\u8FC7\u4E86\uFF01\u8FD9\u6761\u6D88\u606F\u5728 ${dateStr} \u5C31\u53D1\u8FC7\u4E86\uFF01`)
|
|
1269
|
+
]);
|
|
1270
|
+
return next();
|
|
1233
1271
|
}
|
|
1234
1272
|
}
|
|
1235
1273
|
}
|