Implemented /event add
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from discord import ApplicationContext, Attachment, SlashCommandGroup, option
|
||||
from discord.ext.commands import Cog
|
||||
|
||||
from classes import PycordGuild
|
||||
from classes import PycordEvent, PycordGuild
|
||||
from classes.pycord_bot import PycordBot
|
||||
|
||||
|
||||
@@ -20,8 +23,8 @@ class Event(Cog):
|
||||
description="Create new event",
|
||||
)
|
||||
@option("name", description="Name of the event", required=True)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY)", required=True)
|
||||
@option("finish", description="Date when the event finishes (DD.MM.YYYY)", required=True)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY HH:MM)", required=True)
|
||||
@option("finish", description="Date when the event finishes (DD.MM.YYYY HH:MM)", required=True)
|
||||
@option("thumbnail", description="Thumbnail of the event", required=False)
|
||||
async def command_event_create(
|
||||
self,
|
||||
@@ -33,7 +36,39 @@ class Event(Cog):
|
||||
) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
await ctx.respond("Not implemented.")
|
||||
if not guild.is_configured():
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
guild_timezone: ZoneInfo = ZoneInfo(guild.timezone)
|
||||
|
||||
try:
|
||||
start_date: datetime = datetime.strptime(start, "%d.%m.%Y %H:%M")
|
||||
finish_date: datetime = datetime.strptime(finish, "%d.%m.%Y %H:%M")
|
||||
|
||||
start_date = start_date.replace(tzinfo=guild_timezone)
|
||||
finish_date = finish_date.replace(tzinfo=guild_timezone)
|
||||
except ValueError:
|
||||
await ctx.respond("Could not parse start and finish dates.")
|
||||
return
|
||||
|
||||
if start_date > finish_date:
|
||||
await ctx.respond("Start date must be before finish date")
|
||||
return
|
||||
elif start_date < datetime.now(tz=guild_timezone):
|
||||
await ctx.respond("Start date must not be in the past")
|
||||
return
|
||||
|
||||
event: PycordEvent = await self.bot.create_event(
|
||||
name=name,
|
||||
guild_id=guild.id,
|
||||
creator_id=ctx.author.id,
|
||||
starts=start_date.astimezone(ZoneInfo("UTC")),
|
||||
ends=finish_date.astimezone(ZoneInfo("UTC")),
|
||||
thumbnail_id=thumbnail.id if thumbnail else None,
|
||||
)
|
||||
|
||||
await ctx.respond("Event has been created.")
|
||||
|
||||
# TODO Implement the command
|
||||
@command_group.command(
|
||||
@@ -42,8 +77,8 @@ class Event(Cog):
|
||||
)
|
||||
@option("event", description="Name of the event", required=True)
|
||||
@option("name", description="New name of the event", required=False)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY)", required=False)
|
||||
@option("finish", description="Date when the event finishes (DD.MM.YYYY)", required=False)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY HH:MM)", required=False)
|
||||
@option("finish", description="Date when the event finishes (DD.MM.YYYY HH:MM)", required=False)
|
||||
@option("thumbnail", description="Thumbnail of the event", required=False)
|
||||
async def command_event_edit(
|
||||
self,
|
||||
@@ -56,6 +91,12 @@ class Event(Cog):
|
||||
) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
if not guild.is_configured():
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
guild_timezone: ZoneInfo = ZoneInfo(guild.timezone)
|
||||
|
||||
await ctx.respond("Not implemented.")
|
||||
|
||||
# TODO Implement the command
|
||||
|
Reference in New Issue
Block a user