koishi-plugin-prism 0.1.3 → 0.1.4

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
@@ -58,6 +58,12 @@ export type KoishiActionContext = {
58
58
  userId: string;
59
59
  senderId?: string;
60
60
  senderName?: string;
61
+ username?: string;
62
+ bot?: {
63
+ getUser?(id: string): Promise<{
64
+ name?: string;
65
+ }>;
66
+ };
61
67
  };
62
68
  };
63
69
  export declare function applyPrismKoishiPlugin(ctx: KoishiLikeContext, config: PrismKoishiPluginConfig): void;
package/lib/index.js CHANGED
@@ -64,31 +64,31 @@ function applyPrismKoishiPlugin(ctx, config) {
64
64
  return service.handleCommandError(error);
65
65
  }
66
66
  };
67
- ctx.command("register", "绑定或注册当前平台用户到 PRiSM").action(wrap(async (context) => service.register(service.sender(context))));
68
- ctx.command("login", "开启当前玩家的计费场次").action(async (context) => service.login(service.sender(context)));
69
- ctx.command("入场", "入场 (alias of login)").action(wrap(async (context) => service.login(service.sender(context))));
70
- ctx.command("mahjong <tableId>", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(service.sender(context), tableId)));
71
- ctx.command("上桌 <tableId>", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(service.sender(context), tableId)));
72
- ctx.command("下桌 <tableId>", "离开指定麻将桌").action(wrap(async (context, tableId) => service.mahjongLeave(service.sender(context), tableId)));
73
- ctx.command("logout", "结算当前玩家的计费场次").action(wrap(async (context) => service.logout(service.sender(context))));
74
- ctx.command("billing", "预览当前玩家的结账费用").action(wrap(async (context) => service.billing(service.sender(context))));
75
- ctx.command("wallet", "查看当前玩家钱包余额").action(wrap(async (context) => service.wallet(service.sender(context))));
76
- ctx.command("items", "查看当前玩家持有资产").action(wrap(async (context) => service.items(service.sender(context))));
77
- ctx.command("list", "查看当前在线玩家列表").action(wrap(async (context) => service.listActiveSessions(service.sender(context))));
67
+ ctx.command("register", "绑定或注册当前平台用户到 PRiSM").action(wrap(async (context) => service.register(await service.sender(context))));
68
+ ctx.command("login", "开启当前玩家的计费场次").action(wrap(async (context) => service.login(await service.sender(context))));
69
+ ctx.command("入场", "入场 (alias of login)").action(wrap(async (context) => service.login(await service.sender(context))));
70
+ ctx.command("mahjong <tableId>", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
71
+ ctx.command("上桌 <tableId>", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
72
+ ctx.command("下桌 <tableId>", "离开指定麻将桌").action(wrap(async (context, tableId) => service.mahjongLeave(await service.sender(context), tableId)));
73
+ ctx.command("logout", "结算当前玩家的计费场次").action(wrap(async (context) => service.logout(await service.sender(context))));
74
+ ctx.command("billing", "预览当前玩家的结账费用").action(wrap(async (context) => service.billing(await service.sender(context))));
75
+ ctx.command("wallet", "查看当前玩家钱包余额").action(wrap(async (context) => service.wallet(await service.sender(context))));
76
+ ctx.command("items", "查看当前玩家持有资产").action(wrap(async (context) => service.items(await service.sender(context))));
77
+ ctx.command("list", "查看当前在线玩家列表").action(wrap(async (context) => service.listActiveSessions(await service.sender(context))));
78
78
  ctx.command("show [deviceId]", "查看设备电源状态").action(wrap(async (context, deviceId) => service.listDeviceStates(deviceId)));
79
- ctx.command("history", "查看当前玩家历史场次").action(wrap(async (context) => service.history(service.sender(context))));
80
- ctx.command("lock", "向默认门锁设备发送开门指令").action(wrap(async (context) => service.lock(service.sender(context))));
81
- ctx.command("on <deviceId>", "请求启动指定设备电源").action(wrap(async (context, deviceId) => service.powerOn(service.sender(context), deviceId)));
82
- ctx.command("off <deviceId>", "请求关闭指定设备电源").action(wrap(async (context, deviceId) => service.powerOff(service.sender(context), deviceId)));
83
- ctx.command("coin <deviceId> [count]", "请求向指定设备投币").action(wrap(async (context, deviceId, count) => service.coin(service.sender(context), deviceId, count)));
84
- ctx.command("scan <deviceId> <subject>", "请求指定设备模拟刷卡").action(wrap(async (context, deviceId, subject) => service.scan(service.sender(context), deviceId, subject)));
85
- ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(service.sender(context), code)));
79
+ ctx.command("history", "查看当前玩家历史场次").action(wrap(async (context) => service.history(await service.sender(context))));
80
+ ctx.command("lock", "向默认门锁设备发送开门指令").action(wrap(async (context) => service.lock(await service.sender(context))));
81
+ ctx.command("on <deviceId>", "请求启动指定设备电源").action(wrap(async (context, deviceId) => service.powerOn(await service.sender(context), deviceId)));
82
+ ctx.command("off <deviceId>", "请求关闭指定设备电源").action(wrap(async (context, deviceId) => service.powerOff(await service.sender(context), deviceId)));
83
+ ctx.command("coin <deviceId> [count]", "请求向指定设备投币").action(wrap(async (context, deviceId, count) => service.coin(await service.sender(context), deviceId, count)));
84
+ ctx.command("scan <deviceId> <subject>", "请求指定设备模拟刷卡").action(wrap(async (context, deviceId, subject) => service.scan(await service.sender(context), deviceId, subject)));
85
+ ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(await service.sender(context), code)));
86
86
  if (config.enableStaffCommands) {
87
- ctx.command("admin.players", "列出 PRiSM 玩家").action(wrap(async (context) => service.staffPlayers(service.sender(context))));
88
- ctx.command("admin.create-player <displayName>", "创建 PRiSM 玩家").action(wrap(async (context, displayName) => service.staffCreatePlayer(service.sender(context), displayName)));
89
- ctx.command("admin.grant-balance <playerId> <amount>", "给指定玩家发放充值余额").action(wrap(async (context, playerId, amount) => service.staffGrantBalance(service.sender(context), playerId, amount)));
90
- ctx.command("admin.redeem-code <code> <presentId>", "创建单次使用兑换码").action(wrap(async (context, code, presentId) => service.staffRedeemCode(service.sender(context), code, presentId)));
91
- ctx.command("admin.checkout <playerId>", "替指定玩家结账").action(wrap(async (context, playerId) => service.staffCheckout(service.sender(context), playerId)));
87
+ ctx.command("admin.players", "列出 PRiSM 玩家").action(wrap(async (context) => service.staffPlayers(await service.sender(context))));
88
+ ctx.command("admin.create-player <displayName>", "创建 PRiSM 玩家").action(wrap(async (context, displayName) => service.staffCreatePlayer(await service.sender(context), displayName)));
89
+ ctx.command("admin.grant-balance <playerId> <amount>", "给指定玩家发放充值余额").action(wrap(async (context, playerId, amount) => service.staffGrantBalance(await service.sender(context), playerId, amount)));
90
+ ctx.command("admin.redeem-code <code> <presentId>", "创建单次使用兑换码").action(wrap(async (context, code, presentId) => service.staffRedeemCode(await service.sender(context), code, presentId)));
91
+ ctx.command("admin.checkout <playerId>", "替指定玩家结账").action(wrap(async (context, playerId) => service.staffCheckout(await service.sender(context), playerId)));
92
92
  }
93
93
  const intervalMs = (config.powerOffInterval ?? 0) * 1000;
94
94
  if (intervalMs > 0 && typeof ctx.setInterval === "function") {
@@ -351,9 +351,20 @@ class PrismKoishiService {
351
351
  });
352
352
  }
353
353
  }
354
- sender(context) {
354
+ async sender(context) {
355
355
  const id = context.session?.senderId || context.session?.userId || "";
356
- const name = context.session?.senderName || id;
356
+ let name = id;
357
+ try {
358
+ if (context.session?.bot?.getUser) {
359
+ const user = await context.session.bot.getUser(id);
360
+ if (user?.name) {
361
+ name = user.name;
362
+ }
363
+ }
364
+ }
365
+ catch {
366
+ name = context.session?.username || context.session?.senderName || id;
367
+ }
357
368
  return { id, name };
358
369
  }
359
370
  async register(sender) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "PRiSM Next 计费与设备管理系统的 Koishi 机器人集成插件",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {