diff --git a/plugins/message_sign/main.py b/plugins/message_sign/main.py index 67bf234..a6798ac 100644 --- a/plugins/message_sign/main.py +++ b/plugins/message_sign/main.py @@ -246,7 +246,7 @@ class MessageSignPlugin(MessagePluginInterface): # 在_handle_sign_in方法中,修改断签处理逻辑 # 找到约在第247行的代码块 - + streak = 0 streak_broken = False old_streak = 1 @@ -279,7 +279,7 @@ class MessageSignPlugin(MessagePluginInterface): if user_record: # 保存上次签到时间 last_sign_date = user_record.get('sign_stat') - + # 如果断签,保存断签前的连签天数 if streak_broken and user_record['signin_streak'] > 1: self.sign_in_db.update_sign_record_with_previous_streak( @@ -352,13 +352,13 @@ class MessageSignPlugin(MessagePluginInterface): return min(total_points, self.max_point) # 修改_handle_makeup_sign方法,实现连签恢复功能 - + def _handle_makeup_sign(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理补签请求""" sender = message.get("sender") roomid = message.get("roomid", "") all_contacts = message.get("all_contacts", {}) - + try: # 获取当前时间,带有时区信息 current_time = datetime.now(tz=pytz.timezone(self.timezone)) @@ -366,11 +366,11 @@ class MessageSignPlugin(MessagePluginInterface): today_start = current_time.replace(hour=0, minute=0, second=0, microsecond=0) yesterday = today_start - timedelta(days=1) day_before_yesterday = today_start - timedelta(days=2) - + # 获取用户的签到记录 user_record = self.get_user_record(sender, roomid) wx_nick_name = all_contacts.get(sender, sender) - + # 检查用户是否有签到记录 if not user_record: self.message_util.send_text_msg( @@ -378,25 +378,25 @@ class MessageSignPlugin(MessagePluginInterface): (roomid if roomid else sender), sender ) return True, "无签到记录" - + # 获取上次签到时间并规范化到零点 last_sign_date = None if user_record.get('last_sign_date'): last_sign_date = user_record['last_sign_date'].replace(hour=0, minute=0, second=0, microsecond=0) elif user_record.get('sign_stat'): last_sign_date = user_record['sign_stat'].replace(hour=0, minute=0, second=0, microsecond=0) - + # 确保时区一致 if isinstance(last_sign_date, datetime) and last_sign_date.tzinfo is None: last_sign_date = pytz.timezone(self.timezone).localize(last_sign_date) - + # 获取当前签到状态并规范化到零点 sign_stat = None if user_record.get('sign_stat'): sign_stat = user_record['sign_stat'].replace(hour=0, minute=0, second=0, microsecond=0) if sign_stat.tzinfo is None: sign_stat = pytz.timezone(self.timezone).localize(sign_stat) - + # 检查是否已经签到今天 if sign_stat and sign_stat >= today_start: # 今天已经签到,检查是否需要补签昨天 @@ -420,7 +420,7 @@ class MessageSignPlugin(MessagePluginInterface): (roomid if roomid else sender), sender ) return True, "不符合补签条件" - + if last_sign_date >= yesterday: self.LOG.info(f"昨天已签到,last_sign_date: {last_sign_date}") self.message_util.send_text_msg( @@ -428,45 +428,55 @@ class MessageSignPlugin(MessagePluginInterface): (roomid if roomid else sender), sender ) return True, "无需补签" - + # 检查用户积分是否足够 from db.points_db import PointsDBOperator, PointSource points_db = PointsDBOperator(self.db_manager) user_points = points_db.get_user_points(sender, roomid) - + if not user_points or user_points["total_points"] < self.makeup_cost: self.message_util.send_text_msg( f"❌ 积分不足!补签需要 {self.makeup_cost} 积分,您当前只有 {user_points.get('total_points', 0)} 积分。", (roomid if roomid else sender), sender ) return True, "积分不足" - + # 扣除积分 deduct_success, deduct_result = points_db.deduct_points( sender, roomid, self.makeup_cost, PointSource.PLUGIN, "签到补签消费" ) - + if not deduct_success: self.message_util.send_text_msg( f"❌ 扣除积分失败:{deduct_result.get('error', '未知错误')}", (roomid if roomid else sender), sender ) return True, "扣除积分失败" - + # 在_handle_makeup_sign方法中,修改计算新连签天数的逻辑 - + # 获取原连签天数和断签前连签天数 + original_streak = user_record['signin_streak'] previous_streak = user_record.get('previous_streak', 0) - - # 恢复连签:断签前连签天数 + 1 (补签后相当于连续签到) - new_streak = previous_streak + 1 - self.LOG.info(f"恢复连签: {previous_streak} + 1 = {new_streak}") + + # 计算新的连签天数 + new_streak = original_streak + + # 如果有断签前记录,直接使用断签前连签天数+1 + if previous_streak > 0: + # 恢复连签:断签前连签天数 + 1 (补签后相当于连续签到) + new_streak = previous_streak + 1 + self.LOG.info(f"恢复连签: {previous_streak} + 1 = {new_streak}") + else: + # 如果没有断签前记录,则连签天数+1 + new_streak = original_streak + 1 + self.LOG.info(f"普通补签: {original_streak} + 1 = {new_streak}") # 更新签到记录 yesterday_time = yesterday.replace(hour=current_time.hour, minute=current_time.minute, second=current_time.second) - + # 如果今天已经签到,则更新last_sign_date为昨天,保持sign_stat不变 if sign_stat and sign_stat >= today_start: self.sign_in_db.update_makeup_sign_with_streak_recovery( @@ -485,25 +495,25 @@ class MessageSignPlugin(MessagePluginInterface): last_sign_date, # 保留原来的last_sign_date 0 # 清除previous_streak,因为已经恢复了 ) - + # 发送成功消息 success_message = f"✅ 补签成功!\n💰 消费 {self.makeup_cost} 积分\n" - + # 如果恢复了连签,显示恢复信息 if new_streak > original_streak + 1: success_message += f"🎉 恢复连签!连续签到天数:{new_streak}\n" else: success_message += f"🔄 连续签到天数:{new_streak}\n" - + success_message += f"💰 当前积分:{user_points['total_points'] - self.makeup_cost}" - + self.message_util.send_text_msg( success_message, (roomid if roomid else sender), sender ) - + return True, "补签成功" - + except Exception as e: self.LOG.error(f"处理补签请求出错: {e}") self.message_util.send_text_msg(