From 46b291c25e20fa2e938b38769b4ae1398a661f03 Mon Sep 17 00:00:00 2001 From: Liu Date: Wed, 9 Apr 2025 19:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=A7=AF=E5=88=86=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/point_trade/main.py | 2 +- utils/decorator/points_decorator.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/point_trade/main.py b/plugins/point_trade/main.py index ea83b24..7afebd0 100644 --- a/plugins/point_trade/main.py +++ b/plugins/point_trade/main.py @@ -553,7 +553,7 @@ class PointTradePlugin(MessagePluginInterface): f"🚨 打劫失败!\n" f"👤{robber_name} 试图打劫 👤{target_name} 但被当场抓获,并赔款!\n" f"👮‍♂️ 被罚款 {penalty_amount} 积分!\n" - f"👤{robber_name} 当前积分: {to_user.get('total_points', 0)}" + f"👤{robber_name} 当前积分: {from_user.get('total_points', 0)}" ) wcf.send_text(output, roomid, sender) diff --git a/utils/decorator/points_decorator.py b/utils/decorator/points_decorator.py index b877dcf..0faa326 100644 --- a/utils/decorator/points_decorator.py +++ b/utils/decorator/points_decorator.py @@ -134,14 +134,21 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature = logger = logging.getLogger(f"PointsCost.{plugin_name}") user_points = points_db.get_user_points(sender, roomid) - if user_points["total_points"] < points: + stats = points_db.get_user_points_stats(roomid) + try: + points_auto = int(points * stats["total_points"] / 1000) + except Exception as e: + logger.error(f"计算抵扣积分错误,使用默认积分:{e}") + points_auto = points + + if user_points["total_points"] < points_auto: # 积分不足 wcf = message.get("wcf") if wcf: wcf.send_text( f"❌ 积分不足\n无法使用 {plugin_name} 功能\n" f"🪙 先参与积分活动[签到,答题/t]赚取吧!\n" - f"💰 有: {user_points['total_points']} | 需: {points} |差: {points - user_points['total_points']} ", + f"💰 有: {user_points['total_points']} | 需: {points_auto} |差: {points_auto - user_points['total_points']} ", (roomid if roomid else sender), sender ) logger.info(f"用户 {sender} 积分不足,无法使用功能") @@ -153,20 +160,20 @@ def plugin_points_cost(points: int, description: str = None, feature: Feature = # 如果原始方法执行成功,扣除积分 if success: deduct_success, deduct_result = points_db.deduct_points( - sender, roomid, points, PointSource.PLUGIN, + sender, roomid, points_auto, PointSource.PLUGIN, description or f"使用 {plugin_name} 功能" ) if deduct_success: - logger.info(f"用户 {sender} 使用 {plugin_name} 功能扣除 {points} 积分") + logger.info(f"用户 {sender} 使用 {plugin_name} 功能扣除 {points_auto} 积分") # 如果响应中没有提到积分,添加积分信息 if "积分" not in response: - response += f"\n\n💰 已消费 {points} 积分" + response += f"\n\n💰 已消费 {points_auto} 积分" wcf = message.get("wcf") if wcf: wcf.send_text( - f"💰消费 {points} 积分", + f"💰消费 {points_auto} 积分", (roomid if roomid else sender), sender ) else: