koishi-plugin-prism 0.1.22 → 0.1.23

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/README.md CHANGED
@@ -75,6 +75,7 @@ pricingConfigIds: [pricing-mahjong-a]
75
75
  * `mahjong <tableId>` / `上桌 [tableId]` - 加入指定麻将桌;`/上桌` 未提供桌号时会引导查看 `/麻将列表`。仅允许已通过 `login`/`入场` 开启默认入场会话的玩家使用。
76
76
  * `下桌` - 自动离开当前所在麻将桌。
77
77
  * `麻将列表` - 查看已配置机器的桌名、命令别名,以及空闲、等位或游玩中状态。
78
+ * `api测速 [次数]` - 连续查询自己的钱包,显示 Bot 到 PRiSM API 的最小、平均与最大延迟(默认 3 次,最多 10 次)。
78
79
 
79
80
  ### 管理员快捷指令
80
81
  启用 `enableStaffCommands`、配置 `staffUserIds` 白名单与 `staffSessionToken` 后可使用:
package/lib/index.js CHANGED
@@ -52,6 +52,7 @@ const USAGE = {
52
52
  mahjong_join: "/上桌 <桌号>",
53
53
  mahjong_leave: "/下桌",
54
54
  mahjong_list: "/麻将列表",
55
+ api_benchmark: "/api测速 [次数]",
55
56
  prism_on: "/prism on <设备ID>",
56
57
  prism_off: "/prism off <设备ID|all>",
57
58
  prism_coin: "/prism coin <设备ID> [数量]",
@@ -82,6 +83,7 @@ function applyPrismKoishiPlugin(ctx, config) {
82
83
  ctx.command("logout [target:user]", "结算玩家计费场次").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.logout(sender, context.session?.bot), context.session?.bot)));
83
84
  ctx.command("billing [target:user]", "预览玩家结账费用").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.billing(sender), context.session?.bot)));
84
85
  ctx.command("wallet [target:user]", "查看玩家钱包").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.wallet(sender), context.session?.bot)));
86
+ ctx.command("api测速 [count:number]", "测试 Bot 到 PRiSM API 的钱包查询延迟").action(wrap(async (context, count) => service.benchmarkApi(await service.sender(context), count)));
85
87
  ctx.command("items [target:user]", "查看玩家资产").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.items(sender), context.session?.bot)));
86
88
  ctx.command("list", "查看当前在线玩家列表").action(wrap(async (context) => service.listActiveSessions(await service.sender(context))));
87
89
  ctx.command("show [deviceId]", "查看设备电源状态").action(wrap(async (context, deviceId) => service.listDeviceStates(deviceId)));
@@ -544,6 +546,26 @@ class PrismKoishiService {
544
546
  const result = (await this.client.getWalletByIdentity(this.identity(sender)));
545
547
  return formatWallet(result, this.config.currencyName);
546
548
  }
549
+ async benchmarkApi(sender, rawCount) {
550
+ const count = rawCount == null || rawCount === "" ? 3 : Number(rawCount);
551
+ if (!Number.isInteger(count) || count < 1 || count > 10)
552
+ return "次数须为 1 到 10 的整数。";
553
+ const samples = [];
554
+ for (let index = 0; index < count; index++) {
555
+ const startedAt = performance.now();
556
+ await this.client.getWalletByIdentity(this.identity(sender));
557
+ samples.push(performance.now() - startedAt);
558
+ }
559
+ const min = Math.min(...samples);
560
+ const max = Math.max(...samples);
561
+ const average = samples.reduce((sum, sample) => sum + sample, 0) / samples.length;
562
+ return [
563
+ `📡 PRiSM API 测速(钱包查询,${count} 次)`,
564
+ `最小:${formatNumber(min)} ms`,
565
+ `平均:${formatNumber(average)} ms`,
566
+ `最大:${formatNumber(max)} ms`,
567
+ ].join("\n");
568
+ }
547
569
  async items(sender) {
548
570
  const holdings = extractRows((await this.client.getAssetsByIdentity(this.identity(sender))));
549
571
  if (holdings.length === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "PRiSM Next 计费与设备管理系统的 Koishi 机器人集成插件",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {