From ac74643a3306bad41955178840df31b773339b52 Mon Sep 17 00:00:00 2001 From: tesence Date: Wed, 20 Nov 2024 21:17:05 +0100 Subject: [PATCH] Define common seed options in one place --- gumo/api/models.py | 25 +++++++++++++++++++++++++ gumo/modules/league.py | 18 +----------------- gumo/modules/seed.py | 37 ++----------------------------------- 3 files changed, 28 insertions(+), 52 deletions(-) diff --git a/gumo/api/models.py b/gumo/api/models.py index ad19a0f..70456d9 100644 --- a/gumo/api/models.py +++ b/gumo/api/models.py @@ -99,3 +99,28 @@ VARIATION_CHOICES = [app_commands.Choice(name=name, value=name) for name, value in VARIATIONS.items()] LOGIC_PATH_CHOICES = [app_commands.Choice(name=name, value=name) for name, value in LOGIC_PATHS.items()] ITEM_POOL_CHOICES = [app_commands.Choice(name=name, value=name) for name, value in ITEM_POOLS.items()] + +def add_seed_options(func): + """Set all the common options for seed commands + + Args: + func (function): Command definition + """ + func = app_commands.describe(logic_mode="Randomizer logic mode")(func) + func = app_commands.choices(logic_mode=LOGIC_MODE_CHOICES)(func) + func = app_commands.describe(key_mode="Randomizer key mode")(func) + func = app_commands.choices(key_mode=KEY_MODE_CHOICES)(func) + func = app_commands.describe(goal_mode="Randomizer goal mode")(func) + func = app_commands.choices(goal_mode=GOAL_MODE_CHOICES)(func) + func = app_commands.describe(spawn="The location where the player starts in the seed")(func) + func = app_commands.choices(spawn=SPAWN_CHOICES)(func) + func = app_commands.describe(variation1="Extra randomizer variation")(func) + func = app_commands.choices(variation1=VARIATION_CHOICES)(func) + func = app_commands.describe(variation2="Extra randomizer variation")(func) + func = app_commands.choices(variation2=VARIATION_CHOICES)(func) + func = app_commands.describe(variation3="Extra randomizer variation")(func) + func = app_commands.choices(variation3=VARIATION_CHOICES)(func) + func = app_commands.describe(item_pool="Randomizer item pool")(func) + func = app_commands.choices(item_pool=ITEM_POOL_CHOICES)(func) + func = app_commands.describe(relic_count="(World Tour only) The number of relics to place in the seed")(func) + return func diff --git a/gumo/modules/league.py b/gumo/modules/league.py index edba659..e77c764 100644 --- a/gumo/modules/league.py +++ b/gumo/modules/league.py @@ -238,23 +238,7 @@ async def _submit(self, *submissions): league = app_commands.Group(name="league", description="BF Rando League commands") @league.command(name='set') - @app_commands.describe(logic_mode="Randomizer logic mode") - @app_commands.choices(logic_mode=models.LOGIC_MODE_CHOICES) - @app_commands.describe(key_mode="Randomizer key mode") - @app_commands.choices(key_mode=models.KEY_MODE_CHOICES) - @app_commands.describe(goal_mode="Randomizer goal mode") - @app_commands.choices(goal_mode=models.GOAL_MODE_CHOICES) - @app_commands.describe(spawn="Start location") - @app_commands.choices(spawn=models.SPAWN_CHOICES) - @app_commands.describe(variation1="Extra randomizer variation") - @app_commands.choices(variation1=models.VARIATION_CHOICES) - @app_commands.describe(variation2="Extra randomizer variation") - @app_commands.choices(variation2=models.VARIATION_CHOICES) - @app_commands.describe(variation3="Extra randomizer variation") - @app_commands.choices(variation3=models.VARIATION_CHOICES) - @app_commands.describe(item_pool="Randomizer item pool") - @app_commands.choices(item_pool=models.ITEM_POOL_CHOICES) - @app_commands.describe(relic_count="(World Tour only) The number of relics to place in the seed") + @models.add_seed_options @app_commands.describe(date="The settings of the week to be set") @app_commands.check(is_league_admin_check) # pylint: disable=unused-argument diff --git a/gumo/modules/seed.py b/gumo/modules/seed.py index 524b27e..e3503a3 100644 --- a/gumo/modules/seed.py +++ b/gumo/modules/seed.py @@ -19,7 +19,6 @@ logger = logging.getLogger(__name__) - class BFRandomizer(commands.Cog, name="Blind Forest Randomizer"): """Custom Cog""" @@ -29,23 +28,7 @@ def __init__(self, bot): @app_commands.command(name='seed') @app_commands.describe(seed_name="A string to be used as seed") - @app_commands.describe(logic_mode="Randomizer logic mode") - @app_commands.choices(logic_mode=models.LOGIC_MODE_CHOICES) - @app_commands.describe(key_mode="Randomizer key mode") - @app_commands.choices(key_mode=models.KEY_MODE_CHOICES) - @app_commands.describe(goal_mode="Randomizer goal mode") - @app_commands.choices(goal_mode=models.GOAL_MODE_CHOICES) - @app_commands.describe(spawn="The location where the player starts in the seed") - @app_commands.choices(spawn=models.SPAWN_CHOICES) - @app_commands.describe(variation1="Extra randomizer variation") - @app_commands.choices(variation1=models.VARIATION_CHOICES) - @app_commands.describe(variation2="Extra randomizer variation") - @app_commands.choices(variation2=models.VARIATION_CHOICES) - @app_commands.describe(variation3="Extra randomizer variation") - @app_commands.choices(variation3=models.VARIATION_CHOICES) - @app_commands.describe(item_pool="Randomizer item pool") - @app_commands.choices(item_pool=models.ITEM_POOL_CHOICES) - @app_commands.describe(relic_count="(World Tour only) The number of relics to place in the seed") + @models.add_seed_options # pylint: disable=unused-argument async def seed(self, interaction: discord.Interaction, seed_name: Optional[str] = None, @@ -81,23 +64,7 @@ async def seed(self, interaction: discord.Interaction, return await interaction.followup.send(content=message, files=[file]) @app_commands.command(name='daily') - @app_commands.describe(logic_mode="Randomizer logic mode") - @app_commands.choices(logic_mode=models.LOGIC_MODE_CHOICES) - @app_commands.describe(key_mode="Randomizer key mode") - @app_commands.choices(key_mode=models.KEY_MODE_CHOICES) - @app_commands.describe(goal_mode="Randomizer goal mode") - @app_commands.choices(goal_mode=models.GOAL_MODE_CHOICES) - @app_commands.describe(spawn="Start location") - @app_commands.choices(spawn=models.SPAWN_CHOICES) - @app_commands.describe(variation1="Extra randomizer variation") - @app_commands.choices(variation1=models.VARIATION_CHOICES) - @app_commands.describe(variation2="Extra randomizer variation") - @app_commands.choices(variation2=models.VARIATION_CHOICES) - @app_commands.describe(variation3="Extra randomizer variation") - @app_commands.choices(variation3=models.VARIATION_CHOICES) - @app_commands.describe(item_pool="Randomizer item pool") - @app_commands.choices(item_pool=models.ITEM_POOL_CHOICES) - @app_commands.describe(relic_count="(World Tour only) The number of relics to place in the seed") + @models.add_seed_options # pylint: disable=unused-argument async def daily(self, interaction: discord.Interaction, logic_mode: Optional[app_commands.Choice[str]] = None,