From 6ddaff62603ffbd1a8c32f38198cadb617667684 Mon Sep 17 00:00:00 2001 From: Hugo Hedlund Date: Fri, 14 Feb 2020 15:13:18 +0100 Subject: [PATCH] Payday should store the last time it was used so it can be compared to the cooldown value rather than using a cooldown deco that won't reset if cooldown goes lower (#3496) * Payday #3438 Changed next_payday to last_payday * Created towncrier entry * [PR #3496] Requested changes * rm .vs --- changelog.d/economy/3438.bugfix.rst | 1 + redbot/cogs/economy/economy.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 changelog.d/economy/3438.bugfix.rst diff --git a/changelog.d/economy/3438.bugfix.rst b/changelog.d/economy/3438.bugfix.rst new file mode 100644 index 000000000..6e748956f --- /dev/null +++ b/changelog.d/economy/3438.bugfix.rst @@ -0,0 +1 @@ +Changes next_payday to last_payday. last_payday stores the latest time the command runned successfully, allows the command to dynamicly change with the PAYDAY_TIME variable, by checking if last_payday + PAYDAY_TIME >= current time. \ No newline at end of file diff --git a/redbot/cogs/economy/economy.py b/redbot/cogs/economy/economy.py index 7029cedae..3c4706269 100644 --- a/redbot/cogs/economy/economy.py +++ b/redbot/cogs/economy/economy.py @@ -349,7 +349,11 @@ class Economy(commands.Cog): cur_time = calendar.timegm(ctx.message.created_at.utctimetuple()) credits_name = await bank.get_currency_name(ctx.guild) if await bank.is_global(): # Role payouts will not be used - next_payday = await self.config.user(author).next_payday() + + # Gets the latest time the user used the command successfully and adds the global payday time + next_payday = ( + await self.config.user(author).next_payday() + await self.config.PAYDAY_TIME() + ) if cur_time >= next_payday: try: await bank.deposit_credits(author, await self.config.PAYDAY_CREDITS()) @@ -365,8 +369,8 @@ class Economy(commands.Cog): ) ) return - next_payday = cur_time + await self.config.PAYDAY_TIME() - await self.config.user(author).next_payday.set(next_payday) + # Sets the current time as the latest payday + await self.config.user(author).next_payday.set(cur_time) pos = await bank.get_leaderboard_position(author) await ctx.send( @@ -392,7 +396,12 @@ class Economy(commands.Cog): ).format(author=author, time=dtime) ) else: - next_payday = await self.config.member(author).next_payday() + + # Gets the users latest successfully payday and adds the guilds payday time + next_payday = ( + await self.config.member(author).next_payday() + + self.config.guild(guild).PAYDAY_TIME() + ) if cur_time >= next_payday: credit_amount = await self.config.guild(guild).PAYDAY_CREDITS() for role in author.roles: @@ -415,7 +424,10 @@ class Economy(commands.Cog): ) ) return - next_payday = cur_time + await self.config.guild(guild).PAYDAY_TIME() + + # Sets the latest payday time to the current time + next_payday = cur_time + await self.config.member(author).next_payday.set(next_payday) pos = await bank.get_leaderboard_position(author) await ctx.send(