koishi-plugin-cs2-server-query 2.6.6 → 2.6.7

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 +52 -0
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -154,6 +154,45 @@ function apply(ctx, config) {
154
154
  saveMapStats();
155
155
  }
156
156
  __name(cleanupOldEntries, "cleanupOldEntries");
157
+ function resolveGroupNameByCommand(rawCommand) {
158
+ if (commandMappings[rawCommand]) return commandMappings[rawCommand];
159
+ const lowerCommand = rawCommand.toLowerCase();
160
+ const matched = Object.entries(commandMappings).find(
161
+ ([cmd]) => cmd.toLowerCase() === lowerCommand
162
+ );
163
+ return matched ? matched[1] : null;
164
+ }
165
+ __name(resolveGroupNameByCommand, "resolveGroupNameByCommand");
166
+ function buildWeeklyZEMapReport(groupName) {
167
+ const groupStats = mapStats[groupName];
168
+ if (!groupStats) {
169
+ return `社区 "${groupName}" 最近7天暂无地图统计数据。`;
170
+ }
171
+ const now = Date.now();
172
+ const sevenDaysAgo = now - 7 * 24 * 60 * 60 * 1e3;
173
+ const topMaps = Object.entries(groupStats).filter(([mapName]) => /^ze/i.test(mapName)).map(([mapName, timestamps]) => ({
174
+ mapName,
175
+ count: timestamps.filter((ts) => ts >= sevenDaysAgo).length
176
+ })).filter((item) => item.count > 0).sort((a, b) => b.count - a.count || a.mapName.localeCompare(b.mapName)).slice(0, 10);
177
+ if (!topMaps.length) {
178
+ return `社区 "${groupName}" 最近7天暂无 ze 开头地图记录。`;
179
+ }
180
+ const totalCount = topMaps.reduce((sum, item) => sum + item.count, 0);
181
+ const dateRange = `${new Date(sevenDaysAgo).toLocaleDateString("zh-CN")} - ${new Date(now).toLocaleDateString("zh-CN")}`;
182
+ return [
183
+ `${groupName} 地图周报(ZEmap Top10)`,
184
+ `统计周期:${dateRange}`,
185
+ "",
186
+ ...topMaps.map((item, index) => {
187
+ const translation = mapTranslations[item.mapName]?.translation;
188
+ const translated = translation ? ` (${translation})` : "";
189
+ return `${index + 1}. ${item.mapName}${translated} - ${item.count} 次`;
190
+ }),
191
+ "",
192
+ `Top10 合计出现次数:${totalCount} 次`
193
+ ].join("\n");
194
+ }
195
+ __name(buildWeeklyZEMapReport, "buildWeeklyZEMapReport");
157
196
  ctx.setInterval(() => {
158
197
  cleanupOldEntries();
159
198
  }, 24 * 60 * 60 * 1e3);
@@ -535,6 +574,13 @@ function apply(ctx, config) {
535
574
  __name(handleOfflineServers, "handleOfflineServers");
536
575
  ctx.middleware(async (session, next) => {
537
576
  const content = session.content.trim();
577
+ const weeklyReportMatch = content.match(/^(.+?)周报$/);
578
+ if (weeklyReportMatch) {
579
+ const reportCommand = weeklyReportMatch[1].trim();
580
+ const groupName2 = resolveGroupNameByCommand(reportCommand);
581
+ if (!groupName2) return next();
582
+ return buildWeeklyZEMapReport(groupName2);
583
+ }
538
584
  const commandMatch = content.match(/^(.+?)(\s+(\d+))?$/);
539
585
  if (!commandMatch) return next();
540
586
  const command = commandMatch[1];
@@ -701,6 +747,12 @@ connect ${server.ip}`;
701
747
  if (Object.keys(commandMappings).length === 0) return "未找到任何指令映射。";
702
748
  return `指令映射列表:${Object.entries(commandMappings).map(([command, groupName]) => `${command} -> ${groupName}`).join(", ")}`;
703
749
  });
750
+ ctx.command("cs2周报 <groupCommand>", "查看指定社区最近7天 ze 地图出现次数 Top10(例:cs2周报 exg)").action((_, groupCommand) => {
751
+ if (!groupCommand) return "请提供社区指令,例如:cs2周报 exg";
752
+ const groupName = resolveGroupNameByCommand(groupCommand.trim());
753
+ if (!groupName) return `未找到指令 "${groupCommand}" 对应的社区。`;
754
+ return buildWeeklyZEMapReport(groupName);
755
+ });
704
756
  function fuzzyMatchMap(input) {
705
757
  const lowerInput = input.toLowerCase();
706
758
  const maps = Object.keys(mapTranslations);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cs2-server-query",
3
3
  "description": "自用,不推荐下载",
4
- "version": "2.6.6",
4
+ "version": "2.6.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [