aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2021-08-05 21:26:36 -0700
committerGravatar MarkKoz <[email protected]>2021-08-05 21:26:36 -0700
commit75fabfc0f1a9d95a1167dd6f3d94b741768b72e8 (patch)
tree3515b7ae2b2d15d882c420522ab96953836e053b
parentTime: support more timestamp formats as arguments (diff)
Time: remove DISCORD_TIMESTAMP_REGEX
There's a saner way to parse the timestamp that relied on this regex.
-rw-r--r--bot/exts/moderation/infraction/management.py15
-rw-r--r--bot/utils/time.py2
2 files changed, 6 insertions, 11 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index 23c6e8b92..fa1ebdadc 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -1,8 +1,7 @@
import textwrap
import typing as t
-from datetime import datetime, timezone
-import dateutil.parser
+import arrow
import discord
from dateutil.relativedelta import relativedelta
from discord.ext import commands
@@ -351,7 +350,8 @@ class ModManagement(commands.Cog):
active = infraction["active"]
user = infraction["user"]
expires_at = infraction["expires_at"]
- created = time.discord_timestamp(infraction["inserted_at"])
+ inserted_at = infraction["inserted_at"]
+ created = time.discord_timestamp(inserted_at)
dm_sent = infraction["dm_sent"]
# Format the user string.
@@ -371,12 +371,9 @@ class ModManagement(commands.Cog):
if expires_at is None:
duration = "*Permanent*"
else:
- date_from = datetime.fromtimestamp(
- float(time.DISCORD_TIMESTAMP_REGEX.match(created).group(1)),
- timezone.utc
- )
- date_to = dateutil.parser.isoparse(expires_at)
- duration = time.humanize_delta(relativedelta(date_to, date_from))
+ start = arrow.get(inserted_at).datetime
+ end = arrow.get(expires_at).datetime
+ duration = time.humanize_delta(relativedelta(start, end))
# Format `dm_sent`
if dm_sent is None:
diff --git a/bot/utils/time.py b/bot/utils/time.py
index e927a5e63..21d26db7d 100644
--- a/bot/utils/time.py
+++ b/bot/utils/time.py
@@ -7,8 +7,6 @@ from typing import Optional, Union
import arrow
from dateutil.relativedelta import relativedelta
-DISCORD_TIMESTAMP_REGEX = re.compile(r"<t:(\d+):f>")
-
_DURATION_REGEX = re.compile(
r"((?P<years>\d+?) ?(years|year|Y|y) ?)?"
r"((?P<months>\d+?) ?(months|month|m) ?)?"