Implemented "/user update_channels" (#10)

This commit is contained in:
2025-05-02 14:07:00 +02:00
parent 5507295b1b
commit 3dcae36dec
6 changed files with 110 additions and 36 deletions

View File

@@ -24,6 +24,7 @@ from modules.utils import (
)
# noinspection Mypy
class CogEvent(Cog):
"""Cog with event management commands."""
@@ -94,11 +95,8 @@ class CogEvent(Cog):
guild_timezone: ZoneInfo = ZoneInfo(guild.timezone)
try:
start_date: datetime = datetime.strptime(start, "%d.%m.%Y %H:%M")
end_date: datetime = datetime.strptime(end, "%d.%m.%Y %H:%M")
start_date = start_date.replace(tzinfo=guild_timezone)
end_date = end_date.replace(tzinfo=guild_timezone)
start_date: datetime = datetime.strptime(start, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
end_date: datetime = datetime.strptime(end, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
except ValueError:
# TODO Introduce i18n
await ctx.respond(
@@ -202,13 +200,9 @@ class CogEvent(Cog):
try:
start_date: datetime = (
pycord_event.starts if start is None else datetime.strptime(start, "%d.%m.%Y %H:%M")
)
start_date = (
start_date.replace(tzinfo=ZoneInfo("UTC"))
pycord_event.starts.replace(tzinfo=ZoneInfo("UTC"))
if start is None
else start_date.replace(tzinfo=guild_timezone)
else datetime.strptime(start, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
)
except ValueError:
# TODO Make a nice message
@@ -219,13 +213,9 @@ class CogEvent(Cog):
try:
end_date: datetime = (
pycord_event.ends if end is None else datetime.strptime(end, "%d.%m.%Y %H:%M")
)
end_date = (
end_date.replace(tzinfo=ZoneInfo("UTC"))
pycord_event.ends.replace(tzinfo=ZoneInfo("UTC"))
if end is None
else end_date.replace(tzinfo=guild_timezone)
else datetime.strptime(end, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
)
except ValueError:
# TODO Make a nice message
@@ -234,7 +224,14 @@ class CogEvent(Cog):
)
return
if not await validate_event_validity(ctx, name, start_date, end_date, to_utc=True):
if not await validate_event_validity(
ctx,
pycord_event.name if name is None else name,
start_date,
end_date,
event_id=pycord_event._id,
to_utc=True,
):
return
processed_media: List[Dict[str, Any]] = (