koishi-plugin-prism-neo 0.0.6 → 0.0.9
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.js +25 -25
- 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,25 +339,17 @@ async function handleListCmd(context, user) {
|
|
|
331
339
|
if (!users || users.length === 0) {
|
|
332
340
|
return "窝里目前没有玩家呢";
|
|
333
341
|
}
|
|
334
|
-
const
|
|
342
|
+
const tasks = users.map((user2) => {
|
|
343
|
+
const entryDate = formatDateTime(user2.sessions[0].createdAt);
|
|
335
344
|
const qqBind = user2.binds.find((bind) => bind.type === "QQ");
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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}`;
|
|
341
352
|
});
|
|
342
|
-
const platformUsers = await Promise.all(
|
|
343
|
-
userIds.map((id) => {
|
|
344
|
-
return context.session.bot.getUser(id.id);
|
|
345
|
-
})
|
|
346
|
-
);
|
|
347
|
-
const userReports = platformUsers.map(
|
|
348
|
-
(u, idx) => {
|
|
349
|
-
return `玩家: ${u.name}
|
|
350
|
-
入场时间: ${userIds[idx].entryDate}`;
|
|
351
|
-
}
|
|
352
|
-
);
|
|
353
353
|
return `窝里目前共有 ${users.length} 人
|
|
354
354
|
|
|
355
355
|
${userReports.join("\n\n")}`;
|
|
@@ -361,7 +361,7 @@ async function handleWalletCmd(context, user) {
|
|
|
361
361
|
const res = await wallet(context, userId);
|
|
362
362
|
const message = [];
|
|
363
363
|
const targetUserId = user ? userId : void 0;
|
|
364
|
-
message.push(targetUserId ? `--- 用户 ${targetUserId} 的钱包余额 ---` : "--- 钱包余额 ---");
|
|
364
|
+
message.push(targetUserId ? `--- 用户 ${await getUserName(context.session, targetUserId)} 的钱包余额 ---` : "--- 钱包余额 ---");
|
|
365
365
|
message.push(
|
|
366
366
|
`可用: ${res.total.available} 月饼 (共 ${res.total.all})`,
|
|
367
367
|
` - 付费: ${res.paid.available}`,
|
|
@@ -406,7 +406,7 @@ async function handleBillingCmd(context, user) {
|
|
|
406
406
|
const res = await billing(context, userId);
|
|
407
407
|
const billingMessage = formatBilling(res);
|
|
408
408
|
if (user) {
|
|
409
|
-
return `用户 ${userId} 的账单:
|
|
409
|
+
return `用户 ${await getUserName(context.session, userId)} 的账单:
|
|
410
410
|
|
|
411
411
|
${billingMessage}`;
|
|
412
412
|
}
|
|
@@ -427,9 +427,9 @@ async function handleItemsCmd(context, user) {
|
|
|
427
427
|
if (error) return error;
|
|
428
428
|
const userAssets = await assets(context, userId);
|
|
429
429
|
if (!userAssets || userAssets.length === 0) {
|
|
430
|
-
return user ? `用户 ${userId} 没有任何物品。` : "您当前没有任何物品。";
|
|
430
|
+
return user ? `用户 ${await getUserName(context.session, userId)} 没有任何物品。` : "您当前没有任何物品。";
|
|
431
431
|
}
|
|
432
|
-
const header = user ? `--- 用户 ${userId} 拥有的物品 ---` : "--- 您拥有的物品 ---";
|
|
432
|
+
const header = user ? `--- 用户 ${await getUserName(context.session, userId)} 拥有的物品 ---` : "--- 您拥有的物品 ---";
|
|
433
433
|
const itemsList = userAssets.map((asset) => {
|
|
434
434
|
let line = `- ${asset.asset.name} (x${asset.count})`;
|
|
435
435
|
if (asset.expireAt) {
|
|
@@ -476,7 +476,7 @@ async function handleWalletAdd(context, user, amount) {
|
|
|
476
476
|
if (!amount) return "请输入数量";
|
|
477
477
|
const res = await walletAdd(context, parseInt(amount), userId);
|
|
478
478
|
return [
|
|
479
|
-
`为用户 ${userId} 增加月饼成功`,
|
|
479
|
+
`为用户 ${await getUserName(context.session, userId)} 增加月饼成功`,
|
|
480
480
|
`增加前: ${res.originalBalance}`,
|
|
481
481
|
`增加后: ${res.finalBalance}`
|
|
482
482
|
].join("\n");
|