wacca: fix first play of the day calculation

This commit is contained in:
Hay1tsme 2023-04-19 16:12:35 -04:00
parent 017ef1e224
commit 68b0894e47
2 changed files with 19 additions and 41 deletions

View File

@ -183,8 +183,6 @@ class WaccaBase:
def handle_user_status_login_request(self, data: Dict) -> Dict: def handle_user_status_login_request(self, data: Dict) -> Dict:
req = UserStatusLoginRequest(data) req = UserStatusLoginRequest(data)
resp = UserStatusLoginResponseV1() resp = UserStatusLoginResponseV1()
is_new_day = False
is_consec_day = False
is_consec_day = True is_consec_day = True
if req.userId == 0: if req.userId == 0:
@ -202,29 +200,23 @@ class WaccaBase:
self.logger.info(f"User {req.userId} login on {req.chipId}") self.logger.info(f"User {req.userId} login on {req.chipId}")
last_login_time = int(profile["last_login_date"].timestamp()) last_login_time = int(profile["last_login_date"].timestamp())
resp.lastLoginDate = last_login_time resp.lastLoginDate = last_login_time
midnight_today_ts = int(datetime.now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp())
# If somebodies login timestamp < midnight of current day, then they are logging in for the first time today # If somebodies login timestamp < midnight of current day, then they are logging in for the first time today
if last_login_time < int( if last_login_time < midnight_today_ts:
datetime.now() resp.firstLoginDaily = True
.replace(hour=0, minute=0, second=0, microsecond=0)
.timestamp() # If the difference between midnight today and their last login is greater then 1 day (86400 seconds) they've broken their streak
): if midnight_today_ts - last_login_time > 86400:
is_new_day = True
is_consec_day = True
# If somebodies login timestamp > midnight of current day + 1 day, then they broke their daily login streak
elif last_login_time > int(
(
datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
+ timedelta(days=1)
).timestamp()
):
is_consec_day = False is_consec_day = False
# else, they are simply logging in again on the same day, and we don't need to do anything for that
self.data.profile.session_login(req.userId, is_new_day, is_consec_day) self.data.profile.session_login(req.userId, resp.firstLoginDaily, is_consec_day)
if resp.firstLoginDaily:
# TODO: Daily bonus
pass
resp.firstLoginDaily = int(is_new_day) # TODO: VIP dialy/monthly rewards
return resp.make() return resp.make()

View File

@ -143,8 +143,6 @@ class WaccaLily(WaccaS):
def handle_user_status_login_request(self, data: Dict) -> Dict: def handle_user_status_login_request(self, data: Dict) -> Dict:
req = UserStatusLoginRequest(data) req = UserStatusLoginRequest(data)
resp = UserStatusLoginResponseV2() resp = UserStatusLoginResponseV2()
is_new_day = False
is_consec_day = False
is_consec_day = True is_consec_day = True
if req.userId == 0: if req.userId == 0:
@ -162,34 +160,22 @@ class WaccaLily(WaccaS):
self.logger.info(f"User {req.userId} login on {req.chipId}") self.logger.info(f"User {req.userId} login on {req.chipId}")
last_login_time = int(profile["last_login_date"].timestamp()) last_login_time = int(profile["last_login_date"].timestamp())
resp.lastLoginDate = last_login_time resp.lastLoginDate = last_login_time
midnight_today_ts = int(datetime.now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp())
# If somebodies login timestamp < midnight of current day, then they are logging in for the first time today # If somebodies login timestamp < midnight of current day, then they are logging in for the first time today
if last_login_time < int( if last_login_time < midnight_today_ts:
datetime.now() resp.firstLoginDaily = True
.replace(hour=0, minute=0, second=0, microsecond=0)
.timestamp() # If the difference between midnight today and their last login is greater then 1 day (86400 seconds) they've broken their streak
): if midnight_today_ts - last_login_time > 86400:
is_new_day = True
is_consec_day = True
# If somebodies login timestamp > midnight of current day + 1 day, then they broke their daily login streak
elif last_login_time > int(
(
datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
+ timedelta(days=1)
).timestamp()
):
is_consec_day = False is_consec_day = False
# else, they are simply logging in again on the same day, and we don't need to do anything for that
self.data.profile.session_login(req.userId, is_new_day, is_consec_day) self.data.profile.session_login(req.userId, resp.firstLoginDaily, is_consec_day)
resp.vipInfo.pageYear = datetime.now().year resp.vipInfo.pageYear = datetime.now().year
resp.vipInfo.pageMonth = datetime.now().month resp.vipInfo.pageMonth = datetime.now().month
resp.vipInfo.pageDay = datetime.now().day resp.vipInfo.pageDay = datetime.now().day
resp.vipInfo.numItem = 1 resp.vipInfo.numItem = 1
resp.firstLoginDaily = int(is_new_day)
return resp.make() return resp.make()
def handle_user_status_getDetail_request(self, data: Dict) -> Dict: def handle_user_status_getDetail_request(self, data: Dict) -> Dict: