Implemented /event edit and /edit cancel

This commit is contained in:
2025-04-21 22:49:23 +02:00
parent b72f930c94
commit 08d1ca4d33
5 changed files with 286 additions and 120 deletions

View File

@@ -1,4 +1,5 @@
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
from typing import List
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError, available_timezones
from discord import (
ApplicationContext,
@@ -6,13 +7,27 @@ from discord import (
SlashCommandGroup,
TextChannel,
option,
AutocompleteContext,
)
from discord.ext.commands import Cog
from discord.utils import basic_autocomplete
from classes import PycordGuild
from classes.pycord_bot import PycordBot
# TODO Move to staticmethod or to a separate module
async def get_timezones(ctx: AutocompleteContext) -> List[str]:
return sorted(list(available_timezones()))
# TODO Move to staticmethod or to a separate module
async def get_languages(ctx: AutocompleteContext) -> List[str]:
# TODO Discord normally uses a different set of locales.
# For example, "en" being "en-US", etc. This will require changes to locale handling later.
return ctx.bot.locales.keys()
class Config(Cog):
"""Cog with guild configuration commands."""
@@ -29,9 +44,25 @@ class Config(Cog):
)
@option("category", description="Category where channels for each user will be created", required=True)
@option("channel", description="Text channel for admin notifications", required=True)
@option("timezone", description="Timezone in which events take place", required=True)
@option(
"timezone",
description="Timezone in which events take place",
autocomplete=basic_autocomplete(get_timezones),
required=True,
)
@option(
"language",
description="Language for bot's messages",
autocomplete=basic_autocomplete(get_languages),
required=True,
)
async def command_config_set(
self, ctx: ApplicationContext, category: CategoryChannel, channel: TextChannel, timezone: str
self,
ctx: ApplicationContext,
category: CategoryChannel,
channel: TextChannel,
timezone: str,
language: str,
) -> None:
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
@@ -41,9 +72,13 @@ class Config(Cog):
await ctx.respond(f"Timezone {timezone} was not found.")
return
await guild.set_channel(channel.id, cache=self.bot.cache)
await guild.set_category(category.id, cache=self.bot.cache)
await guild.set_timezone(str(timezone_parsed), cache=self.bot.cache)
await guild.update(
self.bot.cache,
channel_id=channel.id,
category_id=category.id,
timezone=str(timezone_parsed),
language=language,
)
# TODO Make a nice message
await ctx.respond("Okay.")
@@ -62,9 +97,7 @@ class Config(Cog):
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
await guild.reset_channel(cache=self.bot.cache)
await guild.reset_category(cache=self.bot.cache)
await guild.reset_timezone(cache=self.bot.cache)
await guild.purge(self.bot.cache)
# TODO Make a nice message
await ctx.respond("Okay.")