Skip to content

Commit f05f9ad

Browse files
committed
ExtendedEconomy - backpay command
1 parent 2223b15 commit f05f9ad

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

extendedeconomy/commands/admin.py

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -611,28 +611,34 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
611611
if uid not in accounts or uid not in ecousers:
612612
continue
613613

614-
# Calculate how many paydays they could have claimed
615-
next_payday_timestamp = ecousers[uid].get("next_payday", 0)
616-
617-
# Calculate how many full payday periods have passed since lookback_time
618-
# Handle case where user has never claimed a payday
619-
if next_payday_timestamp == 0:
620-
# User has never claimed payday, assume they could claim from the lookback time
621-
potential_paydays = (current_time - lookback_time) // payday_time
614+
# Get the last payday timestamp
615+
last_payday_time = ecousers[uid].get("next_payday", 0)
616+
617+
# If they've never used payday before, assume they could claim from lookback time
618+
if last_payday_time == 0:
619+
last_payday_time = lookback_time - payday_time # Make them eligible for one at lookback time
620+
621+
# Calculate maximum possible paydays in the time window
622+
# We start from max(last_payday_time, lookback_time - payday_time)
623+
# This ensures we count a payday right at the lookback boundary if they're eligible
624+
earliest_payday = max(last_payday_time, lookback_time - payday_time)
625+
626+
# How many complete payday periods fit between earliest_payday and now?
627+
# Note that we need to add payday_time to earliest_payday because the Economy cog
628+
# sets next_payday to the time of last claim, not the time of next eligibility
629+
time_until_eligible = earliest_payday + payday_time
630+
631+
# If they aren't eligible for a payday yet at the lookback time,
632+
# we use their first eligible time after lookback
633+
time_until_eligible = max(time_until_eligible, lookback_time)
634+
635+
# Now count how many paydays fit between their eligibility time and now
636+
if time_until_eligible > current_time:
637+
potential_paydays = 0 # They aren't eligible for any paydays yet
622638
else:
623-
# Check if user's next payday is after our lookback time
624-
if next_payday_timestamp > lookback_time:
625-
# Calculate how many complete payday periods have passed
626-
# between their next available payday and now
627-
time_since_next_available = max(0, current_time - next_payday_timestamp)
628-
potential_paydays = time_since_next_available // payday_time
629-
else:
630-
# They could have claimed from the lookback time to now,
631-
# plus one more if their next payday was before lookback
632-
potential_paydays = (current_time - lookback_time) // payday_time
633-
# Add 1 if they could have claimed right at lookback time
634-
if next_payday_timestamp <= lookback_time:
635-
potential_paydays += 1
639+
# How many full payday periods fit between their eligibility and now
640+
potential_paydays = (current_time - time_until_eligible) // payday_time + 1
641+
# The +1 accounts for the payday they're eligible for at time_until_eligible
636642

637643
if potential_paydays <= 0:
638644
continue
@@ -690,28 +696,34 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
690696
if uid not in accounts or uid not in ecousers:
691697
continue
692698

693-
# Calculate how many paydays they could have claimed
694-
next_payday_timestamp = ecousers[uid].get("next_payday", 0)
699+
# Get the last payday timestamp
700+
last_payday_time = ecousers[uid].get("next_payday", 0)
695701

696-
# Calculate how many full payday periods have passed since lookback_time
697-
# Handle case where user has never claimed a payday
698-
if next_payday_timestamp == 0:
699-
# User has never claimed payday, assume they could claim from the lookback time
700-
potential_paydays = (current_time - lookback_time) // payday_time
702+
# If they've never used payday before, assume they could claim from lookback time
703+
if last_payday_time == 0:
704+
last_payday_time = lookback_time - payday_time # Make them eligible for one at lookback time
705+
706+
# Calculate maximum possible paydays in the time window
707+
# We start from max(last_payday_time, lookback_time - payday_time)
708+
# This ensures we count a payday right at the lookback boundary if they're eligible
709+
earliest_payday = max(last_payday_time, lookback_time - payday_time)
710+
711+
# How many complete payday periods fit between earliest_payday and now?
712+
# Note that we need to add payday_time to earliest_payday because the Economy cog
713+
# sets next_payday to the time of last claim, not the time of next eligibility
714+
time_until_eligible = earliest_payday + payday_time
715+
716+
# If they aren't eligible for a payday yet at the lookback time,
717+
# we use their first eligible time after lookback
718+
time_until_eligible = max(time_until_eligible, lookback_time)
719+
720+
# Now count how many paydays fit between their eligibility time and now
721+
if time_until_eligible > current_time:
722+
potential_paydays = 0 # They aren't eligible for any paydays yet
701723
else:
702-
# Check if user's next payday is after our lookback time
703-
if next_payday_timestamp > lookback_time:
704-
# Calculate how many complete payday periods have passed
705-
# between their next available payday and now
706-
time_since_next_available = max(0, current_time - next_payday_timestamp)
707-
potential_paydays = time_since_next_available // payday_time
708-
else:
709-
# They could have claimed from the lookback time to now,
710-
# plus one more if their next payday was before lookback
711-
potential_paydays = (current_time - lookback_time) // payday_time
712-
# Add 1 if they could have claimed right at lookback time
713-
if next_payday_timestamp <= lookback_time:
714-
potential_paydays += 1
724+
# How many full payday periods fit between their eligibility and now
725+
potential_paydays = (current_time - time_until_eligible) // payday_time + 1
726+
# The +1 accounts for the payday they're eligible for at time_until_eligible
715727

716728
if potential_paydays <= 0:
717729
continue

0 commit comments

Comments
 (0)