koishi-plugin-cs2-server-query 1.8.2 → 1.8.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.
Files changed (2) hide show
  1. package/lib/index.js +55 -32
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -124,6 +124,15 @@ function apply(ctx, config) {
124
124
  }
125
125
  }
126
126
  __name(checkAndAddMapTranslation, "checkAndAddMapTranslation");
127
+ let autoSaveMapStatus = {};
128
+ const autoSaveMapStatusFilePath = import_path.default.resolve(__dirname, "auto-save-map-status.json");
129
+ if (import_fs.default.existsSync(autoSaveMapStatusFilePath)) {
130
+ autoSaveMapStatus = JSON.parse(import_fs.default.readFileSync(autoSaveMapStatusFilePath, "utf-8"));
131
+ }
132
+ function saveAutoSaveMapStatus() {
133
+ import_fs.default.writeFileSync(autoSaveMapStatusFilePath, JSON.stringify(autoSaveMapStatus, null, 2));
134
+ }
135
+ __name(saveAutoSaveMapStatus, "saveAutoSaveMapStatus");
127
136
  const difficultyColors = {
128
137
  "未知": "#3C3C3C",
129
138
  "简单": "#33cc00",
@@ -744,47 +753,61 @@ ${subscriptionList}`;
744
753
  __name(similarity, "similarity");
745
754
  ctx.setInterval(async () => {
746
755
  for (const group of groups) {
747
- for (const server of group.servers) {
748
- try {
749
- const info = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
750
- const newMap = info.map;
751
- if (server.map !== newMap) {
752
- server.mapChangeTime = Date.now();
753
- server.map = newMap;
754
- checkAndAddMapTranslation(newMap, mapTranslations);
755
- const relevantSubscriptions = subscriptions.filter((sub) => sub.groupName === group.name);
756
- for (const sub of relevantSubscriptions) {
757
- const mapNameToCompare = sub.mapName;
758
- const translatedMapName = mapTranslations[mapNameToCompare]?.translation;
759
- let matchPercentage = 0;
760
- if (translatedMapName) {
761
- matchPercentage = similarity(newMap, mapNameToCompare);
762
- } else {
763
- matchPercentage = similarity(newMap, mapNameToCompare);
764
- }
765
- if (matchPercentage >= 80 && canPush(server.ip, mapNameToCompare)) {
766
- const imageBuffer = await generatePushImage(server, mapTranslations);
767
- const message = `connect ${server.ip}`;
768
- const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
769
- const combinedMessage = [
770
- import_koishi.h.image(imageBuffer, "image/png"),
771
- // 图片
772
- message
773
- // 文字
774
- ];
775
- await sendMessageToTarget(ctx, targetId, sub.pushType, combinedMessage, sub.userId);
776
- updatePushRecord(server.ip, mapNameToCompare);
756
+ if (autoSaveMapStatus[group.name]) {
757
+ for (const server of group.servers) {
758
+ try {
759
+ const info = await (0, import_steam_server_query.queryGameServerInfo)(server.ip);
760
+ const newMap = info.map;
761
+ if (server.map !== newMap) {
762
+ server.mapChangeTime = Date.now();
763
+ server.map = newMap;
764
+ checkAndAddMapTranslation(newMap, mapTranslations);
765
+ const relevantSubscriptions = subscriptions.filter((sub) => sub.groupName === group.name);
766
+ for (const sub of relevantSubscriptions) {
767
+ const mapNameToCompare = sub.mapName;
768
+ const translatedMapName = mapTranslations[mapNameToCompare]?.translation;
769
+ let matchPercentage = 0;
770
+ if (translatedMapName) {
771
+ matchPercentage = similarity(newMap, mapNameToCompare);
772
+ } else {
773
+ matchPercentage = similarity(newMap, mapNameToCompare);
774
+ }
775
+ if (matchPercentage >= 80 && canPush(server.ip, mapNameToCompare)) {
776
+ const imageBuffer = await generatePushImage(server, mapTranslations);
777
+ const message = `connect ${server.ip}`;
778
+ const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
779
+ const combinedMessage = [
780
+ import_koishi.h.image(imageBuffer, "image/png"),
781
+ // 图片
782
+ message
783
+ // 文字
784
+ ];
785
+ await sendMessageToTarget(ctx, targetId, sub.pushType, combinedMessage, sub.userId);
786
+ updatePushRecord(server.ip, mapNameToCompare);
787
+ }
777
788
  }
778
789
  }
790
+ } catch (err) {
791
+ server.status = "离线";
779
792
  }
780
- } catch (err) {
781
- server.status = "离线";
782
793
  }
783
794
  }
784
795
  }
785
796
  await handleOfflineServers(groups);
786
797
  saveData();
787
798
  }, 6e4);
799
+ ctx.command("cs2地图保存 <groupName> <status>", "开启或关闭指定社区的自动保存地图功能").action((_, groupName, status) => {
800
+ if (status !== "打开" && status !== "关闭") {
801
+ return '状态无效,请使用 "打开" 或 "关闭"。';
802
+ }
803
+ const group = groups.find((g) => g.name === groupName);
804
+ if (!group) {
805
+ return "未找到该社区。";
806
+ }
807
+ autoSaveMapStatus[groupName] = status === "打开";
808
+ saveAutoSaveMapStatus();
809
+ return `社区 "${groupName}" 的自动保存地图功能已${status}。`;
810
+ });
788
811
  }
789
812
  __name(apply, "apply");
790
813
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cs2-server-query",
3
3
  "description": "自用,不推荐下载",
4
- "version": "1.8.2",
4
+ "version": "1.8.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [