diff options
-rw-r--r-- | bot/cogs/moderation/management.py | 4 | ||||
-rw-r--r-- | bot/cogs/moderation/scheduler.py | 2 | ||||
-rw-r--r-- | bot/utils/time.py | 19 |
3 files changed, 9 insertions, 16 deletions
diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py index 5221baa81..abfe5c2b3 100644 --- a/bot/cogs/moderation/management.py +++ b/bot/cogs/moderation/management.py @@ -97,7 +97,7 @@ class ModManagement(commands.Cog): confirm_messages.append("marked as permanent") elif duration is not None: request_data['expires_at'] = duration.isoformat() - expiry = time.get_duration_from_expiry(request_data['expires_at']) + expiry = time.format_infraction_with_duration(request_data['expires_at']) confirm_messages.append(f"set to expire on {expiry}") else: confirm_messages.append("expiry unchanged") @@ -236,7 +236,7 @@ class ModManagement(commands.Cog): expires = "*Permanent*" else: date_from = datetime.strptime(created, time.INFRACTION_FORMAT) - expires = time.get_duration_from_expiry(infraction["expires_at"], date_from) + expires = time.format_infraction_with_duration(infraction["expires_at"], date_from) lines = textwrap.dedent(f""" {"**===============**" if active else "==============="} diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py index 729763322..3e0968121 100644 --- a/bot/cogs/moderation/scheduler.py +++ b/bot/cogs/moderation/scheduler.py @@ -83,7 +83,7 @@ class InfractionScheduler(Scheduler): infr_type = infraction["type"] icon = utils.INFRACTION_ICONS[infr_type][0] reason = infraction["reason"] - expiry = time.get_duration_from_expiry(infraction["expires_at"]) + expiry = time.format_infraction_with_duration(infraction["expires_at"]) id_ = infraction['id'] log.trace(f"Applying {infr_type} infraction #{id_} to {user}.") diff --git a/bot/utils/time.py b/bot/utils/time.py index ec47fce2e..a024674ac 100644 --- a/bot/utils/time.py +++ b/bot/utils/time.py @@ -113,21 +113,14 @@ def format_infraction(timestamp: str) -> str: return dateutil.parser.isoparse(timestamp).strftime(INFRACTION_FORMAT) -def get_duration_from_expiry( - expiry: str = None, - date_from: datetime.datetime = None, - max_units: int = 2 -) -> Optional[str]: +def format_infraction_with_duration(expiry: str, date_from: datetime.datetime = None, max_units: int = 2) -> str: """ - Returns a human-readable version of the the duration between datetime.utcnow() and an expiry. + Format an infraction timestamp to a more readable ISO 8601 format WITH the duration. - Unlike the original function, this function will force the precision to be 'seconds' by not passing it. - max_units specifies the maximum number of units of time to include (e.g. 1 may include days but not hours). - By default, max_units is 2 - - :param expiry: A string. If not passed in, will early return a None ( Permanent infraction ). - :param date_from: A datetime.datetime object. If not passed in, will use datetime.utcnow(). - :param parts: An int, to show how many parts will be returned ( year - month or year - month - week - day ...). + Returns a human-readable version of the duration between datetime.utcnow() and an expiry. + Unlike `humanize_delta`, this function will force the `precision` to be `seconds` by not passing it. + `max_units` specifies the maximum number of units of time to include (e.g. 1 may include days but not hours). + By default, max_units is 2. """ if not expiry: return None |