feat(aurora): switch from dateparser to dateutil and add on parameter to history command
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Failing after 27s
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 42s

This commit is contained in:
Seaswimmer 2024-08-10 13:27:49 -04:00
parent 1a3af342df
commit 49cf7c9005
Signed by: cswimr
GPG key ID: 3813315477F26F82
4 changed files with 52 additions and 68 deletions

View file

@ -13,7 +13,7 @@ from datetime import datetime, timedelta, timezone
from math import ceil
import discord
from dateparser import parse
from dateutil.parser import ParserError, parse
from discord.ext import tasks
from redbot.core import app_commands, commands, data_manager
from redbot.core.app_commands import Choice
@ -521,6 +521,7 @@ class Aurora(commands.Cog):
moderator: discord.User | None = None,
pagesize: app_commands.Range[int, 1, 20] | None = None,
page: int = 1,
on: str | None = None,
before: str | None = None,
after: str | None = None,
ephemeral: bool | None = None,
@ -539,6 +540,8 @@ class Aurora(commands.Cog):
Amount of infractions to list per page
page: int
Page to select
on: str
List infractions on a certain date
before: str
List infractions before a certain date
after: str
@ -577,21 +580,53 @@ class Aurora(commands.Cog):
or 5
)
if before:
if before and not on:
try:
before = parse(before)
if before is None:
return await interaction.response.send_message(
content=error("Invalid date format for `before`."), ephemeral=True
except (ParserError, OverflowError) as e:
if e == ParserError:
await interaction.response.send_message(
content=error("Invalid date format for `before` parameter!"), ephemeral=True
)
before = before.replace(tzinfo=timezone.utc)
return
if e == OverflowError:
await interaction.response.send_message(
content=error("Date is too far in the future!"), ephemeral=True
)
return
if after:
if after and not on:
try:
after = parse(after)
if after is None:
return await interaction.response.send_message(
content=error("Invalid date format for `after`."), ephemeral=True
except (ParserError, OverflowError) as e:
if e == ParserError:
await interaction.response.send_message(
content=error("Invalid date format for `after` parameter!"), ephemeral=True
)
after = after.replace(tzinfo=timezone.utc)
return
if e == OverflowError:
await interaction.response.send_message(
content=error("Date is too far in the future!"), ephemeral=True
)
return
if on:
try:
on = parse(on)
except (ParserError, OverflowError) as e:
if e == ParserError:
await interaction.response.send_message(
content=error("Invalid date format for `on` parameter!"), ephemeral=True
)
return
if e == OverflowError:
await interaction.response.send_message(
content=error("Date is too far in the future!"), ephemeral=True
)
return
before = on + timedelta(days=1)
after = on - timedelta(days=1)
await interaction.response.defer(ephemeral=ephemeral)

View file

@ -9,7 +9,7 @@
"disabled": false,
"min_bot_version": "3.5.0",
"min_python_version": [3, 10, 0],
"requirements": ["pydantic", "aiosqlite", "phx-class-registry", "dateparser"],
"requirements": ["pydantic", "aiosqlite", "phx-class-registry"],
"tags": [
"mod",
"moderate",

52
poetry.lock generated
View file

@ -668,28 +668,6 @@ webencodings = "*"
doc = ["sphinx", "sphinx_rtd_theme"]
test = ["flake8", "isort", "pytest"]
[[package]]
name = "dateparser"
version = "1.2.0"
description = "Date parsing library designed to parse dates from HTML pages"
optional = false
python-versions = ">=3.7"
files = [
{file = "dateparser-1.2.0-py2.py3-none-any.whl", hash = "sha256:0b21ad96534e562920a0083e97fd45fa959882d4162acc358705144520a35830"},
{file = "dateparser-1.2.0.tar.gz", hash = "sha256:7975b43a4222283e0ae15be7b4999d08c9a70e2d378ac87385b1ccf2cffbbb30"},
]
[package.dependencies]
python-dateutil = "*"
pytz = "*"
regex = "<2019.02.19 || >2019.02.19,<2021.8.27 || >2021.8.27"
tzlocal = "*"
[package.extras]
calendars = ["convertdate", "hijri-converter"]
fasttext = ["fasttext"]
langdetect = ["langdetect"]
[[package]]
name = "defusedxml"
version = "0.7.1"
@ -2395,34 +2373,6 @@ files = [
{file = "typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"},
]
[[package]]
name = "tzdata"
version = "2024.1"
description = "Provider of IANA time zone data"
optional = false
python-versions = ">=2"
files = [
{file = "tzdata-2024.1-py2.py3-none-any.whl", hash = "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252"},
{file = "tzdata-2024.1.tar.gz", hash = "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd"},
]
[[package]]
name = "tzlocal"
version = "5.2"
description = "tzinfo object for the local timezone"
optional = false
python-versions = ">=3.8"
files = [
{file = "tzlocal-5.2-py3-none-any.whl", hash = "sha256:49816ef2fe65ea8ac19d19aa7a1ae0551c834303d5014c6d5a62e4cbda8047b8"},
{file = "tzlocal-5.2.tar.gz", hash = "sha256:8d399205578f1a9342816409cc1e46a93ebd5755e39ea2d85334bea911bf0e6e"},
]
[package.dependencies]
tzdata = {version = "*", markers = "platform_system == \"Windows\""}
[package.extras]
devenv = ["check-manifest", "pytest (>=4.3)", "pytest-cov", "pytest-mock (>=3.3)", "zest.releaser"]
[[package]]
name = "urllib3"
version = "2.2.1"
@ -2740,4 +2690,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = ">=3.11,<3.12"
content-hash = "bc58f1f72ca73806c414042a78294e73c4119906b57fceb045ab48414928849e"
content-hash = "6d09969e0ad7adff5aa105915c5c9e0354b4b7aceb80b9c2b3fb800bb08f21d4"

View file

@ -20,7 +20,6 @@ beautifulsoup4 = "^4.12.3"
markdownify = "^0.12.1"
aiosqlite = "^0.20.0"
phx-class-registry = "^4.1.0"
dateparser = "^1.2.0"
[tool.poetry.group.dev]
optional = true