koishi-plugin-monetary-admin 1.0.0 → 1.0.1
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 +8 -12
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.inject = ['monetary', 'database'];
|
|
|
8
8
|
exports.Config = koishi_1.Schema.object({});
|
|
9
9
|
function apply(ctx) {
|
|
10
10
|
ctx.command('monetary.add <target:user> <currency:string> <amount:number>', '给目标用户添加货币', { authority: 3 })
|
|
11
|
+
.alias('开户')
|
|
11
12
|
.action(async ({ session }, target, currency, amount) => {
|
|
12
13
|
if (!target)
|
|
13
14
|
return '请输入目标用户。';
|
|
@@ -15,19 +16,9 @@ function apply(ctx) {
|
|
|
15
16
|
return '请输入货币类型。';
|
|
16
17
|
if (!amount)
|
|
17
18
|
return '请输入金额。';
|
|
18
|
-
// target is format "platform:pid" from koishi's user arg parser usually,
|
|
19
|
-
// but let's handle the string manual parsing just in case or if passed raw.
|
|
20
|
-
// However <target:user> argument definition in Koishi automatically parses @mentions into a string format.
|
|
21
|
-
// If it's a mention like @User, target will be the string representation.
|
|
22
|
-
// Actually, Koishi's <target:user> returns the raw string provided in the command usually but validates it?
|
|
23
|
-
// Wait, <target:user> in recent Koishi versions often resolves to the user object or returns the user ID string.
|
|
24
|
-
// Let's assume standard behavior: `target` is a string like "platform:pid".
|
|
25
|
-
// We need to parse platform and pid.
|
|
26
|
-
// Koishi's standard format for users is `platform:pid`.
|
|
27
19
|
const [platform, pid] = target.split(':');
|
|
28
20
|
if (!platform || !pid)
|
|
29
21
|
return '目标用户格式错误。';
|
|
30
|
-
// Find the aid (uid) from binding table
|
|
31
22
|
const bindings = await ctx.database.get('binding', {
|
|
32
23
|
platform,
|
|
33
24
|
pid,
|
|
@@ -36,15 +27,18 @@ function apply(ctx) {
|
|
|
36
27
|
return '未找到该用户。';
|
|
37
28
|
}
|
|
38
29
|
const uid = bindings[0].aid;
|
|
30
|
+
const [user] = await ctx.database.get('user', { id: uid }, ['name']);
|
|
31
|
+
const name = user?.name || target;
|
|
39
32
|
try {
|
|
40
33
|
await ctx.monetary.gain(uid, amount, currency);
|
|
41
|
-
return `成功给用户 ${
|
|
34
|
+
return `成功给用户 ${name} (UID: ${uid}) 添加了 ${amount} ${currency}。`;
|
|
42
35
|
}
|
|
43
36
|
catch (e) {
|
|
44
37
|
return `添加失败: ${e.message}`;
|
|
45
38
|
}
|
|
46
39
|
});
|
|
47
40
|
ctx.command('monetary.remove <target:user>', '删除目标用户的所有货币记录', { authority: 3 })
|
|
41
|
+
.alias('销户')
|
|
48
42
|
.action(async ({ session }, target) => {
|
|
49
43
|
if (!target)
|
|
50
44
|
return '请输入目标用户。';
|
|
@@ -59,9 +53,11 @@ function apply(ctx) {
|
|
|
59
53
|
return '未找到该用户。';
|
|
60
54
|
}
|
|
61
55
|
const uid = bindings[0].aid;
|
|
56
|
+
const [user] = await ctx.database.get('user', { id: uid }, ['name']);
|
|
57
|
+
const name = user?.name || target;
|
|
62
58
|
try {
|
|
63
59
|
await ctx.database.remove('monetary', { uid });
|
|
64
|
-
return `成功删除用户 ${
|
|
60
|
+
return `成功删除用户 ${name} (UID: ${uid}) 的所有货币记录。`;
|
|
65
61
|
}
|
|
66
62
|
catch (e) {
|
|
67
63
|
return `删除失败: ${e.message}`;
|
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.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
"koishi-plugin-monetary": "^0.1.3",
|
|
27
27
|
"typescript": "^5.2.2"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|