koishi-plugin-cs2-server-query 2.1.0 → 2.3.0

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 -65
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -302,7 +302,7 @@ function apply(ctx, config) {
302
302
  const recentCount = (mapStats[group.name]?.[server.map] || []).filter(
303
303
  (ts) => Date.now() - ts <= 7 * 24 * 60 * 60 * 1e3
304
304
  ).length;
305
- const isHot = recentCount >= 20;
305
+ const isHot = recentCount >= 15;
306
306
  return `
307
307
 
308
308
  <tr>
@@ -419,6 +419,33 @@ function apply(ctx, config) {
419
419
  return screenshot;
420
420
  }
421
421
  __name(generatePushImage, "generatePushImage");
422
+ async function processMapChange(group, server, newMap) {
423
+ checkAndAddMapTranslation(newMap, mapTranslations);
424
+ if (!mapStats[group.name]) mapStats[group.name] = {};
425
+ if (!mapStats[group.name][newMap]) mapStats[group.name][newMap] = [];
426
+ mapStats[group.name][newMap].push(Date.now());
427
+ saveMapStats();
428
+ const relevantSubs = subscriptions.filter(
429
+ (sub) => sub.groupName === group.name && sub.mapName === newMap && canPush(server.ip, newMap)
430
+ );
431
+ for (const sub of relevantSubs) {
432
+ const image = await generatePushImage(server, mapTranslations);
433
+ const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
434
+ const message = [
435
+ import_koishi.h.image(image, "image/png"),
436
+ `connect ${server.ip}`
437
+ ];
438
+ await sendMessageToTarget(
439
+ ctx,
440
+ targetId,
441
+ sub.pushType,
442
+ message,
443
+ sub.userId
444
+ );
445
+ updatePushRecord(server.ip, newMap);
446
+ }
447
+ }
448
+ __name(processMapChange, "processMapChange");
422
449
  async function handleOfflineServers(groups2) {
423
450
  for (const group of groups2) {
424
451
  for (const server of group.servers) {
@@ -434,30 +461,7 @@ function apply(ctx, config) {
434
461
  server.status = "在线";
435
462
  if (oldMap !== newMap) {
436
463
  server.mapChangeTime = Date.now();
437
- checkAndAddMapTranslation(newMap, mapTranslations);
438
- if (!mapStats[group.name]) mapStats[group.name] = {};
439
- if (!mapStats[group.name][newMap]) mapStats[group.name][newMap] = [];
440
- mapStats[group.name][newMap].push(Date.now());
441
- saveMapStats();
442
- const relevantSubs = subscriptions.filter(
443
- (sub) => sub.groupName === group.name && sub.mapName === newMap && canPush(server.ip, newMap)
444
- );
445
- for (const sub of relevantSubs) {
446
- const image = await generatePushImage(server, mapTranslations);
447
- const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
448
- const message = [
449
- import_koishi.h.image(image, "image/png"),
450
- `connect ${server.ip}`
451
- ];
452
- await sendMessageToTarget(
453
- ctx,
454
- targetId,
455
- sub.pushType,
456
- message,
457
- sub.userId
458
- );
459
- updatePushRecord(server.ip, newMap);
460
- }
464
+ await processMapChange(group, server, newMap);
461
465
  }
462
466
  } catch (err) {
463
467
  server.status = "离线";
@@ -716,7 +720,7 @@ connect ${server.ip}`;
716
720
  }
717
721
  return next();
718
722
  });
