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.
Files changed (2) hide show
  1. package/lib/index.js +33 -49
  2. 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 relevantSubs = subscriptions.filter(
437
+ const matchedSubs = subscriptions.filter(
438
438
  (sub) => sub.groupName === group.name && sub.mapName === newMap && canPush(server.ip, newMap)
439
439
  );
440
- if (relevantSubs.length === 0) {
441
- return;
442
- }
443
- const groupedSubs = {};
444
- for (const sub of relevantSubs) {
445
- const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
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
- users: []
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
- for (const [targetId, groupInfo] of Object.entries(groupedSubs)) {
457
- const image = await generatePushImage(server, mapTranslations);
453
+ const image = await generatePushImage(server, mapTranslations);
454
+ for (const groupInfo of pushGroups.values()) {
458
455
  if (groupInfo.pushType === "私聊") {
459
- for (const userId of groupInfo.users) {
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
- userId,
459
+ uid,
467
460
  "私聊",
468
- message,
469
- userId
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 atUsers = groupInfo.users.map((userId) => import_koishi.h.at(userId)).join(" ");
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
- targetId,
472
+ groupInfo.channelId,
482
473
  "群聊",
483
- message,
484
- void 0
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
- try {
1124
- if (Array.isArray(message)) {
1125
- const combinedMessage = (0, import_koishi.h)("message", message);
1126
- await sendSingleMessage(ctx2, targetId, pushType, combinedMessage);
1127
- } else {
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");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "koishi-plugin-cs2-server-query",
3
3
  "private": false,
4
4
  "description": "自用,不推荐下载",
5
- "version": "2.6.4",
5
+ "version": "2.6.5",
6
6
  "main": "lib/index.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "files": [