koishi-plugin-monetary-admin 1.1.0 → 1.2.0
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 +57 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -33,10 +33,23 @@ function apply(ctx) {
|
|
|
33
33
|
}
|
|
34
34
|
return { uid, name };
|
|
35
35
|
}
|
|
36
|
-
ctx.command('monetary.add
|
|
36
|
+
ctx.command('monetary.add [target:user] <currency:string> <amount:number>', '给目标用户添加货币', { authority: 5 })
|
|
37
|
+
.userFields(['id'])
|
|
37
38
|
.action(async ({ session }, target, currency, amount) => {
|
|
38
39
|
try {
|
|
39
|
-
|
|
40
|
+
let uid, name;
|
|
41
|
+
if (!target) {
|
|
42
|
+
// 如果没有指定目标,则给自己添加
|
|
43
|
+
if (!session?.user?.id)
|
|
44
|
+
return '无法获取您的用户信息。';
|
|
45
|
+
uid = session.user.id;
|
|
46
|
+
name = session.username || String(uid);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const resolved = await resolveUser(target);
|
|
50
|
+
uid = resolved.uid;
|
|
51
|
+
name = resolved.name;
|
|
52
|
+
}
|
|
40
53
|
if (!currency)
|
|
41
54
|
return '请输入货币类型。';
|
|
42
55
|
if (!amount)
|
|
@@ -50,11 +63,23 @@ function apply(ctx) {
|
|
|
50
63
|
return typeof e === 'string' ? e : `添加失败: ${e.message}`;
|
|
51
64
|
}
|
|
52
65
|
});
|
|
53
|
-
ctx.command('monetary.reduce
|
|
66
|
+
ctx.command('monetary.reduce [target:user] <currency:string> <amount:number>', '扣除目标用户货币', { authority: 5 })
|
|
54
67
|
.alias('扣款')
|
|
68
|
+
.userFields(['id'])
|
|
55
69
|
.action(async ({ session }, target, currency, amount) => {
|
|
56
70
|
try {
|
|
57
|
-
|
|
71
|
+
let uid, name;
|
|
72
|
+
if (!target) {
|
|
73
|
+
if (!session?.user?.id)
|
|
74
|
+
return '无法获取您的用户信息。';
|
|
75
|
+
uid = session.user.id;
|
|
76
|
+
name = session.username || String(uid);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const resolved = await resolveUser(target);
|
|
80
|
+
uid = resolved.uid;
|
|
81
|
+
name = resolved.name;
|
|
82
|
+
}
|
|
58
83
|
if (!currency)
|
|
59
84
|
return '请输入货币类型。';
|
|
60
85
|
if (!amount)
|
|
@@ -68,11 +93,23 @@ function apply(ctx) {
|
|
|
68
93
|
return typeof e === 'string' ? e : `扣除失败: ${e.message}`;
|
|
69
94
|
}
|
|
70
95
|
});
|
|
71
|
-
ctx.command('monetary.clear
|
|
96
|
+
ctx.command('monetary.clear [target:user] <currency:string>', '清零目标用户指定货币', { authority: 5 })
|
|
72
97
|
.alias('清零')
|
|
98
|
+
.userFields(['id'])
|
|
73
99
|
.action(async ({ session }, target, currency) => {
|
|
74
100
|
try {
|
|
75
|
-
|
|
101
|
+
let uid, name;
|
|
102
|
+
if (!target) {
|
|
103
|
+
if (!session?.user?.id)
|
|
104
|
+
return '无法获取您的用户信息。';
|
|
105
|
+
uid = session.user.id;
|
|
106
|
+
name = session.username || String(uid);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const resolved = await resolveUser(target);
|
|
110
|
+
uid = resolved.uid;
|
|
111
|
+
name = resolved.name;
|
|
112
|
+
}
|
|
76
113
|
if (!currency)
|
|
77
114
|
return '请输入货币类型。';
|
|
78
115
|
await ctx.database.set('monetary', { uid, currency }, { value: 0 });
|
|
@@ -98,11 +135,23 @@ function apply(ctx) {
|
|
|
98
135
|
return typeof e === 'string' ? e : `删除失败: ${e.message}`;
|
|
99
136
|
}
|
|
100
137
|
});
|
|
101
|
-
ctx.command('monetary.balance
|
|
138
|
+
ctx.command('monetary.balance [target:user]', '查询目标用户的货币余额', { authority: 1 })
|
|
102
139
|
.alias('查询余额')
|
|
140
|
+
.userFields(['id'])
|
|
103
141
|
.action(async ({ session }, target) => {
|
|
104
142
|
try {
|
|
105
|
-
|
|
143
|
+
let uid, name;
|
|
144
|
+
if (!target) {
|
|
145
|
+
if (!session?.user?.id)
|
|
146
|
+
return '无法获取您的用户信息。';
|
|
147
|
+
uid = session.user.id;
|
|
148
|
+
name = session.username || '您';
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const resolved = await resolveUser(target);
|
|
152
|
+
uid = resolved.uid;
|
|
153
|
+
name = resolved.name;
|
|
154
|
+
}
|
|
106
155
|
const monetaryRecords = await ctx.database.get('monetary', { uid });
|
|
107
156
|
if (monetaryRecords.length === 0) {
|
|
108
157
|
return `用户 ${name} (UID: ${uid}) 暂无任何货币记录。`;
|