koishi-plugin-monetary-admin 1.0.1 → 1.0.2

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 +26 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -28,7 +28,19 @@ function apply(ctx) {
28
28
  }
29
29
  const uid = bindings[0].aid;
30
30
  const [user] = await ctx.database.get('user', { id: uid }, ['name']);
31
- const name = user?.name || target;
31
+ let name = user?.name || target;
32
+ if (!user?.name) {
33
+ const bot = ctx.bots.find(b => b.platform === platform);
34
+ if (bot) {
35
+ try {
36
+ const platformUser = await bot.getUser(pid);
37
+ if (platformUser?.name) {
38
+ name = platformUser.name;
39
+ }
40
+ }
41
+ catch (e) { }
42
+ }
43
+ }
32
44
  try {
33
45
  await ctx.monetary.gain(uid, amount, currency);
34
46
  return `成功给用户 ${name} (UID: ${uid}) 添加了 ${amount} ${currency}。`;
@@ -54,7 +66,19 @@ function apply(ctx) {
54
66
  }
55
67
  const uid = bindings[0].aid;
56
68
  const [user] = await ctx.database.get('user', { id: uid }, ['name']);
57
- const name = user?.name || target;
69
+ let name = user?.name || target;
70
+ if (!user?.name) {
71
+ const bot = ctx.bots.find(b => b.platform === platform);
72
+ if (bot) {
73
+ try {
74
+ const platformUser = await bot.getUser(pid);
75
+ if (platformUser?.name) {
76
+ name = platformUser.name;
77
+ }
78
+ }
79
+ catch (e) { }
80
+ }
81
+ }
58
82
  try {
59
83
  await ctx.database.remove('monetary', { uid });
60
84
  return `成功删除用户 ${name} (UID: ${uid}) 的所有货币记录。`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-monetary-admin",
3
3
  "description": "Admin commands for Koishi monetary system",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [