diff options
author | 2020-03-14 23:52:14 +0100 | |
---|---|---|
committer | 2020-03-14 23:53:20 +0100 | |
commit | fad81522959573c7ed7fbdc0cadfc93b783400d5 (patch) | |
tree | a978d3e51a8fe75704be54d0a71de0d7fd3d0679 | |
parent | Deseasonify: implement `BrandingManager` cog (diff) |
Deseasonify: improve logic in `set` command
Prevent re-applying branding if the user requests an already active
season. This saves us an expensive operation.
Only trigger typing if season switch was successful and `apply` will
be called, as otherwise the bot will respond immediately.
-rw-r--r-- | bot/seasons/branding.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/bot/seasons/branding.py b/bot/seasons/branding.py index a2ea5172..1cbc7e50 100644 --- a/bot/seasons/branding.py +++ b/bot/seasons/branding.py @@ -290,20 +290,21 @@ class BrandingManager(commands.Cog): @branding_cmds.command(name="set") async def branding_set(self, ctx: commands.Context, season_name: t.Optional[str] = None) -> None: """Manually set season if `season_name` is provided, otherwise reset to current.""" - async with ctx.typing(): - if season_name is None: - self.current_season = get_current_season() - else: - found_season = get_season(season_name) - - if found_season is None: - raise commands.BadArgument("No such season exists") - - self.current_season = found_season - - await self.refresh() - await self.apply() - await self.branding_info(ctx) + if season_name is None: + new_season = get_current_season() + else: + new_season = get_season(season_name) + if new_season is None: + raise commands.BadArgument("No such season exists") + + if self.current_season is not new_season: + async with ctx.typing(): + self.current_season = new_season + await self.refresh() + await self.apply() + await self.branding_info(ctx) + else: + await ctx.send(f"Season {self.current_season.season_name} already active") def setup(bot: SeasonalBot) -> None: |