koishi-plugin-csss 1.2.0 → 2.0.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.
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Context, Schema } from 'koishi';
2
- export declare const name = "cs-server-status";
2
+ export declare const name = "csss";
3
+ export declare const inject: string[];
3
4
  export interface Config {
4
5
  timeout: number;
5
6
  cacheTime: number;
@@ -14,15 +15,6 @@ export interface Config {
14
15
  fontFamily: string;
15
16
  serverList: string[];
16
17
  batchTimeout: number;
17
- scheduleEnabled: boolean;
18
- scheduleInterval: number;
19
- scheduleStartTime: string;
20
- scheduleEndTime: string;
21
- scheduleGroups: string[];
22
- scheduleUseImage: boolean;
23
- qqAdapterName: string;
24
- useFullChannelId: boolean;
25
18
  }
26
19
  export declare const Config: Schema<Config>;
27
20
  export declare function apply(ctx: Context, config: Config): void;
28
- export declare const inject: string[];
package/lib/index.js CHANGED
@@ -27,7 +27,8 @@ __export(src_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
29
  var import_koishi = require("koishi");
30
- var name = "cs-server-status";
30
+ var name = "csss";
31
+ var inject = ["canvas", "gamedig", "database"];
31
32
  var Config = import_koishi.Schema.object({
32
33
  timeout: import_koishi.Schema.number().min(1e3).max(3e4).default(5e3).description("查询超时时间(毫秒)"),
33
34
  cacheTime: import_koishi.Schema.number().min(0).max(3e5).default(3e4).description("缓存时间(毫秒,0为禁用缓存)"),
@@ -39,24 +40,15 @@ var Config = import_koishi.Schema.object({
39
40
  imageWidth: import_koishi.Schema.number().min(600).max(2e3).default(1200).description("图片宽度(像素)"),
40
41
  imageHeight: import_koishi.Schema.number().min(200).max(2500).default(500).description("图片最小高度(像素),实际高度会根据内容自适应"),
41
42
  fontSize: import_koishi.Schema.number().min(12).max(48).default(24).description("字体大小"),
42
- fontFamily: import_koishi.Schema.string().default("Microsoft YaHei, sans-serif").description("字体家族"),
43
- serverList: import_koishi.Schema.array(import_koishi.Schema.string()).role("table").description("批量查询服务器列表(格式: 地址:端口,每行一个)").default([
43
+ fontFamily: import_koishi.Schema.string().default('"JetBrains Mono", monospace').description("字体"),
44
+ serverList: import_koishi.Schema.array(import_koishi.Schema.string()).role("table").description("批量查询服务器列表(格式: [地址]:[端口],每行一个)").default([
44
45
  "edgebug.cn:27015",
45
46
  "edgebug.cn:27016",
46
47
  "edgebug.cn:27017",
47
- "edgebug.cn:27018"
48
+ "edgebug.cn:27018",
49
+ "edgebug.cn:27019"
48
50
  ]),
49
- batchTimeout: import_koishi.Schema.number().min(1e3).max(6e4).default(15e3).description("批量查询总超时时间(毫秒)"),
50
- // 定时任务配置
51
- scheduleEnabled: import_koishi.Schema.boolean().default(false).description("是否启用定时自动查询功能"),
52
- scheduleInterval: import_koishi.Schema.number().min(1).max(1440).default(5).description("定时查询间隔时间(分钟)"),
53
- scheduleStartTime: import_koishi.Schema.string().pattern(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/).default("08:00").description("定时任务开始时间(24小时制,格式: HH:MM)"),
54
- scheduleEndTime: import_koishi.Schema.string().pattern(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/).default("23:00").description("定时任务结束时间(24小时制,格式: HH:MM)"),
55
- scheduleGroups: import_koishi.Schema.array(import_koishi.Schema.string()).role("table").description("定时发送的群组ID列表(每行一个群组ID)").default([]),
56
- scheduleUseImage: import_koishi.Schema.boolean().default(true).description("定时任务是否使用图片格式输出"),
57
- // QQ适配器配置
58
- qqAdapterName: import_koishi.Schema.string().default("qq").description('QQ适配器名称(默认为"qq",如果在QQ配置中指定了其他名称请修改)'),
59
- useFullChannelId: import_koishi.Schema.boolean().default(true).description("是否使用完整的频道ID格式(推荐开启)")
51
+ batchTimeout: import_koishi.Schema.number().min(1e3).max(6e4).default(15e3).description("批量查询总超时时间(毫秒)")
60
52
  });
61
53
  var COLORS = {
62
54
  background: "rgba(28,28,31,0.80)",
@@ -109,28 +101,10 @@ var utils = {
109
101
  if (ms < 1e3) return `${ms}ms`;
110
102
  if (ms < 6e4) return `${(ms / 1e3).toFixed(1)}秒`;
111
103
  return `${(ms / 1e3).toFixed(0)}秒`;
112
- },
113
- parseTimeToMinutes(timeStr) {
114
- const [hours, minutes] = timeStr.split(":").map(Number);
115
- return hours * 60 + minutes;
116
- },
117
- isWithinScheduleTime(startTime, endTime) {
118
- const now = /* @__PURE__ */ new Date();
119
- const currentMinutes = now.getHours() * 60 + now.getMinutes();
120
- const startMinutes = this.parseTimeToMinutes(startTime);
121
- const endMinutes = this.parseTimeToMinutes(endTime);
122
- return currentMinutes >= startMinutes && currentMinutes <= endMinutes;
123
- },
124
- formatGroupId(groupId, adapterName, useFullChannelId) {
125
- if (useFullChannelId) {
126
- return `${adapterName}:${groupId}`;
127
- }
128
- return groupId;
129
104
  }
130
105
  };
131
106
  function apply(ctx, config) {
132
107
  const cache = /* @__PURE__ */ new Map();
133
- let scheduleTimer = null;
134
108
  if (!ctx.gamedig) {
135
109
  console.error("koishi-plugin-gamedig 未安装或未启用");
136
110
  return ctx.logger("cs-server-status").error("需要安装并启用 koishi-plugin-gamedig 插件");
@@ -175,7 +149,7 @@ function apply(ctx, config) {
175
149
  message += `✅ 成功: ${successful} 个 | ❌ 失败: ${failed} 个
176
150
 
177
151
  `;
178
- message += "序号 服务器名称 在线人数\n";
152
+ message += "序号 服务器名称 在线人数\n";
179
153
  message += "──────────────────────────────\n";
180
154
  results.forEach((result, index) => {
181
155
  const serverInfo = serversToQuery[index];
@@ -202,77 +176,6 @@ function apply(ctx, config) {
202
176
  return message;
203
177
  }
204
178
  __name(generateTextTable, "generateTextTable");
205
- async function executeScheduleTask() {
206
- if (!config.scheduleEnabled || config.scheduleGroups.length === 0 || config.serverList.length === 0) {
207
- return;
208
- }
209
- if (!utils.isWithinScheduleTime(config.scheduleStartTime, config.scheduleEndTime)) {
210
- return;
211
- }
212
- try {
213
- const { results, queryTime, serversToQuery } = await queryServers(config.serverList);
214
- const now = /* @__PURE__ */ new Date();
215
- const timeStr = now.toLocaleString("zh-CN");
216
- let outputContent;
217
- if (config.scheduleUseImage) {
218
- try {
219
- const imageBuffer = await generateBatchImage(results, serversToQuery, queryTime);
220
- outputContent = import_koishi.h.image(imageBuffer, "image/png");
221
- } catch (imageError) {
222
- console.error("定时任务生成图片失败:", imageError);
223
- outputContent = `🕒 ${timeStr} 服务器状态更新
224
- 生成图片失败,使用文本格式:
225
-
226
- `;
227
- }
228
- }
229
- if (typeof outputContent === "string" || !config.scheduleUseImage) {
230
- const textMessage = generateTextTable(results, serversToQuery, queryTime, "服务器状态更新");
231
- outputContent = `🕒 ${timeStr}
232
-
233
- ${textMessage}`;
234
- }
235
- for (const groupId of config.scheduleGroups) {
236
- try {
237
- const formattedGroupId = utils.formatGroupId(groupId, config.qqAdapterName, config.useFullChannelId);
238
- await ctx.broadcast([formattedGroupId], outputContent);
239
- console.log(`定时任务消息已发送到群组: ${formattedGroupId}`);
240
- } catch (error) {
241
- console.error(`定时任务发送消息到群组 ${groupId} 失败:`, error);
242
- }
243
- }
244
- } catch (error) {
245
- console.error("定时任务执行失败:", error);
246
- }
247
- }
248
- __name(executeScheduleTask, "executeScheduleTask");
249
- function startScheduleTask() {
250
- if (scheduleTimer) {
251
- clearInterval(scheduleTimer);
252
- }
253
- if (config.scheduleEnabled && config.scheduleInterval > 0) {
254
- const intervalMs = config.scheduleInterval * 60 * 1e3;
255
- executeScheduleTask();
256
- scheduleTimer = setInterval(executeScheduleTask, intervalMs);
257
- console.log(`定时任务已启动,间隔: ${config.scheduleInterval}分钟,时间范围: ${config.scheduleStartTime}-${config.scheduleEndTime}`);
258
- }
259
- }
260
- __name(startScheduleTask, "startScheduleTask");
261
- function stopScheduleTask() {
262
- if (scheduleTimer) {
263
- clearInterval(scheduleTimer);
264
- scheduleTimer = null;
265
- console.log("定时任务已停止");
266
- }
267
- }
268
- __name(stopScheduleTask, "stopScheduleTask");
269
- ctx.on("config", () => {
270
- if (config.scheduleEnabled) {
271
- startScheduleTask();
272
- } else {
273
- stopScheduleTask();
274
- }
275
- });
276
179
  function parseAddress(input) {
277
180
  let address = input.replace(/^(http|https|udp|tcp):\/\//, "");
278
181
  if (address.includes("[")) {
@@ -292,7 +195,7 @@ ${textMessage}`;
292
195
  return { host: parts[0], port: 27015 };
293
196
  }
294
197
  throw new Error(`无效的地址格式: ${input}
295
- 正确格式: 地址:端口地址`);
198
+ 正确格式: [地址]:[端口][地址]`);
296
199
  }
297
200
  __name(parseAddress, "parseAddress");
298
201
  async function queryServer(host, port) {
@@ -434,7 +337,7 @@ ${textMessage}`;
434
337
  drawPlayerList(ctx2, players, startY, width, maxHeight, params) {
435
338
  let y = startY;
436
339
  if (players.length === 0) {
437
- this.drawText(ctx2, "服务器当前无在线玩家", 80, y, { color: COLORS.textLight });
340
+ this.drawText(ctx2, "服务器当前无玩家在线", 80, y, { color: COLORS.textLight });
438
341
  return { y: y + 35, displayedCount: 0 };
439
342
  }
440
343
  const sortedPlayers = [...players].sort((a, b) => {
@@ -494,7 +397,7 @@ ${textMessage}`;
494
397
  return { y, displayedCount: displayPlayers.length };
495
398
  }
496
399
  },
497
- // 统一边框绘制函数
400
+ // 边框绘制函数
498
401
  drawBorder(ctx2, width, height) {
499
402
  this.drawDivider(ctx2, 1, 1, width - 1, 1, COLORS.border, 2);
500
403
  this.drawDivider(ctx2, width - 1, 1, width - 1, height - 1, COLORS.border, 2);
@@ -554,7 +457,7 @@ ${textMessage}`;
554
457
  if (result.name) {
555
458
  const cleanName = utils.cleanName(result.name);
556
459
  const fontSize = imageUtils.calculateServerNameFontSize(ctx2d, cleanName, width - 160, config.fontSize);
557
- imageUtils.drawTitle(ctx2d, cleanName, width / 2, titleY + 50, fontSize * 0.8, config.fontFamily, COLORS.highlight);
460
+ imageUtils.drawTitle(ctx2d, cleanName, width / 2, titleY + 50, fontSize * 1.8, config.fontFamily, COLORS.highlight);
558
461
  }
559
462
  imageUtils.drawDivider(ctx2d, 80, titleY + 80, width - 80, titleY + 80, COLORS.border, 2);
560
463
  let y = titleY + 120;
@@ -664,122 +567,8 @@ ${textMessage}`;
664
567
  return canvas.toBuffer("image/png");
665
568
  }
666
569
  __name(generateBatchImage, "generateBatchImage");
667
- ctx.command("cs.schedule", "定时任务管理").alias("定时任务").option("status", "-s 查看定时任务状态", { type: Boolean, fallback: false }).option("start", "-S 启动定时任务", { type: Boolean, fallback: false }).option("stop", "-T 停止定时任务", { type: Boolean, fallback: false }).option("test", "-t 测试定时任务", { type: Boolean, fallback: false }).option("addGroup", "-a <groupId> 添加群组到定时任务", { type: String }).option("removeGroup", "-r <groupId> 从定时任务移除群组", { type: String }).option("listGroups", "-l 列出定时任务群组", { type: Boolean, fallback: false }).option("run", "-R 立即执行一次定时任务", { type: Boolean, fallback: false }).option("testQQ", "-q 测试QQ适配器连接", { type: Boolean, fallback: false }).action(async ({ session, options }) => {
668
- if (options.status) {
669
- const status = config.scheduleEnabled ? "✅ 已启用" : "❌ 已禁用";
670
- const nextRun = scheduleTimer ? "运行中" : "未运行";
671
- const groups = config.scheduleGroups.length;
672
- const qqBots = ctx.bots.filter((bot) => bot.platform === config.qqAdapterName);
673
- const qqStatus = qqBots.length > 0 ? `✅ 可用 (${qqBots.length}个)` : "❌ 不可用";
674
- return `📅 定时任务状态
675
- 状态: ${status}
676
- 定时器: ${nextRun}
677
- 间隔: ${config.scheduleInterval}分钟
678
- 时间范围: ${config.scheduleStartTime} - ${config.scheduleEndTime}
679
- 输出格式: ${config.scheduleUseImage ? "图片" : "文本"}
680
- 监控服务器: ${config.serverList.length}个
681
- 目标群组: ${groups}个
682
- QQ适配器: ${qqStatus} (名称: ${config.qqAdapterName})
683
- 群组ID格式: ${config.useFullChannelId ? "适配器:群号" : "群号"}
684
-
685
- 使用 cs.schedule -h 查看所有命令选项`;
686
- }
687
- if (options.start) {
688
- config.scheduleEnabled = true;
689
- startScheduleTask();
690
- return "✅ 定时任务已启动";
691
- }
692
- if (options.stop) {
693
- config.scheduleEnabled = false;
694
- stopScheduleTask();
695
- return "✅ 定时任务已停止";
696
- }
697
- if (options.test) {
698
- await executeScheduleTask();
699
- return "✅ 定时任务测试执行完成";
700
- }
701
- if (options.run) {
702
- await executeScheduleTask();
703
- return "✅ 已立即执行一次定时任务";
704
- }
705
- if (options.testQQ) {
706
- const qqBots = ctx.bots.filter((bot) => bot.platform === config.qqAdapterName);
707
- if (qqBots.length === 0) {
708
- return `❌ 找不到 ${config.qqAdapterName} 适配器的机器人
709
- 请确保已正确配置QQ适配器`;
710
- }
711
- let message = `✅ 找到 ${qqBots.length} 个 ${config.qqAdapterName} 适配器机器人:
712
- `;
713
- qqBots.forEach((bot, index) => {
714
- message += `${index + 1}. ${bot.selfId} (在线: ${bot.status})
715
- `;
716
- });
717
- if (session) {
718
- try {
719
- await session.send("测试消息: QQ适配器连接正常 ✓");
720
- message += "\n✅ 当前会话消息发送测试成功";
721
- } catch (error) {
722
- message += `
723
- ❌ 当前会话消息发送失败: ${error.message}`;
724
- }
725
- }
726
- return message;
727
- }
728
- if (options.addGroup) {
729
- let groupId = options.addGroup.trim();
730
- if (config.useFullChannelId && !groupId.includes(":")) {
731
- groupId = `${config.qqAdapterName}:${groupId}`;
732
- }
733
- if (!config.scheduleGroups.includes(groupId)) {
734
- config.scheduleGroups.push(groupId);
735
- return `✅ 已添加群组 ${groupId} 到定时任务
736
- 当前列表: ${config.scheduleGroups.length} 个群组`;
737
- } else {
738
- return `❌ 群组 ${groupId} 已在列表中`;
739
- }
740
- }
741
- if (options.removeGroup) {
742
- const index = config.scheduleGroups.indexOf(options.removeGroup);
743
- if (index !== -1) {
744
- config.scheduleGroups.splice(index, 1);
745
- return `✅ 已从定时任务移除群组 ${options.removeGroup}`;
746
- } else {
747
- return `❌ 群组 ${options.removeGroup} 不在列表中`;
748
- }
749
- }
750
- if (options.listGroups) {
751
- if (config.scheduleGroups.length === 0) {
752
- return "📋 定时任务群组列表为空\n使用 cs.schedule -a <群组ID> 添加群组";
753
- }
754
- let message = "📋 定时任务群组列表:\n";
755
- config.scheduleGroups.forEach((groupId, index) => {
756
- message += `${index + 1}. ${groupId}
757
- `;
758
- });
759
- return message;
760
- }
761
- return `📅 定时任务管理命令
762
-
763
- 选项:
764
- -s, -status 查看定时任务状态
765
- -S, -start 启动定时任务
766
- -T, -stop 停止定时任务
767
- -t, -test 测试定时任务
768
- -R, -run 立即执行一次定时任务
769
- -q, -testQQ 测试QQ适配器连接
770
- -a, -addGroup 添加群组到定时任务
771
- -r, -removeGroup 从定时任务移除群组
772
- -l, -listGroups 列出定时任务群组
773
-
774
- 示例:
775
- cs.schedule -s # 查看状态
776
- cs.schedule -S # 启动定时任务
777
- cs.schedule -a 123456 # 添加群组123456
778
- cs.schedule -t # 测试执行
779
- cs.schedule -q # 测试QQ适配器连接`;
780
- });
781
570
  ctx.command("cs <address>", "查询服务器状态").alias("查询").alias("server").option("noPlayers", "-n 隐藏玩家列表", { type: Boolean, fallback: false }).option("image", "-i 生成图片横幅", { type: Boolean, fallback: false }).option("text", "-t 输出文本信息", { type: Boolean, fallback: false }).option("clear", "-c 清除缓存", { type: Boolean, fallback: false }).action(async ({ session, options }, address) => {
782
- if (!address) return "使用格式: cs [地址:端口]\n示例: cs 127.0.0.1:27015\n示例: cs edgebug.cn";
571
+ if (!address) return "使用格式: cs [地址:端口]\n示例: cs 127.0.0.1:27015 / cs edgebug.cn";
783
572
  if (options.clear) {
784
573
  const count = cache.size;
785
574
  cache.clear();
@@ -837,16 +626,10 @@ cs.schedule -q # 测试QQ适配器连接`;
837
626
  }
838
627
  }
839
628
  const cacheSize = cache.size;
840
- const scheduleStatus = config.scheduleEnabled ? "✅ 已启用" : "❌ 已禁用";
841
- const scheduleTimerStatus = scheduleTimer ? "运行中" : "未运行";
842
- const qqBots = ctx.bots.filter((bot) => bot.platform === config.qqAdapterName);
843
- const qqStatus = qqBots.length > 0 ? `✅ 可用 (${qqBots.length}个)` : "❌ 不可用";
844
629
  return `✅ CS服务器查询插件状态
845
630
  💾 缓存数量: ${cacheSize} 条
846
631
  🕹️ Gamedig插件: ${gamedigStatus}
847
632
  🖼️ Canvas插件: ${canvasStatus}
848
- 📅 定时任务: ${scheduleStatus} (${scheduleTimerStatus})
849
- 🤖 QQ适配器: ${qqStatus} (名称: ${config.qqAdapterName})
850
633
  ⚙️ 配置参数:
851
634
  超时时间: ${config.timeout}ms
852
635
  缓存时间: ${config.cacheTime}ms
@@ -857,11 +640,9 @@ cs.schedule -q # 测试QQ适配器连接`;
857
640
  生成图片横幅: ${config.generateImage ? "是" : "否"}
858
641
  图片最小高度: ${config.imageHeight}px
859
642
  字体大小: ${config.fontSize}px
860
- 群组ID格式: ${config.useFullChannelId ? "适配器:群号" : "群号"}
861
643
 
862
644
  📝 使用: cs [地址:端口]
863
- 📝 选项: -i 生成图片, -t 输出文本, -c 清除缓存
864
- 📅 定时任务: cs.schedule 查看定时任务管理`;
645
+ 📝 选项: -i 生成图片, -t 输出文本, -c 清除缓存`;
865
646
  } catch (error) {
866
647
  return `❌ 插件状态异常: ${error.message}
867
648
  请确保已安装并启用 koishi-plugin-gamedig 和 koishi-plugin-canvas 插件`;
@@ -872,9 +653,7 @@ cs.schedule -q # 测试QQ适配器连接`;
872
653
 
873
654
  📝 基本用法:
874
655
  cs [地址:端口]
875
- 示例: cs 127.0.0.1:27015
876
- 示例: cs edgebug.cn
877
-
656
+ 示例: cs 127.0.0.1:27015 / cs edgebug.cn
878
657
  🔧 选项:
879
658
  -i 生成图片横幅
880
659
  -t 输出文本信息
@@ -882,18 +661,11 @@ cs [地址:端口]
882
661
 
883
662
  🎯 快捷命令:
884
663
  csss - 批量查询服务器状态
885
- cs.schedule - 定时任务管理
886
664
 
887
665
  📋 其他命令:
888
666
  cs.status - 检查插件状态和配置
889
667
  cs.help - 显示此帮助
890
668
 
891
- 📅 定时任务:
892
- 定时自动向指定QQ群组发送服务器状态
893
- 配置: 插件配置面板中设置
894
- 管理: cs.schedule 命令
895
- 群组ID格式: ${config.useFullChannelId ? "适配器:群号 (如: qq:123456)" : "群号 (如: 123456)"}
896
-
897
669
  💡 提示:
898
670
  1. 如果不指定端口,默认使用27015
899
671
  2. 只支持CS服务器查询
@@ -960,23 +732,17 @@ cs.help - 显示此帮助
960
732
  }
961
733
  }
962
734
  let message = generateTextTable(results, serversToQuery, queryTime, "批量查询结果");
963
- message += "\n📋 输入 `cs <序号>` 查看服务器详情";
964
735
  message += "\n📋 输入 `cs <服务器地址>` 查询单个服务器";
965
736
  return message;
966
737
  } catch (error) {
967
738
  return `❌ 批量查询失败: ${error.message}`;
968
739
  }
969
740
  });
970
- if (config.scheduleEnabled) {
971
- startScheduleTask();
972
- }
973
741
  ctx.on("dispose", () => {
974
742
  cache.clear();
975
- stopScheduleTask();
976
743
  });
977
744
  }
978
745
  __name(apply, "apply");
979
- var inject = ["canvas", "gamedig", "database"];
980
746
  // Annotate the CommonJS export names for ESM import in node:
981
747
  0 && (module.exports = {
982
748
  Config,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-csss",
3
3
  "description": "Check the status of the CS server",
4
- "version": "1.2.0",
4
+ "version": "2.0.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -9,6 +9,11 @@
9
9
  "dist"
10
10
  ],
11
11
  "license": "MIT",
12
+ "homepage": "https://github.com/sanksu/koishi-plugin-csss",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/sanksu/koishi-plugin-csss.git"
16
+ },
12
17
  "keywords": [
13
18
  "chatbot",
14
19
  "koishi",