koishi-plugin-prism-neo 0.0.16 → 0.0.18

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
@@ -3,6 +3,7 @@ export declare const name = "prism-neo";
3
3
  export interface Config {
4
4
  url: string;
5
5
  admin: string;
6
+ currency: string;
6
7
  }
7
8
  export declare const Config: Schema<Config>;
8
9
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -182,7 +182,8 @@ var name = "prism-neo";
182
182
  var kv = /* @__PURE__ */ new Map();
183
183
  var Config = import_koishi.Schema.object({
184
184
  url: import_koishi.Schema.string().required(),
185
- admin: import_koishi.Schema.string().default("authority:3")
185
+ admin: import_koishi.Schema.string().default("authority:3"),
186
+ currency: import_koishi.Schema.string().default("月饼").description("货币名称")
186
187
  });
187
188
  async function getUserName(session, userId) {
188
189
  if (userId) {
@@ -223,7 +224,7 @@ var formatDateTime = /* @__PURE__ */ __name((dateStr) => {
223
224
  const s = date.getSeconds().toString().padStart(2, "0");
224
225
  return `${y}/${m}/${d} ${h2}:${min}:${s}`;
225
226
  }, "formatDateTime");
226
- var formatBilling = /* @__PURE__ */ __name((res) => {
227
+ var formatBilling = /* @__PURE__ */ __name((res, currency) => {
227
228
  const message = [];
228
229
  message.push("--- 账单详情 ---");
229
230
  message.push(`入场: ${formatDateTime(res.session.createdAt)}`);
@@ -245,18 +246,18 @@ var formatBilling = /* @__PURE__ */ __name((res) => {
245
246
  if (res.session.costOverwrite) {
246
247
  finalCost = res.session.costOverwrite;
247
248
  }
248
- message.push(`计费价: ${originalCost} 月饼`);
249
+ message.push(`计费价: ${originalCost} ${currency}`);
249
250
  if (res.discount && res.discount.appliedLogs.length > 0) {
250
251
  res.discount.appliedLogs.forEach((log) => {
251
- message.push(` -「${log.asset}」: -${log.saved} 月饼`);
252
+ message.push(` -「${log.asset}」: -${log.saved} ${currency}`);
252
253
  });
253
254
  }
254
- message.push(`结算价: ${finalCost} 月饼`);
255
+ message.push(`结算价: ${finalCost} ${currency}`);
255
256
  message.push("---");
256
257
  const currentBalance = res.wallet.total.available;
257
258
  const finalBalance = currentBalance - finalCost;
258
- message.push(`当前余额: ${currentBalance} 月饼`);
259
- message.push(`扣款后: ${finalBalance} 月饼`);
259
+ message.push(`当前余额: ${currentBalance} ${currency}`);
260
+ message.push(`扣款后: ${finalBalance} ${currency}`);
260
261
  message.push("---");
261
262
  message.push("计费区间:");
262
263
  if (res.billing.segments.length > 0) {
@@ -287,7 +288,7 @@ var formatBilling = /* @__PURE__ */ __name((res) => {
287
288
  message.push(`- ${seg.ruleName}`);
288
289
  message.push(` 时段: ${timeString}`);
289
290
  message.push(` 时长: ${segDurationStr}`);
290
- message.push(` 费用: ${seg.cost} 月饼 ${seg.isCapped ? "(已封顶)" : ""}`);
291
+ message.push(` 费用: ${seg.cost} ${currency} ${seg.isCapped ? "(已封顶)" : ""}`);
291
292
  }
292
293
  });
293
294
  } else {
@@ -320,7 +321,8 @@ __name(handleRegisterCmd, "handleRegisterCmd");
320
321
  async function handleLoginCmd(context, user) {
321
322
  const { error, userId } = await getTargetUserId(context, user);
322
323
  if (error) return error;
323
- let [_, lockMessage] = await Promise.all([login(context, userId), handleLockCmd(context)]);
324
+ await login(context, userId);
325
+ let lockMessage = await handleLockCmd(context);
324
326
  let message = "✅ 入场成功\n\n" + lockMessage;
325
327
  return message;
326
328
  }
@@ -338,11 +340,11 @@ async function handleLogoutCmd(context, user) {
338
340
  messagePrefix,
339
341
  `入场时间: ${formatDateTime(res.session.createdAt)}`,
340
342
  `离场时间: ${formatDateTime(res.session.closedAt)}`,
341
- `消费: ${res.session.finalCost} 月饼`
343
+ `消费: ${res.session.finalCost} ${context.config.currency}`
342
344
  ].join("\n");
343
345
  } else {
344
346
  const billingRes = await billing(context, targetUserId);
345
- const billingMessage = formatBilling(billingRes);
347
+ const billingMessage = formatBilling(billingRes, context.config.currency);
346
348
  kv.set(targetUserId, now);
347
349
  if (user) {
348
350
  return `以下是用户 ${await getUserName(context.session, targetUserId)} 的账单预览:
@@ -388,21 +390,21 @@ async function handleWalletCmd(context, user) {
388
390
  const targetUserId = user ? userId : void 0;
389
391
  message.push(targetUserId ? `--- 用户 ${await getUserName(context.session, targetUserId)} 的钱包余额 ---` : "--- 钱包余额 ---");
390
392
  message.push(
391
- `可用: ${res.total.available} 月饼 (共 ${res.total.all})`,
393
+ `可用: ${res.total.available} ${context.config.currency} (共 ${res.total.all})`,
392
394
  ` - 付费: ${res.paid.available}`,
393
395
  ` - 免费: ${res.free.available}`
394
396
  );
395
397
  const unavailable = res.total.all - res.total.available;
396
398
  if (unavailable > 0) {
397
399
  message.push(`
398
- 您还有 ${unavailable} 月饼未到可用时间。`);
400
+ 您还有 ${unavailable} ${context.config.currency}未到可用时间。`);
399
401
  }
400
402
  const expiringFreeAssets = res.free.details?.available?.filter((asset) => asset.expireAt) || [];
401
403
  if (expiringFreeAssets.length > 0) {
402
404
  expiringFreeAssets.sort((a, b) => new Date(a.expireAt).getTime() - new Date(b.expireAt).getTime());
403
405
  const soonestToExpire = expiringFreeAssets[0];
404
406
  message.push(`
405
- 注意:您有 ${soonestToExpire.count} 免费月饼将于 ${formatDateTime(soonestToExpire.expireAt)} 过期。`);
407
+ 注意:您有 ${soonestToExpire.count} 免费${context.config.currency}将于 ${formatDateTime(soonestToExpire.expireAt)} 过期。`);
406
408
  }
407
409
  const availablePasses = res.passes?.details?.available || [];
408
410
  if (availablePasses.length > 0) {
@@ -429,7 +431,7 @@ async function handleBillingCmd(context, user) {
429
431
  const { error, userId } = await getTargetUserId(context, user);
430
432
  if (error) return error;
431
433
  const res = await billing(context, userId);
432
- const billingMessage = formatBilling(res);
434
+ const billingMessage = formatBilling(res, context.config.currency);
433
435
  if (user) {
434
436
  return `用户 ${await getUserName(context.session, userId)} 的账单:
435
437
 
@@ -504,7 +506,7 @@ async function handleWalletAdd(context, user, amount) {
504
506
  if (!amount) return "请输入数量";
505
507
  const res = await walletAdd(context, parseInt(amount), userId);
506
508
  return [
507
- `为用户 ${await getUserName(context.session, userId)} 增加月饼成功`,
509
+ `为用户 ${await getUserName(context.session, userId)} 增加${context.config.currency}成功`,
508
510
  `增加前: ${res.originalBalance}`,
509
511
  `增加后: ${res.finalBalance}`
510
512
  ].join("\n");
@@ -516,7 +518,7 @@ async function handleWalletDeduct(context, user, amount) {
516
518
  if (!amount) return "请输入数量";
517
519
  const res = await walletDel(context, parseInt(amount), userId);
518
520
  return [
519
- `为用户 ${userId} 扣除月饼成功`,
521
+ `为用户 ${userId} 扣除${context.config.currency}成功`,
520
522
  `扣款前: ${res.originalBalance}`,
521
523
  `扣款后: ${res.finalBalance}`
522
524
  ].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.16",
4
+ "version": "0.0.18",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",