Skip to content

Commit 1631a98

Browse files
committed
ExtendedEconomy - backpay command
1 parent f05f9ad commit 1631a98

File tree

1 file changed

+19
-67
lines changed

1 file changed

+19
-67
lines changed

extendedeconomy/commands/admin.py

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,21 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
589589

590590
# Get current time and the time to look back to
591591
current_time = calendar.timegm(datetime.now(tz=timezone.utc).utctimetuple())
592-
lookback_time = current_time - int(duration.total_seconds())
592+
593+
# Get the payday cooldown period
594+
if is_global:
595+
payday_time = await eco_conf.PAYDAY_TIME()
596+
payday_credits = await eco_conf.PAYDAY_CREDITS()
597+
else:
598+
payday_time = await eco_conf.guild(ctx.guild).PAYDAY_TIME()
599+
payday_credits = await eco_conf.guild(ctx.guild).PAYDAY_CREDITS()
600+
601+
# Calculate total possible paydays in the lookback period
602+
# This ensures everyone gets the same number of paydays for the same duration
603+
total_possible_paydays = int(duration.total_seconds() // payday_time)
604+
605+
if total_possible_paydays <= 0:
606+
return await ctx.send(_("The specified duration is too short for any paydays."))
593607

594608
# Create a list to store the report data
595609
report_data = []
@@ -601,8 +615,6 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
601615
ecogroup = eco_conf._get_base_group(eco_conf.USER)
602616
accounts: t.Dict[str, dict] = await bankgroup.all()
603617
ecousers: t.Dict[str, dict] = await ecogroup.all()
604-
payday_time = await eco_conf.PAYDAY_TIME()
605-
payday_credits = await eco_conf.PAYDAY_CREDITS()
606618

607619
for member in ctx.guild.members:
608620
uid = str(member.id)
@@ -611,37 +623,8 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
611623
if uid not in accounts or uid not in ecousers:
612624
continue
613625

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
638-
else:
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
642-
643-
if potential_paydays <= 0:
644-
continue
626+
# All eligible users get the same number of paydays
627+
potential_paydays = total_possible_paydays
645628

646629
# Calculate amount to give (base amount * number of paydays)
647630
amount_to_give = payday_credits * potential_paydays
@@ -685,8 +668,6 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
685668
ecogroup = eco_conf._get_base_group(eco_conf.MEMBER, str(ctx.guild.id))
686669
accounts: t.Dict[str, dict] = await bankgroup.all()
687670
ecousers: t.Dict[str, dict] = await ecogroup.all()
688-
payday_time = await eco_conf.guild(ctx.guild).PAYDAY_TIME()
689-
payday_credits = await eco_conf.guild(ctx.guild).PAYDAY_CREDITS()
690671
payday_roles: t.Dict[int, dict] = await eco_conf.all_roles()
691672

692673
for member in ctx.guild.members:
@@ -696,37 +677,8 @@ async def backpay_cmd(self, ctx: commands.Context, duration: commands.TimedeltaC
696677
if uid not in accounts or uid not in ecousers:
697678
continue
698679

699-
# Get the last payday timestamp
700-
last_payday_time = ecousers[uid].get("next_payday", 0)
701-
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
723-
else:
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
727-
728-
if potential_paydays <= 0:
729-
continue
680+
# All eligible users get the same number of paydays
681+
potential_paydays = total_possible_paydays
730682

731683
# Calculate per-payday amount with role bonuses
732684
base_amount = payday_credits

0 commit comments

Comments
 (0)