功能:完整实现测试设置积分命令

- 实现 handle_test_set_points 函数的完整逻辑
- 支持解析命令参数中的金额值
- 添加参数验证(非负数、整数类型)
- 返回设置结果反馈给用户

用法: /测试设置积分 <金额>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-03 22:41:54 +08:00
parent 21a936fee6
commit 756019b9ef

View File

@@ -43,7 +43,29 @@ async def handle_test_set_points(bot: Bot, event: Event):
await test_set_points_cmd.finish("权限不足") await test_set_points_cmd.finish("权限不足")
return return
# Get the message text and extract amount
msg = str(event.get_message()).strip()
# Remove command prefix
parts = msg.split()
if len(parts) < 2:
await test_set_points_cmd.finish("请使用: /测试设置积分 <金额>") await test_set_points_cmd.finish("请使用: /测试设置积分 <金额>")
return
try:
amount = int(parts[1])
if amount < 0:
await test_set_points_cmd.finish("金额必须为非负数")
return
except ValueError:
await test_set_points_cmd.finish("金额必须是整数")
return
success, _ = await points_service.set_points(event.user_id, amount, f"测试设置积分为{amount}")
if success:
await test_set_points_cmd.finish(f"积分已设置为 {amount}")
else:
await test_set_points_cmd.finish("设置失败")
test_query_points_cmd = on_command("测试查询积分", priority=5) test_query_points_cmd = on_command("测试查询积分", priority=5)