koishi-plugin-cs2-server-query 2.6.4 → 2.6.5
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 +33 -49
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -434,59 +434,52 @@ function apply(ctx, config) {
|
|
|
434
434
|
if (!mapStats[group.name][newMap]) mapStats[group.name][newMap] = [];
|
|
435
435
|
mapStats[group.name][newMap].push(Date.now());
|
|
436
436
|
saveMapStats();
|
|
437
|
-
const
|
|
437
|
+
const matchedSubs = subscriptions.filter(
|
|
438
438
|
(sub) => sub.groupName === group.name && sub.mapName === newMap && canPush(server.ip, newMap)
|
|
439
439
|
);
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (!groupedSubs[targetId]) {
|
|
447
|
-
groupedSubs[targetId] = {
|
|
440
|
+
if (matchedSubs.length === 0) return;
|
|
441
|
+
const pushGroups = /* @__PURE__ */ new Map();
|
|
442
|
+
for (const sub of matchedSubs) {
|
|
443
|
+
const key = sub.pushType === "私聊" ? `private:${sub.userId}` : `group:${sub.channelId}`;
|
|
444
|
+
if (!pushGroups.has(key)) {
|
|
445
|
+
pushGroups.set(key, {
|
|
448
446
|
pushType: sub.pushType,
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (!groupedSubs[targetId].users.includes(sub.userId)) {
|
|
453
|
-
groupedSubs[targetId].users.push(sub.userId);
|
|
447
|
+
channelId: sub.channelId,
|
|
448
|
+
users: /* @__PURE__ */ new Set()
|
|
449
|
+
});
|
|
454
450
|
}
|
|
451
|
+
pushGroups.get(key).users.add(sub.userId);
|
|
455
452
|
}
|
|
456
|
-
|
|
457
|
-
|
|
453
|
+
const image = await generatePushImage(server, mapTranslations);
|
|
454
|
+
for (const groupInfo of pushGroups.values()) {
|
|
458
455
|
if (groupInfo.pushType === "私聊") {
|
|
459
|
-
for (const
|
|
460
|
-
const message = [
|
|
461
|
-
import_koishi.h.image(image, "image/png"),
|
|
462
|
-
`connect ${server.ip}`
|
|
463
|
-
];
|
|
456
|
+
for (const uid of groupInfo.users) {
|
|
464
457
|
await sendMessageToTarget(
|
|
465
458
|
ctx,
|
|
466
|
-
|
|
459
|
+
uid,
|
|
467
460
|
"私聊",
|
|
468
|
-
|
|
469
|
-
|
|
461
|
+
[
|
|
462
|
+
import_koishi.h.image(image, "image/png"),
|
|
463
|
+
`connect ${server.ip}`
|
|
464
|
+
],
|
|
465
|
+
uid
|
|
470
466
|
);
|
|
471
467
|
}
|
|
472
468
|
} else {
|
|
473
|
-
const
|
|
474
|
-
const message = [
|
|
475
|
-
atUsers,
|
|
476
|
-
import_koishi.h.image(image, "image/png"),
|
|
477
|
-
`connect ${server.ip}`
|
|
478
|
-
];
|
|
469
|
+
const atAll = Array.from(groupInfo.users).map((uid) => import_koishi.h.at(uid));
|
|
479
470
|
await sendMessageToTarget(
|
|
480
471
|
ctx,
|
|
481
|
-
|
|
472
|
+
groupInfo.channelId,
|
|
482
473
|
"群聊",
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
474
|
+
[
|
|
475
|
+
...atAll,
|
|
476
|
+
import_koishi.h.image(image, "image/png"),
|
|
477
|
+
`connect ${server.ip}`
|
|
478
|
+
]
|
|
486
479
|
);
|
|
487
480
|
}
|
|
488
|
-
updatePushRecord(server.ip, newMap);
|
|
489
481
|
}
|
|
482
|
+
updatePushRecord(server.ip, newMap);
|
|
490
483
|
}
|
|
491
484
|
__name(processMapChange, "processMapChange");
|
|
492
485
|
async function handleOfflineServers(groups2) {
|
|
@@ -1120,20 +1113,11 @@ ${mapList}
|
|
|
1120
1113
|
}
|
|
1121
1114
|
__name(calculateDifficultyStats, "calculateDifficultyStats");
|
|
1122
1115
|
async function sendMessageToTarget(ctx2, targetId, pushType, message, userId) {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
if (pushType === "群聊" && userId) {
|
|
1129
|
-
const atMessage = import_koishi.h.at(userId) + " " + message;
|
|
1130
|
-
await sendSingleMessage(ctx2, targetId, pushType, atMessage);
|
|
1131
|
-
} else {
|
|
1132
|
-
await sendSingleMessage(ctx2, targetId, pushType, message);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
} catch (err) {
|
|
1136
|
-
ctx2.logger("cs2-server-query").error(`发送消息失败: ${err.message}`);
|
|
1116
|
+
const finalMessage = Array.isArray(message) ? (0, import_koishi.h)("message", message) : message;
|
|
1117
|
+
if (pushType === "私聊") {
|
|
1118
|
+
await ctx2.bots[0].sendPrivateMessage(targetId, finalMessage);
|
|
1119
|
+
} else {
|
|
1120
|
+
await ctx2.bots[0].sendMessage(targetId, finalMessage);
|
|
1137
1121
|
}
|
|
1138
1122
|
}
|
|
1139
1123
|
__name(sendMessageToTarget, "sendMessageToTarget");
|