Added validation for ongoing events (#2)
This commit is contained in:
@@ -1,12 +1,30 @@
|
|||||||
from discord import SlashCommandGroup, option, ApplicationContext, Attachment
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
from discord import ApplicationContext, Attachment, SlashCommandGroup, option
|
||||||
from discord.ext.commands import Cog
|
from discord.ext.commands import Cog
|
||||||
from discord.utils import basic_autocomplete
|
from discord.utils import basic_autocomplete
|
||||||
|
|
||||||
from classes import PycordGuild, PycordEventStage, PycordEvent
|
from classes import PycordEvent, PycordEventStage, PycordGuild
|
||||||
from classes.pycord_bot import PycordBot
|
from classes.pycord_bot import PycordBot
|
||||||
from modules.utils import autocomplete_active_events, autocomplete_event_stages
|
from modules.utils import autocomplete_active_events, autocomplete_event_stages
|
||||||
|
|
||||||
|
|
||||||
|
async def validate_event_status(
|
||||||
|
ctx: ApplicationContext,
|
||||||
|
event: PycordEvent,
|
||||||
|
) -> None:
|
||||||
|
if event.cancelled:
|
||||||
|
# TODO Make a nice message
|
||||||
|
await ctx.respond("This event was cancelled.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if event.starts <= datetime.now(tz=ZoneInfo("UTC")) <= event.ends:
|
||||||
|
# TODO Make a nice message
|
||||||
|
await ctx.respond("Ongoing events cannot be modified.")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class Stage(Cog):
|
class Stage(Cog):
|
||||||
"""Cog with event stage management commands."""
|
"""Cog with event stage management commands."""
|
||||||
|
|
||||||
@@ -39,13 +57,16 @@ class Stage(Cog):
|
|||||||
media: Attachment = None,
|
media: Attachment = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||||
pycord_event: PycordEvent = await self.bot.find_event(event)
|
|
||||||
|
|
||||||
if not guild.is_configured():
|
if not guild.is_configured():
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond("Guild is not configured.")
|
await ctx.respond("Guild is not configured.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
pycord_event: PycordEvent = await self.bot.find_event(event)
|
||||||
|
|
||||||
|
await validate_event_status(ctx, pycord_event)
|
||||||
|
|
||||||
event_stage: PycordEventStage = await self.bot.create_event_stage(
|
event_stage: PycordEventStage = await self.bot.create_event_stage(
|
||||||
event=pycord_event,
|
event=pycord_event,
|
||||||
event_id=pycord_event._id,
|
event_id=pycord_event._id,
|
||||||
@@ -96,14 +117,18 @@ class Stage(Cog):
|
|||||||
remove_media: bool = False,
|
remove_media: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||||
pycord_event: PycordEvent = await self.bot.find_event(event)
|
|
||||||
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
|
||||||
|
|
||||||
if not guild.is_configured():
|
if not guild.is_configured():
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond("Guild is not configured.")
|
await ctx.respond("Guild is not configured.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
pycord_event: PycordEvent = await self.bot.find_event(event)
|
||||||
|
|
||||||
|
await validate_event_status(ctx, pycord_event)
|
||||||
|
|
||||||
|
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
||||||
|
|
||||||
if order is not None and order > len(pycord_event.stage_ids):
|
if order is not None and order > len(pycord_event.stage_ids):
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond("Stage sequence out of range.")
|
await ctx.respond("Stage sequence out of range.")
|
||||||
@@ -149,14 +174,18 @@ class Stage(Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||||
pycord_event: PycordEvent = await self.bot.find_event(event)
|
|
||||||
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
|
||||||
|
|
||||||
if not guild.is_configured():
|
if not guild.is_configured():
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond("Guild is not configured.")
|
await ctx.respond("Guild is not configured.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
pycord_event: PycordEvent = await self.bot.find_event(event)
|
||||||
|
|
||||||
|
await validate_event_status(ctx, pycord_event)
|
||||||
|
|
||||||
|
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
||||||
|
|
||||||
await pycord_event.remove_stage(self.bot, event_stage._id, cache=self.bot.cache)
|
await pycord_event.remove_stage(self.bot, event_stage._id, cache=self.bot.cache)
|
||||||
await event_stage.purge(cache=self.bot.cache)
|
await event_stage.purge(cache=self.bot.cache)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user