积分打劫功能

This commit is contained in:
liuwei
2025-04-09 17:44:47 +08:00
parent 941ea3a435
commit d1bab5d585

View File

@@ -70,7 +70,8 @@ class PointTradePlugin(MessagePluginInterface):
# 从配置中获取参数 # 从配置中获取参数
point_trade_config = self._config.get("PointTrade", {}) point_trade_config = self._config.get("PointTrade", {})
self._commands = point_trade_config.get("command", ["积分交易", "积分转账", "转账积分", "我的积分", "积分排行", "打劫"]) self._commands = point_trade_config.get("command",
["积分交易", "积分转账", "转账积分", "我的积分", "积分排行", "打劫"])
self.command_format = point_trade_config.get("command-format", """ self.command_format = point_trade_config.get("command-format", """
积分交易指令: 积分交易指令:
积分转账 积分数 @用户 - 转账给指定用户 积分转账 积分数 @用户 - 转账给指定用户
@@ -82,8 +83,8 @@ class PointTradePlugin(MessagePluginInterface):
# 打劫功能配置 # 打劫功能配置
self.rob_success_rate = point_trade_config.get("rob-success-rate", 0.3) # 打劫成功率 self.rob_success_rate = point_trade_config.get("rob-success-rate", 0.3) # 打劫成功率
self.rob_min_percent = point_trade_config.get("rob-min-percent", 0.1) # 打劫最小百分比 self.rob_min_percent = point_trade_config.get("rob-min-percent", 0.1) # 打劫最小百分比
self.rob_max_percent = point_trade_config.get("rob-max-percent", 0.3) # 打劫最大百分比 self.rob_max_percent = point_trade_config.get("rob-max-percent", 0.3) # 打劫最大百分比
self.rob_penalty_percent = point_trade_config.get("rob-penalty-percent", 0.2) # 打劫失败惩罚百分比 self.rob_penalty_percent = point_trade_config.get("rob-penalty-percent", 0.2) # 打劫失败惩罚百分比
self.rob_cooldown = point_trade_config.get("rob-cooldown", 1800) # 打劫冷却时间(秒) self.rob_cooldown = point_trade_config.get("rob-cooldown", 1800) # 打劫冷却时间(秒)
self.rob_min_points = point_trade_config.get("rob-min-points", 10) # 打劫最低积分要求 self.rob_min_points = point_trade_config.get("rob-min-points", 10) # 打劫最低积分要求
@@ -238,7 +239,7 @@ class PointTradePlugin(MessagePluginInterface):
if not user_points: if not user_points:
wcf.send_text(f"❌未找到你的积分记录!请先参与积分活动[签到,答题/t]。", wcf.send_text(f"❌未找到你的积分记录!请先参与积分活动[签到,答题/t]。",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, "未找到积分记录" return True, "未找到积分记录"
# 获取用户昵称 # 获取用户昵称
@@ -284,7 +285,7 @@ class PointTradePlugin(MessagePluginInterface):
except Exception as e: except Exception as e:
self.LOG.error(f"查询积分出错: {e}") self.LOG.error(f"查询积分出错: {e}")
wcf.send_text(f"❌查询积分失败!请稍后重试。错误: {str(e)}", wcf.send_text(f"❌查询积分失败!请稍后重试。错误: {str(e)}",
(roomid if roomid else sender), sender) (roomid if roomid else sender), sender)
return True, f"处理出错: {str(e)}" return True, f"处理出错: {str(e)}"
def _handle_points_ranking(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: def _handle_points_ranking(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
@@ -442,14 +443,14 @@ class PointTradePlugin(MessagePluginInterface):
remaining_time = int(self.rob_cooldown - time_passed) remaining_time = int(self.rob_cooldown - time_passed)
minutes, seconds = divmod(remaining_time, 60) minutes, seconds = divmod(remaining_time, 60)
wcf.send_text(f"❌你最近已经打劫过了,需要冷却 {minutes}{seconds}秒 后才能再次打劫!", wcf.send_text(f"❌你最近已经打劫过了,需要冷却 {minutes}{seconds}秒 后才能再次打劫!",
roomid, sender) roomid, sender)
return True, "冷却中" return True, "冷却中"
# 检查@用户是否有效 # 检查@用户是否有效
at_users = self.at_list(xml) at_users = self.at_list(xml)
if len(at_users) != 1: if len(at_users) != 1:
wcf.send_text(f"打劫失败❌\n请指定一个打劫目标!\n打劫 @用户", wcf.send_text(f"打劫失败❌\n请指定一个打劫目标!\n打劫 @用户",
roomid, sender) roomid, sender)
return True, "目标无效" return True, "目标无效"
target_wxid = next(iter(at_users)) target_wxid = next(iter(at_users))
@@ -538,16 +539,16 @@ class PointTradePlugin(MessagePluginInterface):
penalty_amount = max(1, penalty_amount) penalty_amount = max(1, penalty_amount)
# 记录积分变动 # 记录积分变动
success, result = self.points_db.add_points( success, result = self.points_db.transfer_points(
robber_wxid, roomid, -penalty_amount, robber_wxid, target_wxid, roomid,
PointSource.OTHER, f"打劫{target_name}失败的惩罚" penalty_amount, f"打劫{target_name}失败的惩罚"
) )
if success: if success:
# 构建打劫失败消息 # 构建打劫失败消息
output = ( output = (
f"🚨 打劫失败!\n" f"🚨 打劫失败!\n"
f"👤{robber_name} 试图打劫 👤{target_name} 但被当场抓获!\n" f"👤{robber_name} 试图打劫 👤{target_name} 但被当场抓获,并赔款\n"
f"👮‍♂️ 被罚款 {penalty_amount} 积分!\n" f"👮‍♂️ 被罚款 {penalty_amount} 积分!\n"
f"👤{robber_name} 当前积分: {result.get('total_points', 0)}" f"👤{robber_name} 当前积分: {result.get('total_points', 0)}"
) )