修复重复签到bug

This commit is contained in:
liuwei
2025-03-05 10:25:00 +08:00
parent 943a8df7d4
commit 38b30eded9
2 changed files with 13 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
[SignIn]
enable = true
command = ["签到", "每日签到", "qd", "Qd", "QD"]
command = ["签到", "每日签到", "qd", "Qd", "QD", "上班"]
min-point = 3
max-point = 20
streak-cycle = 5 # 每签到?天后额外积分奖励加1点

View File

@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, timedelta
import logging
import mysql.connector.pooling
import tomllib
@@ -161,16 +161,24 @@ class SignInSystem:
if self.gbm.get_group_permission(message.roomid, Feature.SIGNIN) == PermissionStatus.DISABLED:
return
current_time = datetime.datetime.now(tz=pytz.timezone(self.timezone))
today_start = current_time.replace(hour=0, minute=0, second=0, microsecond=0)
yesterday = today_start - datetime.timedelta(days=1)
# 获取当前时间,带有时区信息
current_time = datetime.now(tz=pytz.timezone(self.timezone))
# 获取当天零点的时间
today_start = current_time.replace(hour=0, minute=0, second=0, microsecond=0)
# 获取昨天的时间
yesterday = today_start - timedelta(days=1)
# 获取用户的签到记录
user_record = self.get_user_record(message.sender, message.roomid)
wx_nick_name = self.all_contacts.get(message.sender, message.sender)
# 判断用户是否已经签到过
if user_record and user_record['sign_stat'] and user_record['sign_stat'] >= today_start:
self.wcf.send_text(
f"@{wx_nick_name} 您今天已经签到过了!当前积分:{user_record['points']}",
(message.roomid if message.from_group() else message.sender),
message.sender
)
return
@@ -230,4 +238,3 @@ class SignInSystem:
def __del__(self):
"""连接池由外部管理,不需要手动关闭"""
pass