diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/moderation/scheduler.py | 23 | 
1 files changed, 9 insertions, 14 deletions
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py index d75a72ddb..601e238c9 100644 --- a/bot/cogs/moderation/scheduler.py +++ b/bot/cogs/moderation/scheduler.py @@ -1,4 +1,3 @@ -import asyncio  import logging  import textwrap  import typing as t @@ -23,13 +22,13 @@ from .utils import UserSnowflake  log = logging.getLogger(__name__) -class InfractionScheduler(Scheduler): +class InfractionScheduler:      """Handles the application, pardoning, and expiration of infractions."""      def __init__(self, bot: Bot, supported_infractions: t.Container[str]): -        super().__init__() -          self.bot = bot +        self.scheduler = Scheduler(self.__class__.__name__) +          self.bot.loop.create_task(self.reschedule_infractions(supported_infractions))      @property @@ -49,7 +48,7 @@ class InfractionScheduler(Scheduler):          )          for infraction in infractions:              if infraction["expires_at"] is not None and infraction["type"] in supported_infractions: -                self.schedule_task(infraction["id"], infraction) +                self.schedule_expiration(infraction)      async def reapply_infraction(          self, @@ -155,7 +154,7 @@ class InfractionScheduler(Scheduler):                  await action_coro                  if expiry:                      # Schedule the expiration of the infraction. -                    self.schedule_task(infraction["id"], infraction) +                    self.schedule_expiration(infraction)              except discord.HTTPException as e:                  # Accordingly display that applying the infraction failed.                  confirm_msg = ":x: failed to apply" @@ -278,7 +277,7 @@ class InfractionScheduler(Scheduler):                  # Cancel pending expiration task.                  if infraction["expires_at"] is not None: -                    self.cancel_task(infraction["id"]) +                    self.scheduler.cancel(infraction["id"])          # Accordingly display whether the user was successfully notified via DM.          dm_emoji = "" @@ -415,7 +414,7 @@ class InfractionScheduler(Scheduler):          # Cancel the expiration task.          if infraction["expires_at"] is not None: -            self.cancel_task(infraction["id"]) +            self.scheduler.cancel(infraction["id"])          # Send a log message to the mod log.          if send_log: @@ -449,7 +448,7 @@ class InfractionScheduler(Scheduler):          """          raise NotImplementedError -    async def _scheduled_task(self, infraction: utils.Infraction) -> None: +    def schedule_expiration(self, infraction: utils.Infraction) -> None:          """          Marks an infraction expired after the delay from time of scheduling to time of expiration. @@ -457,8 +456,4 @@ class InfractionScheduler(Scheduler):          expiration task is cancelled.          """          expiry = dateutil.parser.isoparse(infraction["expires_at"]).replace(tzinfo=None) -        await time.wait_until(expiry) - -        # Because deactivate_infraction() explicitly cancels this scheduled task, it is shielded -        # to avoid prematurely cancelling itself. -        await asyncio.shield(self.deactivate_infraction(infraction)) +        self.scheduler.schedule_at(expiry, infraction["id"], self.deactivate_infraction(infraction))  |