archetypes, with dropdown

This commit is contained in:
Sakimori 2022-09-18 11:49:50 -04:00
parent 2b56ea6955
commit 393094a63c
2 changed files with 34 additions and 26 deletions

View file

@ -1,5 +1,6 @@
import random import random
from gametext import appearance_outcomes from gametext import appearance_outcomes
from discord.app_commands import Choice
class Archetype: class Archetype:
name = "basic" name = "basic"
@ -126,6 +127,12 @@ def all_archetypes():
Control 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): def search_archetypes(text):
for archetype in all_archetypes(): for archetype in all_archetypes():
if archetype.name == text or archetype.display_name.lower() == text.lower(): if archetype.name == text or archetype.display_name.lower() == text.lower():

View file

@ -229,19 +229,20 @@ class AssignArchetypeCommand(Command):
template = "m;archetype [team name]\n[player name]\n[archetype name]" 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.""" 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): @client.tree.command()
lines = command.split("\n") @app_commands.choices(archetype=archetypes.archetype_choices())
async def archetype(interaction, team: str, player: str, archetype: app_commands.Choice[str]):
try: try:
team = get_team_fuzzy_search(lines[0].strip()) team = get_team_fuzzy_search(team)
player_name = lines[1].strip() player_name = player
archetype_name = lines[2].strip() archetype_name = archetype.value
except IndexError: except IndexError:
raise CommandError("You didn't give us enough info, boss. Check the help text.") raise CommandError("You didn't give us enough info, boss. Check the help text.")
if team is None: if team is None:
raise CommandError("We can't find that team.") raise CommandError("We can't find that team.")
team, ownerid = games.get_team_and_owner(team.name) team, ownerid = games.get_team_and_owner(team.name)
if ownerid != msg.author.id and msg.author.id not in config()["owners"]: 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.") raise CommandError("That team ain't yours, and we're not about to help you cheat.")
player = team.find_player(player_name)[0] player = team.find_player(player_name)[0]
@ -258,7 +259,7 @@ class AssignArchetypeCommand(Command):
team.archetypes = {player.name : archetype} team.archetypes = {player.name : archetype}
games.update_team(team) 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): class ArchetypeHelpCommand(Command):
name = "archetypehelp" name = "archetypehelp"
@ -1612,7 +1613,7 @@ commands = [
AssignOwnerCommand(), AssignOwnerCommand(),
ShowPlayerCommand(), #done ShowPlayerCommand(), #done
SaveTeamCommand(), #done SaveTeamCommand(), #done
AssignArchetypeCommand(), AssignArchetypeCommand(), #done
ViewArchetypesCommand(), ViewArchetypesCommand(),
ArchetypeHelpCommand(), ArchetypeHelpCommand(),
ImportCommand(), ImportCommand(),