719
- ctx.command("cs2订阅 <groupName> <mapInput> [pushType]", "订阅指定社区服务器的地图,需输入以下指定社区名称:EXG 风云社 僵尸乐园 UB社区 ZE国际服 X社区,在指令后面加上空格-a可以直接订阅所有社区,例:cs2订阅 EXG FF -a").option("all", "-a 订阅所有社区服务器").action(async ({ session, options }, groupName, mapInput, pushType = "私聊") => {
723
+ ctx.command("cs2订阅 <groupName> <mapInput> [pushType]", "订阅指定社区服务器的地图,需输入以下指定社区名称:EXG 风云社 僵尸乐园 UB社区 ZE国际服 X社区,在指令后面加上空格-a可一次性直接订阅所有社区推送,例:cs2订阅 EXG FF 群聊或私聊 -a,注:私聊推送需要添加芙兰好友才能正常推送。群聊推送无需添加,默认是群聊推送。").option("all", "-a 订阅所有社区服务器").action(async ({ session, options }, groupName, mapInput, pushType = "群聊") => {
720
724
  const userId = session.userId;
721
725
  const channelId = session.channelId;
722
726
  if (pushType !== "私聊" && pushType !== "群聊") {
@@ -782,7 +786,7 @@ ${mapList}
782
786
  const userId = session.userId;
783
787
  if (options.all) groupName = null;
784
788
  if (!options.all && !groupName) return "参数不足,请提供以下指定社区名称:EXG 风云社 僵尸乐园 UB社区 ZE国际服 X社区,以及地图名,末端可使用 -a 取消所有社区订阅。例:cs2取消订阅 EXG 狮子王 -a";
785
- if (!mapInput) return "参数不足,请提供以下指定社区名称:EXG 风云社 僵尸乐园 UB社区 ZE国际服 X社区,以及地图名,末端可使用 -a 取消所有社区订阅。例:cs2取消订阅 EXG 狮子王 -a";
789
+ if (!mapInput) return "参数不足,请提供以下指定社区名称:EXG 风云社 僵尸乐园 UB社区 ZE国际服 X社区,以及地图名,末端可使用 -a 取消所有社区订阅。例:cs2取消订阅 EXG 狮子王 群聊/私聊 -a";
786
790
  const matchedMaps = fuzzyMatchMap(mapInput);
787
791
  if (matchedMaps.length === 0) return "未找到匹配的地图。";
788
792
  if (matchedMaps.length > 1) {
@@ -1104,47 +1108,11 @@ ${mapList}
1104
1108
  try {
1105
1109
  const info = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
1106
1110
  const newMap = info.map;
1111
+ const oldMap = server.map;
1107
1112
  if (server.map !== newMap) {
1108
- const oldMap = server.map;
1109
1113
  server.mapChangeTime = Date.now();
1110
1114
  server.map = newMap;
1111
- checkAndAddMapTranslation(newMap, mapTranslations);
1112
- const globalSubs = subscriptions.filter(
1113
- (sub) => sub.mapName === newMap && sub.groupName === group.name
1114
- );
1115
- for (const sub of globalSubs) {
1116
- const mapNameToCompare = sub.mapName;
1117
- const translatedMapName = mapTranslations[mapNameToCompare]?.translation;
1118
- let matchPercentage = 0;
1119
- if (server.map !== newMap) {
1120
- server.mapChangeTime = Date.now();
1121
- server.map = newMap;
1122
- if (!mapStats[group.name]) {
1123
- mapStats[group.name] = {};
1124
- }
1125
- if (!mapStats[group.name][newMap]) {
1126
- mapStats[group.name][newMap] = [];
1127
- }
1128
- mapStats[group.name][newMap].push(Date.now());
1129
- saveMapStats();
1130
- }
1131
- if (newMap === mapNameToCompare && canPush(server.ip, mapNameToCompare)) {
1132
- const imageBuffer = await generatePushImage(server, mapTranslations);
1133
- const message = `connect ${server.ip}`;
1134
- const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
1135
- const combinedMessage = [
1136
- import_koishi.h.image(imageBuffer, "image/png"),
1137
- // 图片
1138
- message
1139
- // 文字
1140
- ];
1141
- await sendMessageToTarget(ctx, targetId, sub.pushType, combinedMessage, sub.userId);
1142
- updatePushRecord(server.ip, mapNameToCompare);
1143
- }
1144
- }
1145
- if (!mapStats[group.name][newMap]) mapStats[group.name][newMap] = [];
1146
- mapStats[group.name][newMap].push(Date.now());
1147
- saveMapStats();
1115
+ await processMapChange(group, server, newMap);
1148
1116
  }
1149
1117
  server.status = "在线";
1150
1118
  server.players = info.players;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cs2-server-query",
3
3
  "description": "自用,不推荐下载",
4
- "version": "2.1.0",
4
+ "version": "2.3.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [