Fixed /config show, added /event show, added stubs for /stage and /guess
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List
|
||||
from typing import Dict, Any
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from bson import ObjectId
|
||||
@@ -8,8 +8,6 @@ from discord import (
|
||||
Attachment,
|
||||
SlashCommandGroup,
|
||||
option,
|
||||
AutocompleteContext,
|
||||
OptionChoice,
|
||||
)
|
||||
from discord.ext.commands import Cog
|
||||
from discord.utils import basic_autocomplete
|
||||
@@ -17,24 +15,10 @@ from discord.utils import basic_autocomplete
|
||||
from classes import PycordEvent, PycordGuild
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.database import col_events
|
||||
from modules.utils import autofill_active_events
|
||||
|
||||
|
||||
# TODO Move to staticmethod or to a separate module
|
||||
async def get_event(ctx: AutocompleteContext) -> List[OptionChoice]:
|
||||
query: Dict[str, Any] = {
|
||||
"ended": None,
|
||||
"ends": {"$gt": datetime.now(tz=ZoneInfo("UTC"))},
|
||||
"cancelled": {"$ne": True},
|
||||
}
|
||||
|
||||
event_names: List[OptionChoice] = []
|
||||
|
||||
async for result in col_events.find(query):
|
||||
event_names.append(OptionChoice(result["name"], str(result["_id"])))
|
||||
|
||||
return event_names
|
||||
|
||||
|
||||
async def validate_event_validity(
|
||||
ctx: ApplicationContext,
|
||||
name: str,
|
||||
@@ -134,7 +118,10 @@ class Event(Cog):
|
||||
description="Edit event",
|
||||
)
|
||||
@option(
|
||||
"event", description="Name of the event", autocomplete=basic_autocomplete(get_event), required=True
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("name", description="New name of the event", required=False)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY HH:MM)", required=False)
|
||||
@@ -153,10 +140,12 @@ class Event(Cog):
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
|
||||
if pycord_event is None:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
@@ -168,6 +157,7 @@ class Event(Cog):
|
||||
)
|
||||
start_date = start_date.replace(tzinfo=guild_timezone)
|
||||
except ValueError:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Could not parse the start date.")
|
||||
return
|
||||
|
||||
@@ -177,6 +167,7 @@ class Event(Cog):
|
||||
)
|
||||
end_date = end_date.replace(tzinfo=guild_timezone)
|
||||
except ValueError:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Could not parse the end date.")
|
||||
return
|
||||
|
||||
@@ -190,15 +181,19 @@ class Event(Cog):
|
||||
thumbnail_id=pycord_event.thumbnail_id if thumbnail is None else thumbnail.id,
|
||||
)
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event has been updated.")
|
||||
|
||||
# TODO Implement the command
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="cancel",
|
||||
description="Cancel event",
|
||||
)
|
||||
@option(
|
||||
"event", description="Name of the event", autocomplete=basic_autocomplete(get_event), required=True
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
required=True,
|
||||
)
|
||||
async def command_event_cancel(
|
||||
self,
|
||||
@@ -209,10 +204,12 @@ class Event(Cog):
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
|
||||
if pycord_event is None:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
@@ -225,13 +222,43 @@ class Event(Cog):
|
||||
or end_date <= datetime.now(tz=ZoneInfo("UTC"))
|
||||
or start_date <= datetime.now(tz=ZoneInfo("UTC"))
|
||||
):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Finished or ongoing events cannot be cancelled.")
|
||||
return
|
||||
|
||||
await pycord_event.cancel()
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was cancelled.")
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="show",
|
||||
description="Show the details about certain event",
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
required=True,
|
||||
)
|
||||
async def command_event_show(self, ctx: ApplicationContext, event: str) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
|
||||
if pycord_event is None:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
|
||||
starts_date: datetime = pycord_event.starts.replace(tzinfo=ZoneInfo("UTC"))
|
||||
ends_date: datetime = pycord_event.ends.replace(tzinfo=ZoneInfo("UTC"))
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond(
|
||||
f"**Event details**\n\nName: {pycord_event.name}\nStarts: <t:{int(starts_date.timestamp())}>\nEnds: <t:{int(ends_date.timestamp())}>"
|
||||
)
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(Event(bot))
|
||||
|
Reference in New Issue
Block a user