From f8c7fc4fc672a24f66c8b9d5ec11e323d078dbee Mon Sep 17 00:00:00 2001 From: esefxdz Date: Mon, 13 Jul 2026 00:32:01 +0300 Subject: [PATCH] calendar command qol --- cogs/calendar.py | 4 ++-- cogs/calendar_data.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cogs/calendar.py b/cogs/calendar.py index 89adbd5..f76f6f4 100644 --- a/cogs/calendar.py +++ b/cogs/calendar.py @@ -19,7 +19,7 @@ FIRESTORE_CALENDAR = ( DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$") TIME_RE = re.compile(r"^\d{2}:\d{2}$") -from .calendar_data import COUNTRY_TZ, tz_choices +from .calendar_data import COUNTRY_TZ, country_autocomplete class Calendar(commands.Cog): @@ -43,7 +43,7 @@ class Calendar(commands.Cog): title="Event title", description="Extra notes (optional)", ) - @app_commands.choices(country=tz_choices()) + @app_commands.autocomplete(country=country_autocomplete) async def book_cmd( self, interaction: discord.Interaction, diff --git a/cogs/calendar_data.py b/cogs/calendar_data.py index 2bbf2c1..eba2aec 100644 --- a/cogs/calendar_data.py +++ b/cogs/calendar_data.py @@ -48,7 +48,16 @@ COUNTRY_TZ: dict[str, float] = { # fmt: on -def tz_choices() -> list: - """Return app_commands.Choice list for the country dropdown.""" +async def country_autocomplete( + _interaction, + current: str, +) -> list: + """Return matching countries for slash-command autocomplete.""" from discord import app_commands - return [app_commands.Choice(name=c, value=c) for c in sorted(COUNTRY_TZ)] + current = current.lower() + matches = [ + app_commands.Choice(name=c, value=c) + for c in sorted(COUNTRY_TZ) + if current in c.lower() + ] + return matches[:25] # Discord limits to 25 suggestions