koishi-plugin-prism-neo 0.0.5 → 0.0.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 +25 -13
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -172,6 +172,14 @@ var Config = import_koishi.Schema.object({
172
172
  url: import_koishi.Schema.string().required(),
173
173
  admin: import_koishi.Schema.string().default("authority:3")
174
174
  });
175
+ async function getUserName(session, userId) {
176
+ if (userId) {
177
+ return (await session.bot.getUser(userId)).name + `(${userId}})`;
178
+ } else {
179
+ return "匿名用户";
180
+ }
181
+ }
182
+ __name(getUserName, "getUserName");
175
183
  var handleAction = /* @__PURE__ */ __name((action) => {
176
184
  return async (argv, ...args) => {
177
185
  let message;
@@ -285,7 +293,7 @@ async function handleLoginCmd(context, user) {
285
293
  await login(context, userId);
286
294
  const pwd = await getLock(context, userId);
287
295
  if (user) {
288
- return `✅ 已为用户 ${userId} 入场,该用户的门锁密码是: ${pwd.password}
296
+ return `✅ 已为用户 ${getUserName(context.session, userId)} 入场,该用户的门锁密码是: ${pwd.password}
289
297
  注意! 门锁密码有效期为三分钟`;
290
298
  }
291
299
  return `✅ 入场成功,你的门锁密码是: ${pwd.password}
@@ -300,7 +308,7 @@ async function handleLogoutCmd(context, user) {
300
308
  if (pendingLogout && now - pendingLogout < 60 * 1e3) {
301
309
  kv.delete(targetUserId);
302
310
  const res = await logout(context, targetUserId);
303
- const messagePrefix = user ? `✅ 已为用户 ${targetUserId} 退场` : "✅ 退场成功";
311
+ const messagePrefix = user ? `✅ 已为用户 ${getUserName(context.session, targetUserId)} 退场` : "✅ 退场成功";
304
312
  return [
305
313
  messagePrefix,
306
314
  `入场时间: ${formatDateTime(res.session.createdAt)}`,
@@ -312,7 +320,7 @@ async function handleLogoutCmd(context, user) {
312
320
  const billingMessage = formatBilling(billingRes);
313
321
  kv.set(targetUserId, now);
314
322
  if (user) {
315
- return `以下是用户 ${targetUserId} 的账单预览:
323
+ return `以下是用户 ${await getUserName(context.session, targetUserId)} 的账单预览:
316
324
 
317
325
  ${billingMessage}
318
326
 
@@ -331,12 +339,16 @@ async function handleListCmd(context, user) {
331
339
  if (!users || users.length === 0) {
332
340
  return "窝里目前没有玩家呢";
333
341
  }
334
- const userReports = users.map((user2) => {
335
- const qqBind = user2.binds.find((bind) => bind.type === "QQ");
336
- const name2 = qqBind ? qqBind.bid : "匿名玩家";
342
+ const tasks = users.map((user2) => {
337
343
  const entryDate = formatDateTime(user2.sessions[0].createdAt);
338
- return `玩家: ${name2}
339
- 入场时间: ${entryDate}`;
344
+ const qqBind = user2.binds.find((bind) => bind.type === "QQ");
345
+ let id = qqBind ? qqBind.bid : null;
346
+ return { entryDate, task: getUserName(context.session, id) };
347
+ });
348
+ const platformUsers = await Promise.all(tasks.map((t) => t.task));
349
+ const userReports = platformUsers.map((u, idx) => {
350
+ return `玩家: ${u}
351
+ 入场时间: ${tasks[idx].entryDate}`;
340
352
  });
341
353
  return `窝里目前共有 ${users.length} 人
342
354
 
@@ -349,7 +361,7 @@ async function handleWalletCmd(context, user) {
349
361
  const res = await wallet(context, userId);
350
362
  const message = [];
351
363
  const targetUserId = user ? userId : void 0;
352
- message.push(targetUserId ? `--- 用户 ${targetUserId} 的钱包余额 ---` : "--- 钱包余额 ---");
364
+ message.push(targetUserId ? `--- 用户 ${await getUserName(context.session, targetUserId)} 的钱包余额 ---` : "--- 钱包余额 ---");
353
365
  message.push(
354
366
  `可用: ${res.total.available} 月饼 (共 ${res.total.all})`,
355
367
  ` - 付费: ${res.paid.available}`,
@@ -394,7 +406,7 @@ async function handleBillingCmd(context, user) {
394
406
  const res = await billing(context, userId);
395
407
  const billingMessage = formatBilling(res);
396
408
  if (user) {
397
- return `用户 ${userId} 的账单:
409
+ return `用户 ${await getUserName(context.session, userId)} 的账单:
398
410
 
399
411
  ${billingMessage}`;
400
412
  }
@@ -415,9 +427,9 @@ async function handleItemsCmd(context, user) {
415
427
  if (error) return error;
416
428
  const userAssets = await assets(context, userId);
417
429
  if (!userAssets || userAssets.length === 0) {
418
- return user ? `用户 ${userId} 没有任何物品。` : "您当前没有任何物品。";
430
+ return user ? `用户 ${await getUserName(context.session, userId)} 没有任何物品。` : "您当前没有任何物品。";
419
431
  }
420
- const header = user ? `--- 用户 ${userId} 拥有的物品 ---` : "--- 您拥有的物品 ---";
432
+ const header = user ? `--- 用户 ${await getUserName(context.session, userId)} 拥有的物品 ---` : "--- 您拥有的物品 ---";
421
433
  const itemsList = userAssets.map((asset) => {
422
434
  let line = `- ${asset.asset.name} (x${asset.count})`;
423
435
  if (asset.expireAt) {
@@ -464,7 +476,7 @@ async function handleWalletAdd(context, user, amount) {
464
476
  if (!amount) return "请输入数量";
465
477
  const res = await walletAdd(context, parseInt(amount), userId);
466
478
  return [
467
- `为用户 ${userId} 增加月饼成功`,
479
+ `为用户 ${await getUserName(context.session, userId)} 增加月饼成功`,
468
480
  `增加前: ${res.originalBalance}`,
469
481
  `增加后: ${res.finalBalance}`
470
482
  ].join("\n");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism-neo",
3
3
  "description": "prism koishi前端",
4
- "version": "0.0.5",
4
+ "version": "0.0.7",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",