예제 #1
0
파일: defcon.py 프로젝트: scragly/bot
    async def _sync_settings(self) -> None:
        """On cog load, try to synchronize DEFCON settings to the API."""
        log.trace("Waiting for the guild to become available before syncing.")
        await self.bot.wait_until_guild_available()
        self.channel = await self.bot.fetch_channel(Channels.defcon)

        log.trace("Syncing settings.")

        try:
            settings = await self.defcon_settings.to_dict()
            self.threshold = parse_duration_string(
                settings["threshold"]) if settings.get("threshold") else None
            self.expiry = datetime.fromisoformat(
                settings["expiry"]) if settings.get("expiry") else None
        except RedisError:
            log.exception("Unable to get DEFCON settings!")
            await self.channel.send(
                f"<@&{Roles.moderators}> <@&{Roles.devops}> **WARNING**: Unable to get DEFCON settings!"
                f"\n\n```{traceback.format_exc()}```")

        else:
            if self.expiry:
                self.scheduler.schedule_at(self.expiry, 0,
                                           self._remove_threshold())

            self._update_notifier()
            log.info(
                f"DEFCON synchronized: {humanize_delta(self.threshold) if self.threshold else '-'}"
            )

        self._update_channel_topic()
예제 #2
0
    async def convert(self, ctx: Context, duration: str) -> relativedelta:
        """
        Converts a `duration` string to a relativedelta object.

        The converter supports the following symbols for each unit of time:
        - years: `Y`, `y`, `year`, `years`
        - months: `m`, `month`, `months`
        - weeks: `w`, `W`, `week`, `weeks`
        - days: `d`, `D`, `day`, `days`
        - hours: `H`, `h`, `hour`, `hours`
        - minutes: `M`, `minute`, `minutes`
        - seconds: `S`, `s`, `second`, `seconds`

        The units need to be provided in descending order of magnitude.
        """
        if not (delta := parse_duration_string(duration)):
            raise BadArgument(f"`{duration}` is not a valid duration string.")