koishi-plugin-cs2-server-query 2.6.0 → 2.6.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 +41 -23
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -437,22 +437,45 @@ function apply(ctx, config) {
|
|
|
437
437
|
const relevantSubs = subscriptions.filter(
|
|
438
438
|
(sub) => sub.groupName === group.name && sub.mapName === newMap && canPush(server.ip, newMap)
|
|
439
439
|
);
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
440
|
+
if (relevantSubs.length === 0) return;
|
|
441
|
+
const groupedSubs = {};
|
|
442
|
+
relevantSubs.forEach((sub) => {
|
|
443
|
+
const key = sub.pushType === "群聊" ? `group_${sub.channelId}` : `private_${sub.userId}`;
|
|
444
|
+
if (!groupedSubs[key]) {
|
|
445
|
+
groupedSubs[key] = [];
|
|
446
|
+
}
|
|
447
|
+
groupedSubs[key].push(sub);
|
|
448
|
+
});
|
|
449
|
+
for (const [key, subs] of Object.entries(groupedSubs)) {
|
|
450
|
+
if (subs[0].pushType === "私聊") {
|
|
451
|
+
for (const sub of subs) {
|
|
452
|
+
const image = await generatePushImage(server, mapTranslations);
|
|
453
|
+
const message = [
|
|
454
|
+
import_koishi.h.image(image, "image/png"),
|
|
455
|
+
`connect ${server.ip}`
|
|
456
|
+
];
|
|
457
|
+
await sendMessageToTarget(
|
|
458
|
+
ctx,
|
|
459
|
+
sub.userId,
|
|
460
|
+
"私聊",
|
|
461
|
+
message,
|
|
462
|
+
sub.userId
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
} else {
|
|
466
|
+
const channelId = subs[0].channelId;
|
|
467
|
+
const userIds = subs.map((sub) => sub.userId);
|
|
468
|
+
const image = await generatePushImage(server, mapTranslations);
|
|
469
|
+
const atUsers = userIds.map((userId) => import_koishi.h.at(userId)).join(" ");
|
|
470
|
+
const message = [
|
|
471
|
+
atUsers,
|
|
472
|
+
import_koishi.h.image(image, "image/png"),
|
|
473
|
+
`connect ${server.ip}`
|
|
474
|
+
];
|
|
475
|
+
await ctx.bots[0].sendMessage(channelId, message);
|
|
476
|
+
}
|
|
455
477
|
}
|
|
478
|
+
updatePushRecord(server.ip, newMap);
|
|
456
479
|
}
|
|
457
480
|
__name(processMapChange, "processMapChange");
|
|
458
481
|
async function handleOfflineServers(groups2) {
|
|
@@ -1087,14 +1110,9 @@ ${mapList}
|
|
|
1087
1110
|
__name(calculateDifficultyStats, "calculateDifficultyStats");
|
|
1088
1111
|
async function sendMessageToTarget(ctx2, targetId, pushType, message, userId) {
|
|
1089
1112
|
try {
|
|
1090
|
-
if (pushType === "
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
if (Array.isArray(message)) {
|
|
1094
|
-
const combinedMessage = (0, import_koishi.h)("message", message);
|
|
1095
|
-
await sendSingleMessage(ctx2, targetId, pushType, combinedMessage);
|
|
1096
|
-
} else {
|
|
1097
|
-
await sendSingleMessage(ctx2, targetId, pushType, message);
|
|
1113
|
+
if (pushType === "私聊") {
|
|
1114
|
+
const finalMessage = Array.isArray(message) ? (0, import_koishi.h)("message", message) : message;
|
|
1115
|
+
await ctx2.bots[0].sendPrivateMessage(targetId, finalMessage);
|
|
1098
1116
|
}
|
|
1099
1117
|
} catch (err) {
|
|
1100
1118
|
ctx2.logger("cs2-server-query").error(`发送消息失败: ${err.message}`);
|