Implemented /stage edit and /stage delete (#2)
This commit is contained in:
@@ -12,7 +12,7 @@ from discord.utils import basic_autocomplete
|
||||
|
||||
from classes import PycordGuild
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autofill_timezones, autofill_languages
|
||||
from modules.utils import autocomplete_timezones, autocomplete_languages
|
||||
|
||||
|
||||
class Config(Cog):
|
||||
@@ -34,13 +34,13 @@ class Config(Cog):
|
||||
@option(
|
||||
"timezone",
|
||||
description="Timezone in which events take place",
|
||||
autocomplete=basic_autocomplete(autofill_timezones),
|
||||
autocomplete=basic_autocomplete(autocomplete_timezones),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"language",
|
||||
description="Language for bot's messages",
|
||||
autocomplete=basic_autocomplete(autofill_languages),
|
||||
autocomplete=basic_autocomplete(autocomplete_languages),
|
||||
required=True,
|
||||
)
|
||||
async def command_config_set(
|
||||
@@ -97,6 +97,11 @@ class Config(Cog):
|
||||
async def command_config_show(self, ctx: ApplicationContext) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond(
|
||||
f"**Guild config**\n\nChannel: <#{guild.channel_id}>\nCategory: <#{guild.category_id}>\nTimezone: {guild.timezone}\nLanguage: {guild.language}"
|
||||
|
@@ -15,7 +15,7 @@ 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
|
||||
from modules.utils import autocomplete_active_events
|
||||
|
||||
|
||||
# TODO Move to staticmethod or to a separate module
|
||||
@@ -120,7 +120,7 @@ class Event(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("name", description="New name of the event", required=False)
|
||||
@@ -192,14 +192,21 @@ class Event(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_event_cancel(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
event: str,
|
||||
confirm: bool = False,
|
||||
) -> None:
|
||||
if confirm is None or not confirm:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Operation not confirmed.")
|
||||
return
|
||||
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
|
||||
@@ -239,7 +246,7 @@ class Event(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
async def command_event_show(self, ctx: ApplicationContext, event: str) -> None:
|
||||
|
@@ -4,7 +4,7 @@ from discord.utils import basic_autocomplete
|
||||
|
||||
from classes import PycordGuild, PycordEventStage, PycordEvent
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autofill_active_events
|
||||
from modules.utils import autocomplete_active_events, autocomplete_event_stages
|
||||
|
||||
|
||||
class Stage(Cog):
|
||||
@@ -24,7 +24,7 @@ class Stage(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("question", description="Question to be answered", required=True)
|
||||
@@ -54,7 +54,7 @@ class Stage(Cog):
|
||||
creator_id=ctx.author.id,
|
||||
question=question,
|
||||
answer=answer,
|
||||
media=None if media is None else media.id,
|
||||
media=[] if media is None else [media.id],
|
||||
)
|
||||
|
||||
# TODO Make a nice message
|
||||
@@ -69,14 +69,21 @@ class Stage(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("stage", description="Stage to edit", required=True)
|
||||
@option("order", description="Number in the event stages' order", required=False)
|
||||
# TODO Add autofill
|
||||
@option(
|
||||
"stage",
|
||||
description="Stage to edit",
|
||||
autocomplete=basic_autocomplete(autocomplete_event_stages),
|
||||
required=True,
|
||||
)
|
||||
@option("order", description="Number in the event stages' order", min_value=1, required=False)
|
||||
@option("question", description="Question to be answered", required=False)
|
||||
@option("answer", description="Answer to the stage's question", required=False)
|
||||
@option("media", description="Media file to be attached", required=False)
|
||||
@option("remove_media", description="Remove attached media", required=False)
|
||||
async def command_stage_edit(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
@@ -86,8 +93,33 @@ class Stage(Cog):
|
||||
question: str,
|
||||
answer: str,
|
||||
media: Attachment = None,
|
||||
remove_media: bool = False,
|
||||
) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
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():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
if order is not None and order > len(pycord_event.stage_ids):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Stage sequence out of range.")
|
||||
return
|
||||
|
||||
if not (question is None and answer is None and media is None and remove_media is False):
|
||||
await event_stage.update(
|
||||
question=event_stage.question if question is None else question,
|
||||
answer=event_stage.answer if answer is None else answer,
|
||||
media=[] if remove_media else (event_stage.media if media is None else [media.id]),
|
||||
)
|
||||
|
||||
if order is not None and order - 1 != event_stage.sequence:
|
||||
await pycord_event.reorder_stage(self.bot, event_stage._id, order - 1, cache=self.bot.cache)
|
||||
|
||||
await ctx.respond("Event stage has been updated.")
|
||||
|
||||
# TODO Implement the command
|
||||
# /stage delete <event> <stage> <confirm>
|
||||
@@ -98,15 +130,38 @@ class Stage(Cog):
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
autocomplete=basic_autocomplete(autofill_active_events),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"stage",
|
||||
description="Stage to delete",
|
||||
autocomplete=basic_autocomplete(autocomplete_event_stages),
|
||||
required=True,
|
||||
)
|
||||
@option("stage", description="Stage to edit", required=True)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_stage_delete(
|
||||
self, ctx: ApplicationContext, event: str, stage: str, confirm: bool = False
|
||||
) -> None:
|
||||
await ctx.respond("Not implemented.")
|
||||
if confirm is None or not confirm:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Operation not confirmed.")
|
||||
return
|
||||
|
||||
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():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
return
|
||||
|
||||
await pycord_event.remove_stage(self.bot, event_stage._id, cache=self.bot.cache)
|
||||
await event_stage.purge(cache=self.bot.cache)
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Okay.")
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
|
Reference in New Issue
Block a user