koishi-plugin-monetary-admin 1.5.0 → 1.6.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 +9 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ function apply(ctx) {
|
|
|
33
33
|
}
|
|
34
34
|
return { uid, name };
|
|
35
35
|
}
|
|
36
|
-
ctx.command('monetary.add [target:user] <currency:string> <amount:number>', '
|
|
36
|
+
ctx.command('monetary.add [target:user] <currency:string> <amount:number>', '给目标用户添加货币', { authority: 5 })
|
|
37
37
|
.userFields(['id'])
|
|
38
38
|
.action(async ({ session }, target, currency, amount) => {
|
|
39
39
|
try {
|
|
@@ -177,13 +177,18 @@ function apply(ctx) {
|
|
|
177
177
|
return '请输入货币类型。';
|
|
178
178
|
if (!amount)
|
|
179
179
|
return '请输入金额。';
|
|
180
|
-
if (amount <= 0)
|
|
181
|
-
return '
|
|
180
|
+
if (amount <= 0 || amount > 100000)
|
|
181
|
+
return '转账金额必须在 1 到 100000 之间。';
|
|
182
182
|
const senderUid = session.user.id;
|
|
183
183
|
const { uid: targetUid, name: targetName } = await resolveUser(target);
|
|
184
184
|
if (senderUid === targetUid)
|
|
185
185
|
return '不能给自己转账。';
|
|
186
|
-
//
|
|
186
|
+
// 检查发送者余额
|
|
187
|
+
const senderRecords = await ctx.database.get('monetary', { uid: senderUid, currency });
|
|
188
|
+
if (senderRecords.length === 0 || senderRecords[0].value < amount) {
|
|
189
|
+
return `您的 ${currency} 余额不足。`;
|
|
190
|
+
}
|
|
191
|
+
// 执行转账
|
|
187
192
|
await ctx.monetary.gain(senderUid, -amount, currency);
|
|
188
193
|
await ctx.monetary.gain(targetUid, amount, currency);
|
|
189
194
|
const [senderUser] = await ctx.database.get('user', { id: senderUid }, ['name']);
|