diff options
author | 2020-02-23 20:09:26 +0100 | |
---|---|---|
committer | 2020-02-23 20:09:26 +0100 | |
commit | 9330b404316cb00379f6eb5074b7ace842cedc8b (patch) | |
tree | 7a23091700eba50711e1232f444368c4711ccd0f | |
parent | Add icon cycle frequency constant (diff) |
Cycle icons within season in configured interval only
The `load_seasons` task now has an internal state, which increments for
every day. Before cycling the icon within the same season, first check
whether we've waited the configured amount of days since the last cycle.
Entering a new season, or changing the icon, resets the state to 0.
This allows us to slow down the rate at which we cycle icons, addressing
a bug where the icon wasn't loading for some users.
-rw-r--r-- | bot/seasons/season.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/bot/seasons/season.py b/bot/seasons/season.py index 8fc68491..763a08d2 100644 --- a/bot/seasons/season.py +++ b/bot/seasons/season.py @@ -383,18 +383,29 @@ class SeasonManager(commands.Cog): """Asynchronous timer loop to check for a new season every midnight.""" await self.bot.wait_until_ready() await self.season.load() + days_since_icon_change = 0 while True: await asyncio.sleep(self.sleep_time) # Sleep until midnight self.sleep_time = 24 * 3600 # Next time, sleep for 24 hours + days_since_icon_change += 1 + log.debug(f"Days since last icon change: {days_since_icon_change}") + # If the season has changed, load it. new_season = get_season(date=datetime.datetime.utcnow()) if new_season.name != self.season.name: self.season = new_season await self.season.load() + days_since_icon_change = 0 # Start counting afresh for the new season + + # Otherwise we check whether it's time for an icon cycle within the current season else: - await self.season.change_server_icon() + if days_since_icon_change == Client.icon_cycle_frequency: + await self.season.change_server_icon() + days_since_icon_change = 0 + else: + log.debug(f"Waiting {Client.icon_cycle_frequency - days_since_icon_change} more days to cycle icon") @with_role(Roles.moderator, Roles.admin, Roles.owner) @commands.command(name="season") |