修复签到bug
This commit is contained in:
@@ -158,30 +158,32 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
Returns:
|
Returns:
|
||||||
int: 奖励积分数量
|
int: 奖励积分数量
|
||||||
"""
|
"""
|
||||||
sender = message.get("sender")
|
points = 0
|
||||||
roomid = message.get("roomid", "")
|
if success:
|
||||||
|
sender = message.get("sender")
|
||||||
|
roomid = message.get("roomid", "")
|
||||||
|
|
||||||
# 获取当前时间,带有时区信息
|
# 获取当前时间,带有时区信息
|
||||||
current_time = datetime.now(tz=pytz.timezone(self.timezone))
|
current_time = datetime.now(tz=pytz.timezone(self.timezone))
|
||||||
today_start = current_time.replace(hour=0, minute=0, second=0, microsecond=0)
|
today_start = current_time.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
yesterday = today_start - timedelta(days=1)
|
yesterday = today_start - timedelta(days=1)
|
||||||
|
|
||||||
# 获取用户的签到记录
|
# 获取用户的签到记录
|
||||||
user_record = self.get_user_record(sender, roomid)
|
user_record = self.get_user_record(sender, roomid)
|
||||||
|
|
||||||
# 计算连续签到天数
|
# 计算连续签到天数
|
||||||
streak = 1
|
streak = 1
|
||||||
if user_record and user_record['sign_stat']:
|
if user_record and user_record['sign_stat']:
|
||||||
last_sign_date = user_record['sign_stat'].replace(hour=0, minute=0, second=0, microsecond=0)
|
last_sign_date = user_record['sign_stat'].replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
# 确保 sign_stat 和 today_start 是同一时区对象
|
# 确保 sign_stat 和 today_start 是同一时区对象
|
||||||
if isinstance(last_sign_date, datetime) and last_sign_date.tzinfo is None:
|
if isinstance(last_sign_date, datetime) and last_sign_date.tzinfo is None:
|
||||||
last_sign_date = pytz.timezone(self.timezone).localize(last_sign_date)
|
last_sign_date = pytz.timezone(self.timezone).localize(last_sign_date)
|
||||||
|
|
||||||
if last_sign_date == yesterday:
|
if last_sign_date == yesterday:
|
||||||
streak = user_record['signin_streak'] + 1
|
streak = user_record['signin_streak'] + 1
|
||||||
|
|
||||||
# 计算积分
|
# 计算积分
|
||||||
points = self.calculate_points(streak)
|
points = self.calculate_points(streak)
|
||||||
return points
|
return points
|
||||||
|
|
||||||
# 修改 process_message 方法,作为路由分发
|
# 修改 process_message 方法,作为路由分发
|
||||||
@@ -240,7 +242,7 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
if sign_stat >= today_start:
|
if sign_stat >= today_start:
|
||||||
self.message_util.send_text_msg(f"您今天已经签到过了!共获得积分:{user_record['points']}",
|
self.message_util.send_text_msg(f"您今天已经签到过了!共获得积分:{user_record['points']}",
|
||||||
(roomid if roomid else sender), sender)
|
(roomid if roomid else sender), sender)
|
||||||
return True, "已签到"
|
return False, "已签到"
|
||||||
|
|
||||||
streak = 0
|
streak = 0
|
||||||
streak_broken = False
|
streak_broken = False
|
||||||
|
|||||||
Reference in New Issue
Block a user