From 4685f4aea8648bb2f2662079c98594c53b638ecd Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 18 Sep 2022 12:02:34 -0400 Subject: [PATCH] added weather selection box --- the_prestige.py | 13 +++++-------- weather.py | 7 +++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/the_prestige.py b/the_prestige.py index fb5fa8d..8e01e16 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -109,10 +109,11 @@ class StartGameCommand(Command): - this command has fuzzy search so you don't need to type the full name of the team as long as you give enough to identify the team you're looking for.""" @client.tree.command() -async def startgame(interaction, away: str, home: str, innings: Optional[int]=9, flags: Optional[str] = ""): +@app_commands.rename(wthr="weather") +@app_commands.choices(wthr=weather.weather_choices()) +async def startgame(interaction, away: str, home: str, innings: Optional[int]=9, wthr: Optional[app_commands.Choice[str]] = None, flags: Optional[str] = ""): league = None day = None - weather_name = None innings = None voice = None @@ -128,10 +129,6 @@ async def startgame(interaction, away: str, home: str, innings: Optional[int]=9, day = int(flag[1]) except: raise CommandError("Make sure you put an integer after the -d flag.") - elif flag[0] == "w": - weather_name = flag[1] - if weather_name not in weather.all_weathers(): - raise CommandError("We can't find that weather, chief. Try again.") elif flag[0] == "v" or flag[0] == "a": if flag[1] in gametext.all_voices(): voice = gametext.all_voices()[flag[1]] @@ -168,8 +165,8 @@ async def startgame(interaction, away: str, home: str, innings: Optional[int]=9, game.voice = voice() channel = interaction.channel - if weather_name is not None: - game.weather = weather.all_weathers()[weather_name](game) + if wthr is not None: + game.weather = weather.all_weathers()[wthr.value](game) game_task = asyncio.create_task(watch_game(channel, game, user=interaction.user, league=league, interaction=interaction)) await game_task diff --git a/weather.py b/weather.py index 4784610..27e9def 100644 --- a/weather.py +++ b/weather.py @@ -1,5 +1,6 @@ import random, math, roman from gametext import appearance_outcomes, game_strings_base, base_string +from discord.app_commands import Choice class Weather: name = "Sunny" @@ -636,6 +637,12 @@ def all_weathers(): } return weathers_dic +def weather_choices(): + lst = [] + for key, value in list(all_weathers().items()): + lst.append(Choice(name=key, value=key)) + return lst + def safe_weathers(): """weathers safe to swap in mid-game""" weathers_dic = {