koishi-plugin-monetary-admin 1.0.1 → 1.0.3
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 +71 -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
|
-
|
|
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
|
-
|
|
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}) 的所有货币记录。`;
|
|
@@ -63,4 +87,49 @@ function apply(ctx) {
|
|
|
63
87
|
return `删除失败: ${e.message}`;
|
|
64
88
|
}
|
|
65
89
|
});
|
|
90
|
+
ctx.command('monetary.balance <target:user>', '查询目标用户的货币余额', { authority: 1 })
|
|
91
|
+
.alias('查询余额')
|
|
92
|
+
.action(async ({ session }, target) => {
|
|
93
|
+
if (!target)
|
|
94
|
+
return '请输入目标用户。';
|
|
95
|
+
const [platform, pid] = target.split(':');
|
|
96
|
+
if (!platform || !pid)
|
|
97
|
+
return '目标用户格式错误。';
|
|
98
|
+
const bindings = await ctx.database.get('binding', {
|
|
99
|
+
platform,
|
|
100
|
+
pid,
|
|
101
|
+
}, ['aid']);
|
|
102
|
+
if (bindings.length === 0) {
|
|
103
|
+
return '未找到该用户。';
|
|
104
|
+
}
|
|
105
|
+
const uid = bindings[0].aid;
|
|
106
|
+
const [user] = await ctx.database.get('user', { id: uid }, ['name']);
|
|
107
|
+
let name = user?.name || target;
|
|
108
|
+
if (!user?.name) {
|
|
109
|
+
const bot = ctx.bots.find(b => b.platform === platform);
|
|
110
|
+
if (bot) {
|
|
111
|
+
try {
|
|
112
|
+
const platformUser = await bot.getUser(pid);
|
|
113
|
+
if (platformUser?.name) {
|
|
114
|
+
name = platformUser.name;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e) { }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const monetaryRecords = await ctx.database.get('monetary', { uid });
|
|
122
|
+
if (monetaryRecords.length === 0) {
|
|
123
|
+
return `用户 ${name} (UID: ${uid}) 暂无任何货币记录。`;
|
|
124
|
+
}
|
|
125
|
+
let result = `用户 ${name} (UID: ${uid}) 的货币余额:\n`;
|
|
126
|
+
for (const record of monetaryRecords) {
|
|
127
|
+
result += `${record.currency} ${record.value}\n`;
|
|
128
|
+
}
|
|
129
|
+
return result.trim();
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return `查询失败: ${e.message}`;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
66
135
|
}
|