Ejemplo n.º 1
0
    async def branding_set(self,
                           ctx: commands.Context,
                           *,
                           season_name: t.Optional[str] = None) -> None:
        """
        Manually set season, or reset to current if none given.

        Season search is a case-less comparison against both seasonal class name,
        and its `season_name` attr.

        This only pre-loads the cog's internal state to the chosen season, but does not
        automatically apply the branding. As that is an expensive operation, the `apply`
        command must be called explicitly after this command finishes.

        This means that this command can be used to 'preview' a season gathering info
        about its available assets, without applying them to the guild.

        If the daemon is running, it will automatically reset the season to current when
        it wakes up. The season set via this command can therefore remain 'detached' from
        what it should be - the daemon will make sure that it's set back properly.
        """
        if season_name is None:
            new_season = get_current_season()
        else:
            new_season = get_season(season_name)
            if new_season is None:
                raise BrandingError("No such season exists")

        if self.current_season is new_season:
            raise BrandingError(
                f"Season {self.current_season.season_name} already active")

        self.current_season = new_season
        await self.branding_refresh(ctx)
Ejemplo n.º 2
0
    async def daemon_stop(self, ctx: commands.Context) -> None:
        """If the daemon is running, stop it."""
        if not self._daemon_running:
            raise BrandingError("Daemon not running!")

        self.daemon.cancel()
        self._write_config("daemon_active", False)

        response = discord.Embed(description=f"Daemon stopped {Emojis.ok_hand}", colour=Colours.soft_green)
        await ctx.send(embed=response)
Ejemplo n.º 3
0
    async def daemon_start(self, ctx: commands.Context) -> None:
        """If the daemon isn't running, start it."""
        if self._daemon_running:
            raise BrandingError("Daemon already running!")

        self.daemon = self.bot.loop.create_task(self._daemon_func())
        self._write_config("daemon_active", True)

        response = discord.Embed(description=f"Daemon started {Emojis.ok_hand}", colour=Colours.soft_green)
        await ctx.send(embed=response)
Ejemplo n.º 4
0
    async def branding_cycle(self, ctx: commands.Context) -> None:
        """
        Apply the next-up guild icon, if multiple are available.

        The order is random.
        """
        async with ctx.typing():
            success = await self.cycle()
            if not success:
                raise BrandingError("Failed to cycle icon")

            response = discord.Embed(description=f"Success {Emojis.ok_hand}", colour=Colours.soft_green)
            await ctx.send(embed=response)
Ejemplo n.º 5
0
    async def branding_apply(self, ctx: commands.Context) -> None:
        """
        Apply current season's branding to the guild.

        Use `info` to check which assets will be applied. Shows which assets have
        failed to be applied, if any.
        """
        async with ctx.typing():
            failed_assets = await self.apply()
            if failed_assets:
                raise BrandingError(f"Failed to apply following assets: {', '.join(failed_assets)}")

            response = discord.Embed(description=f"All assets applied {Emojis.ok_hand}", colour=Colours.soft_green)
            await ctx.send(embed=response)
Ejemplo n.º 6
0
def _validate_season_overlap() -> None:
    """
    Raise BrandingError if there are any colliding seasons.

    This serves as a local test to ensure that seasons haven't been misconfigured.
    """
    month_to_season = {}

    for season in SeasonBase.__subclasses__():
        for month in season.months:
            colliding_season = month_to_season.get(month)

            if colliding_season:
                raise BrandingError(
                    f"Season {season} collides with {colliding_season} in {month.name}"
                )
            else:
                month_to_season[month] = season