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
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():

View file

@ -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(),