From 393094a63c473a0bc25d4f43988da6ea0a137f99 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Sun, 18 Sep 2022 11:49:50 -0400 Subject: [PATCH] archetypes, with dropdown --- archetypes.py | 7 +++++++ the_prestige.py | 53 +++++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/archetypes.py b/archetypes.py index 24e775b..8c47525 100644 --- a/archetypes.py +++ b/archetypes.py @@ -1,5 +1,6 @@ import random from gametext import appearance_outcomes +from discord.app_commands import Choice class Archetype: name = "basic" @@ -126,6 +127,12 @@ def all_archetypes(): Control ] +def archetype_choices(): + lst = [] + for arch in all_archetypes(): + lst.append(Choice(name=arch.display_name, value=arch.name)) + return lst + def search_archetypes(text): for archetype in all_archetypes(): if archetype.name == text or archetype.display_name.lower() == text.lower(): diff --git a/the_prestige.py b/the_prestige.py index 9ff948a..fb5fa8d 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -229,36 +229,37 @@ class AssignArchetypeCommand(Command): template = "m;archetype [team name]\n[player name]\n[archetype name]" description = """Assigns an archetype to a player on your team. This can be changed at any time! For a description of a specific archetype, or a list of all archetypes, use m;archetypehelp.""" - async def execute(self, msg, command, flags): - lines = command.split("\n") - try: - team = get_team_fuzzy_search(lines[0].strip()) - player_name = lines[1].strip() - archetype_name = lines[2].strip() - except IndexError: - raise CommandError("You didn't give us enough info, boss. Check the help text.") - if team is None: - raise CommandError("We can't find that team.") +@client.tree.command() +@app_commands.choices(archetype=archetypes.archetype_choices()) +async def archetype(interaction, team: str, player: str, archetype: app_commands.Choice[str]): + try: + team = get_team_fuzzy_search(team) + player_name = player + archetype_name = archetype.value + except IndexError: + raise CommandError("You didn't give us enough info, boss. Check the help text.") + if team is None: + raise CommandError("We can't find that team.") - team, ownerid = games.get_team_and_owner(team.name) - if ownerid != msg.author.id and msg.author.id not in config()["owners"]: - raise CommandError("That team ain't yours, and we're not about to help you cheat.") + team, ownerid = games.get_team_and_owner(team.name) + if ownerid != interaction.user.id and interaction.user.id not in config()["owners"]: + raise CommandError("That team ain't yours, and we're not about to help you cheat.") - player = team.find_player(player_name)[0] - if player is None: - raise CommandError("That player isn't on your team, boss.") + player = team.find_player(player_name)[0] + if player is None: + raise CommandError("That player isn't on your team, boss.") - archetype = archetypes.search_archetypes(archetype_name) - if archetype is None: - raise CommandError("We can't find that archetype, chief. Try m;archetypehelp.") + archetype = archetypes.search_archetypes(archetype_name) + if archetype is None: + raise CommandError("We can't find that archetype, chief. Try m;archetypehelp.") - try: - team.archetypes[player.name] = archetype - except AttributeError: - team.archetypes = {player.name : archetype} - games.update_team(team) + try: + team.archetypes[player.name] = archetype + except AttributeError: + team.archetypes = {player.name : archetype} + games.update_team(team) - await msg.channel.send("Player specialization is a beautiful thing, ain't it? Here's hoping they like it.") + await interaction.response.send_message("Player specialization is a beautiful thing, ain't it? Here's hoping they like it.") class ArchetypeHelpCommand(Command): name = "archetypehelp" @@ -1612,7 +1613,7 @@ commands = [ AssignOwnerCommand(), ShowPlayerCommand(), #done SaveTeamCommand(), #done - AssignArchetypeCommand(), + AssignArchetypeCommand(), #done ViewArchetypesCommand(), ArchetypeHelpCommand(), ImportCommand(),