koishi-plugin-prism-neo 0.0.17 → 0.0.19
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 +3 -0
- package/lib/index.js +34 -18
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export declare const name = "prism-neo";
|
|
|
3
3
|
export interface Config {
|
|
4
4
|
url: string;
|
|
5
5
|
admin: string;
|
|
6
|
+
currency: string;
|
|
7
|
+
autoLockOnLogin: boolean;
|
|
8
|
+
logoutConfirmation: boolean;
|
|
6
9
|
}
|
|
7
10
|
export declare const Config: Schema<Config>;
|
|
8
11
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -182,7 +182,10 @@ 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("货币名称"),
|
|
187
|
+
autoLockOnLogin: import_koishi.Schema.boolean().default(true).description("登录时自动获取门锁密码"),
|
|
188
|
+
logoutConfirmation: import_koishi.Schema.boolean().default(true).description("登出时需要二次确认")
|
|
186
189
|
});
|
|
187
190
|
async function getUserName(session, userId) {
|
|
188
191
|
if (userId) {
|
|
@@ -223,7 +226,7 @@ var formatDateTime = /* @__PURE__ */ __name((dateStr) => {
|
|
|
223
226
|
const s = date.getSeconds().toString().padStart(2, "0");
|
|
224
227
|
return `${y}/${m}/${d} ${h2}:${min}:${s}`;
|
|
225
228
|
}, "formatDateTime");
|
|
226
|
-
var formatBilling = /* @__PURE__ */ __name((res) => {
|
|
229
|
+
var formatBilling = /* @__PURE__ */ __name((res, currency) => {
|
|
227
230
|
const message = [];
|
|
228
231
|
message.push("--- 账单详情 ---");
|
|
229
232
|
message.push(`入场: ${formatDateTime(res.session.createdAt)}`);
|
|
@@ -245,18 +248,18 @@ var formatBilling = /* @__PURE__ */ __name((res) => {
|
|
|
245
248
|
if (res.session.costOverwrite) {
|
|
246
249
|
finalCost = res.session.costOverwrite;
|
|
247
250
|
}
|
|
248
|
-
message.push(`计费价: ${originalCost}
|
|
251
|
+
message.push(`计费价: ${originalCost} ${currency}`);
|
|
249
252
|
if (res.discount && res.discount.appliedLogs.length > 0) {
|
|
250
253
|
res.discount.appliedLogs.forEach((log) => {
|
|
251
|
-
message.push(` -「${log.asset}」: -${log.saved}
|
|
254
|
+
message.push(` -「${log.asset}」: -${log.saved} ${currency}`);
|
|
252
255
|
});
|
|
253
256
|
}
|
|
254
|
-
message.push(`结算价: ${finalCost}
|
|
257
|
+
message.push(`结算价: ${finalCost} ${currency}`);
|
|
255
258
|
message.push("---");
|
|
256
259
|
const currentBalance = res.wallet.total.available;
|
|
257
260
|
const finalBalance = currentBalance - finalCost;
|
|
258
|
-
message.push(`当前余额: ${currentBalance}
|
|
259
|
-
message.push(`扣款后: ${finalBalance}
|
|
261
|
+
message.push(`当前余额: ${currentBalance} ${currency}`);
|
|
262
|
+
message.push(`扣款后: ${finalBalance} ${currency}`);
|
|
260
263
|
message.push("---");
|
|
261
264
|
message.push("计费区间:");
|
|
262
265
|
if (res.billing.segments.length > 0) {
|
|
@@ -287,7 +290,7 @@ var formatBilling = /* @__PURE__ */ __name((res) => {
|
|
|
287
290
|
message.push(`- ${seg.ruleName}`);
|
|
288
291
|
message.push(` 时段: ${timeString}`);
|
|
289
292
|
message.push(` 时长: ${segDurationStr}`);
|
|
290
|
-
message.push(` 费用: ${seg.cost}
|
|
293
|
+
message.push(` 费用: ${seg.cost} ${currency} ${seg.isCapped ? "(已封顶)" : ""}`);
|
|
291
294
|
}
|
|
292
295
|
});
|
|
293
296
|
} else {
|
|
@@ -321,14 +324,27 @@ async function handleLoginCmd(context, user) {
|
|
|
321
324
|
const { error, userId } = await getTargetUserId(context, user);
|
|
322
325
|
if (error) return error;
|
|
323
326
|
await login(context, userId);
|
|
324
|
-
let
|
|
325
|
-
|
|
327
|
+
let message = "✅ 入场成功";
|
|
328
|
+
if (context.config.autoLockOnLogin) {
|
|
329
|
+
let lockMessage = await handleLockCmd(context);
|
|
330
|
+
message += "\n\n" + lockMessage;
|
|
331
|
+
}
|
|
326
332
|
return message;
|
|
327
333
|
}
|
|
328
334
|
__name(handleLoginCmd, "handleLoginCmd");
|
|
329
335
|
async function handleLogoutCmd(context, user) {
|
|
330
336
|
const { error, userId: targetUserId } = await getTargetUserId(context, user);
|
|
331
337
|
if (error) return error;
|
|
338
|
+
if (!context.config.logoutConfirmation) {
|
|
339
|
+
const res = await logout(context, targetUserId);
|
|
340
|
+
const messagePrefix = user ? `✅ 已为用户 ${await getUserName(context.session, targetUserId)} 退场` : "✅ 退场成功";
|
|
341
|
+
return [
|
|
342
|
+
messagePrefix,
|
|
343
|
+
`入场时间: ${formatDateTime(res.session.createdAt)}`,
|
|
344
|
+
`离场时间: ${formatDateTime(res.session.closedAt)}`,
|
|
345
|
+
`消费: ${res.session.finalCost} ${context.config.currency}`
|
|
346
|
+
].join("\n");
|
|
347
|
+
}
|
|
332
348
|
const pendingLogout = kv.get(targetUserId);
|
|
333
349
|
const now = Date.now();
|
|
334
350
|
if (pendingLogout && now - pendingLogout < 60 * 1e3) {
|
|
@@ -339,11 +355,11 @@ async function handleLogoutCmd(context, user) {
|
|
|
339
355
|
messagePrefix,
|
|
340
356
|
`入场时间: ${formatDateTime(res.session.createdAt)}`,
|
|
341
357
|
`离场时间: ${formatDateTime(res.session.closedAt)}`,
|
|
342
|
-
`消费: ${res.session.finalCost}
|
|
358
|
+
`消费: ${res.session.finalCost} ${context.config.currency}`
|
|
343
359
|
].join("\n");
|
|
344
360
|
} else {
|
|
345
361
|
const billingRes = await billing(context, targetUserId);
|
|
346
|
-
const billingMessage = formatBilling(billingRes);
|
|
362
|
+
const billingMessage = formatBilling(billingRes, context.config.currency);
|
|
347
363
|
kv.set(targetUserId, now);
|
|
348
364
|
if (user) {
|
|
349
365
|
return `以下是用户 ${await getUserName(context.session, targetUserId)} 的账单预览:
|
|
@@ -389,21 +405,21 @@ async function handleWalletCmd(context, user) {
|
|
|
389
405
|
const targetUserId = user ? userId : void 0;
|
|
390
406
|
message.push(targetUserId ? `--- 用户 ${await getUserName(context.session, targetUserId)} 的钱包余额 ---` : "--- 钱包余额 ---");
|
|
391
407
|
message.push(
|
|
392
|
-
`可用: ${res.total.available}
|
|
408
|
+
`可用: ${res.total.available} ${context.config.currency} (共 ${res.total.all})`,
|
|
393
409
|
` - 付费: ${res.paid.available}`,
|
|
394
410
|
` - 免费: ${res.free.available}`
|
|
395
411
|
);
|
|
396
412
|
const unavailable = res.total.all - res.total.available;
|
|
397
413
|
if (unavailable > 0) {
|
|
398
414
|
message.push(`
|
|
399
|
-
您还有 ${unavailable}
|
|
415
|
+
您还有 ${unavailable} ${context.config.currency}未到可用时间。`);
|
|
400
416
|
}
|
|
401
417
|
const expiringFreeAssets = res.free.details?.available?.filter((asset) => asset.expireAt) || [];
|
|
402
418
|
if (expiringFreeAssets.length > 0) {
|
|
403
419
|
expiringFreeAssets.sort((a, b) => new Date(a.expireAt).getTime() - new Date(b.expireAt).getTime());
|
|
404
420
|
const soonestToExpire = expiringFreeAssets[0];
|
|
405
421
|
message.push(`
|
|
406
|
-
注意:您有 ${soonestToExpire.count}
|
|
422
|
+
注意:您有 ${soonestToExpire.count} 免费${context.config.currency}将于 ${formatDateTime(soonestToExpire.expireAt)} 过期。`);
|
|
407
423
|
}
|
|
408
424
|
const availablePasses = res.passes?.details?.available || [];
|
|
409
425
|
if (availablePasses.length > 0) {
|
|
@@ -430,7 +446,7 @@ async function handleBillingCmd(context, user) {
|
|
|
430
446
|
const { error, userId } = await getTargetUserId(context, user);
|
|
431
447
|
if (error) return error;
|
|
432
448
|
const res = await billing(context, userId);
|
|
433
|
-
const billingMessage = formatBilling(res);
|
|
449
|
+
const billingMessage = formatBilling(res, context.config.currency);
|
|
434
450
|
if (user) {
|
|
435
451
|
return `用户 ${await getUserName(context.session, userId)} 的账单:
|
|
436
452
|
|
|
@@ -505,7 +521,7 @@ async function handleWalletAdd(context, user, amount) {
|
|
|
505
521
|
if (!amount) return "请输入数量";
|
|
506
522
|
const res = await walletAdd(context, parseInt(amount), userId);
|
|
507
523
|
return [
|
|
508
|
-
`为用户 ${await getUserName(context.session, userId)}
|
|
524
|
+
`为用户 ${await getUserName(context.session, userId)} 增加${context.config.currency}成功`,
|
|
509
525
|
`增加前: ${res.originalBalance}`,
|
|
510
526
|
`增加后: ${res.finalBalance}`
|
|
511
527
|
].join("\n");
|
|
@@ -517,7 +533,7 @@ async function handleWalletDeduct(context, user, amount) {
|
|
|
517
533
|
if (!amount) return "请输入数量";
|
|
518
534
|
const res = await walletDel(context, parseInt(amount), userId);
|
|
519
535
|
return [
|
|
520
|
-
`为用户 ${userId}
|
|
536
|
+
`为用户 ${userId} 扣除${context.config.currency}成功`,
|
|
521
537
|
`扣款前: ${res.originalBalance}`,
|
|
522
538
|
`扣款后: ${res.finalBalance}`
|
|
523
539
|
].join("\n");
|