消耗太快了

This commit is contained in:
liuwei
2025-04-09 17:18:22 +08:00
committed by Liu
parent 99592ffe0a
commit 57234e4282

View File

@@ -134,21 +134,14 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
logger = logging.getLogger(f"PointsCost.{plugin_name}") logger = logging.getLogger(f"PointsCost.{plugin_name}")
user_points = points_db.get_user_points(sender, roomid) user_points = points_db.get_user_points(sender, roomid)
stats = points_db.get_user_points_stats(roomid) if user_points["total_points"] < points:
try:
points_auto = int(points * stats["total_points"] / 3000)
except Exception as e:
logger.error(f"计算抵扣积分错误,使用默认积分:{e}")
points_auto = points
if user_points["total_points"] < points_auto:
# 积分不足 # 积分不足
wcf = message.get("wcf") wcf = message.get("wcf")
if wcf: if wcf:
wcf.send_text( wcf.send_text(
f"❌ 积分不足\n无法使用 {plugin_name} 功能\n" f"❌ 积分不足\n无法使用 {plugin_name} 功能\n"
f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n" f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n"
f"💰 有: {user_points['total_points']} | 需: {points_auto} |差: {points_auto - user_points['total_points']} ", f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ",
(roomid if roomid else sender), sender (roomid if roomid else sender), sender
) )
logger.info(f"用户 {sender} 积分不足,无法使用功能") logger.info(f"用户 {sender} 积分不足,无法使用功能")
@@ -160,20 +153,20 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature =
# 如果原始方法执行成功,扣除积分 # 如果原始方法执行成功,扣除积分
if success: if success:
deduct_success, deduct_result = points_db.deduct_points( deduct_success, deduct_result = points_db.deduct_points(
sender, roomid, points_auto, PointSource.PLUGIN, sender, roomid, points, PointSource.PLUGIN,
description or f"使用 {plugin_name} 功能" description or f"使用 {plugin_name} 功能"
) )
if deduct_success: if deduct_success:
logger.info(f"用户 {sender} 使用 {plugin_name} 功能扣除 {points_auto} 积分") logger.info(f"用户 {sender} 使用 {plugin_name} 功能扣除 {points} 积分")
# 如果响应中没有提到积分,添加积分信息 # 如果响应中没有提到积分,添加积分信息
if "积分" not in response: if "积分" not in response:
response += f"\n\n💰 已消费 {points_auto} 积分" response += f"\n\n💰 已消费 {points} 积分"
wcf = message.get("wcf") wcf = message.get("wcf")
if wcf: if wcf:
wcf.send_text( wcf.send_text(
f"💰消费 {points_auto} 积分", f"💰消费 {points} 积分",
(roomid if roomid else sender), sender (roomid if roomid else sender), sender
) )
else: else: