fixed environment, continued work on commands

This commit is contained in:
Sakimori 2023-03-31 02:18:28 -04:00
parent 03ab7c24bd
commit d7eb232af4
4 changed files with 89 additions and 39 deletions

1
.gitignore vendored
View file

@ -359,3 +359,4 @@ env
/simmadome/build /simmadome/build
/simmadome/.eslintcache /simmadome/.eslintcache
/matteo_env/Lib/site-packages /matteo_env/Lib/site-packages
/new_matteo_env

View file

@ -954,7 +954,7 @@ def get_team_and_owner(name):
update_team(team_json) update_team(team_json)
return (team_json, owner_id) return (team_json, owner_id)
except: except:
return None return (None, None)
def save_team(this_team, user_id): def save_team(this_team, user_id):
try: try:

View file

@ -11,7 +11,7 @@
<OutputPath>.</OutputPath> <OutputPath>.</OutputPath>
<Name>the-prestige</Name> <Name>the-prestige</Name>
<RootNamespace>the-prestige</RootNamespace> <RootNamespace>the-prestige</RootNamespace>
<InterpreterId>MSBuild|matteo_env|$(MSBuildProjectFullPath)</InterpreterId> <InterpreterId>MSBuild|new_matteo_env|$(MSBuildProjectFullPath)</InterpreterId>
<IsWindowsApplication>False</IsWindowsApplication> <IsWindowsApplication>False</IsWindowsApplication>
<SuppressConfigureTestFrameworkPrompt>true</SuppressConfigureTestFrameworkPrompt> <SuppressConfigureTestFrameworkPrompt>true</SuppressConfigureTestFrameworkPrompt>
</PropertyGroup> </PropertyGroup>
@ -67,6 +67,15 @@
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable> <PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture> <Architecture>X86</Architecture>
</Interpreter> </Interpreter>
<Interpreter Include="new_matteo_env\">
<Id>new_matteo_env</Id>
<Version>3.8</Version>
<Description>new_matteo_env (Python38-32)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="config.json" /> <Content Include="config.json" />
@ -43336,6 +43345,9 @@
<Folder Include="static\" /> <Folder Include="static\" />
<Folder Include="templates\" /> <Folder Include="templates\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<InterpreterReference Include="Global|VisualStudio|Python38-32" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in <!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in Visual Studio and specify your pre- and post-build commands in

View file

@ -96,6 +96,7 @@ class ShowPlayerCommand(Command):
@client.tree.command() @client.tree.command()
@app_commands.rename(command="name") @app_commands.rename(command="name")
async def showplayer(interaction: discord.Interaction, command: str): async def showplayer(interaction: discord.Interaction, command: str):
"""Show a single player's stats."""
player_name = json.loads(ono.get_stats(command)) player_name = json.loads(ono.get_stats(command))
await interaction.response.send_message(embed=build_star_embed(player_name)) await interaction.response.send_message(embed=build_star_embed(player_name))
@ -112,6 +113,7 @@ class StartGameCommand(Command):
@app_commands.rename(wthr="weather") @app_commands.rename(wthr="weather")
@app_commands.choices(wthr=weather.weather_choices()) @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] = ""): async def startgame(interaction, away: str, home: str, innings: Optional[int]=9, wthr: Optional[app_commands.Choice[str]] = None, flags: Optional[str] = ""):
"""Start a game with the given teams and, optionally, weather choice and custom inning number."""
league = None league = None
day = None day = None
innings = None innings = None
@ -180,6 +182,7 @@ class StartRandomGameCommand(Command):
@client.tree.command() @client.tree.command()
async def randomgame(interaction): async def randomgame(interaction):
"""Start a game between two random teams."""
if config()["game_freeze"]: if config()["game_freeze"]:
raise CommandError("Patch incoming. We're not allowing new games right now.") raise CommandError("Patch incoming. We're not allowing new games right now.")
@ -194,11 +197,13 @@ async def randomgame(interaction):
class SaveTeamCommand(Command): class SaveTeamCommand(Command):
name = "saveteam" name = "saveteam"
template = """m;saveteam template = """m;saveteam [bot ping]
[name] [name]
[slogan] [slogan]
[lineup] [lineup]
[rotation]""" [rotation]
"""
description = """Saves a team to the database allowing it to be used for games. Send this command at the top of a list, with entries separated by new lines (shift+enter in discord, or copy+paste from notepad). description = """Saves a team to the database allowing it to be used for games. Send this command at the top of a list, with entries separated by new lines (shift+enter in discord, or copy+paste from notepad).
- the first line of the list is your team's name. - the first line of the list is your team's name.
@ -207,9 +212,7 @@ class SaveTeamCommand(Command):
- the next lines are your batters' names in the order you want them to appear in your lineup, lineups can contain any number of batters between 1 and 12. - the next lines are your batters' names in the order you want them to appear in your lineup, lineups can contain any number of batters between 1 and 12.
- there must be another blank line between your batters and your pitchers. - there must be another blank line between your batters and your pitchers.
- the final lines are the names of the pitchers in your rotation, rotations can contain any number of pitchers between 1 and 8. - the final lines are the names of the pitchers in your rotation, rotations can contain any number of pitchers between 1 and 8.
If you did it correctly, you'll get a team embed with a prompt to confirm. hit the 👍 and your team will be saved! If you did it correctly, you'll get a team embed with a prompt to confirm. hit the 👍 and your team will be saved!"""
***NOTE: This only functions in the bot's DMs. Do not use on a server."""
async def execute(self, msg, command, flags): async def execute(self, msg, command, flags):
if db.get_team(command.split('\n',1)[1].split("\n")[0]) == None: if db.get_team(command.split('\n',1)[1].split("\n")[0]) == None:
@ -221,6 +224,11 @@ If you did it correctly, you'll get a team embed with a prompt to confirm. hit t
name = command.split('\n',1)[1].split('\n')[0] name = command.split('\n',1)[1].split('\n')[0]
raise CommandError(f"{name} already exists. Try a new name, maybe?") raise CommandError(f"{name} already exists. Try a new name, maybe?")
@client.tree.command()
async def newteam(interaction):
"""Get new team instructions. Sent privately, don't worry!"""
await interaction.response.send_message(SaveTeamCommand.template + SaveTeamCommand.description , ephemeral=True)
class AssignArchetypeCommand(Command): class AssignArchetypeCommand(Command):
name = "archetype" name = "archetype"
template = "m;archetype [team name]\n[player name]\n[archetype name]" template = "m;archetype [team name]\n[player name]\n[archetype name]"
@ -228,7 +236,8 @@ class AssignArchetypeCommand(Command):
@client.tree.command() @client.tree.command()
@app_commands.choices(archetype=archetypes.archetype_choices()) @app_commands.choices(archetype=archetypes.archetype_choices())
async def archetype(interaction, team: str, player: str, archetype: app_commands.Choice[str]): async def setarchetype(interaction, team: str, player: str, archetype: app_commands.Choice[str]):
"""Assigns an archetype to a player on an owned team. Reversible."""
try: try:
team = get_team_fuzzy_search(team) team = get_team_fuzzy_search(team)
player_name = player player_name = player
@ -266,6 +275,7 @@ class ArchetypeHelpCommand(Command):
@client.tree.command() @client.tree.command()
@app_commands.choices(archetype=archetypes.archetype_choices()) @app_commands.choices(archetype=archetypes.archetype_choices())
async def archetypehelp(interaction, archetype: app_commands.Choice[str]): async def archetypehelp(interaction, archetype: app_commands.Choice[str]):
"""Describes a specific archetype."""
arch = archetypes.search_archetypes(archetype.value) arch = archetypes.search_archetypes(archetype.value)
if arch is None: if arch is None:
raise CommandError("We don't know what that archetype is. If you're trying to break new ground, here isn't the time *or* the place.") raise CommandError("We don't know what that archetype is. If you're trying to break new ground, here isn't the time *or* the place.")
@ -283,6 +293,7 @@ class ViewArchetypesCommand(Command):
@client.tree.command() @client.tree.command()
@app_commands.rename(team_name="team") @app_commands.rename(team_name="team")
async def teamarchetypes(interaction, team_name: str): async def teamarchetypes(interaction, team_name: str):
"""Lists the current archetypes on a team."""
team = get_team_fuzzy_search(team_name) team = get_team_fuzzy_search(team_name)
if team is None: if team is None:
raise CommandError("We can't find that team, boss.") raise CommandError("We can't find that team, boss.")
@ -321,6 +332,7 @@ class ShowTeamCommand(Command):
@client.tree.command() @client.tree.command()
@app_commands.rename(team_name="team") @app_commands.rename(team_name="team")
async def showteam(interaction, team_name: str): async def showteam(interaction, team_name: str):
"""Display a team's roster and relevant ratings."""
team = get_team_fuzzy_search(team_name) team = get_team_fuzzy_search(team_name)
if team is not None: if team is not None:
await interaction.response.send_message(embed=build_team_embed(team)) await interaction.response.send_message(embed=build_team_embed(team))
@ -356,6 +368,11 @@ class CreditCommand(Command):
async def execute(self, msg, command, flags): async def execute(self, msg, command, flags):
await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.") await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.")
@client.tree.command()
async def credit(interaction):
"""Show artist credit for the bot's avatar."""
await interaction.response.send_message("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.")
class SwapPlayerCommand(Command): class SwapPlayerCommand(Command):
name = "swapsection" name = "swapsection"
template = """m;swapsection template = """m;swapsection
@ -370,7 +387,7 @@ class SwapPlayerCommand(Command):
team, owner_id = games.get_team_and_owner(team_name) team, owner_id = games.get_team_and_owner(team_name)
if team is None: if team is None:
raise CommandError("Can't find that team, boss. Typo?") raise CommandError("Can't find that team, boss. Typo?")
elif owner_id != msg.author.id and msg.author.id not in config()["owners"]: elif owner_id != interaction.user.id and interaction.user.id not in config()["owners"]:
raise CommandError("You're not authorized to mess with this team. Sorry, boss.") raise CommandError("You're not authorized to mess with this team. Sorry, boss.")
elif not team.swap_player(player_name): elif not team.swap_player(player_name):
raise CommandError("Either we can't find that player, you've got no space on the other side, or they're your last member of that side of the roster. Can't field an empty lineup, and we *do* have rules, chief.") raise CommandError("Either we can't find that player, you've got no space on the other side, or they're your last member of that side of the roster. Can't field an empty lineup, and we *do* have rules, chief.")
@ -381,6 +398,22 @@ class SwapPlayerCommand(Command):
except IndexError: except IndexError:
raise CommandError("Three lines, remember? Command, then team, then name.") raise CommandError("Three lines, remember? Command, then team, then name.")
@client.tree.command()
@app_commands.rename(team_name="team", player_name="player")
async def swapplayer(interaction, team_name: str, player_name: str):
"""Swaps a player on an owned team between lineup and rotation."""
team, owner_id = games.get_team_and_owner(team_name)
if team is None:
raise CommandError("Can't find that team, boss. Typo?")
elif owner_id != interaction.user.id and interaction.user.id not in config()["owners"]:
raise CommandError("You're not authorized to mess with this team. Sorry, boss.")
elif not team.swap_player(player_name):
raise CommandError("Either we can't find that player, you've got no space on the other side, or they're your last member of that side of the roster. Can't field an empty lineup, and we *do* have rules, chief.")
else:
await interaction.channel.send(embed=build_team_embed(team))
games.update_team(team)
await interaction.response.send_message("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.")
class MovePlayerCommand(Command): class MovePlayerCommand(Command):
name = "moveplayer" name = "moveplayer"
template = """m;moveplayer template = """m;moveplayer
@ -393,23 +426,29 @@ class MovePlayerCommand(Command):
try: try:
team_name = command.split("\n")[1].strip() team_name = command.split("\n")[1].strip()
player_name = command.split("\n")[2].strip() player_name = command.split("\n")[2].strip()
except IndexError:
raise CommandError("Four lines, remember? Command, then team, then name, and finally, new spot on the lineup or rotation.")
@client.tree.command()
@app_commands.rename(team_name="team", player_name="player", is_pitcher="pitcher", new_pos="newposition")
async def moveplayer(interaction, team_name: str, player_name: str, is_pitcher: bool, new_pos: int):
team, owner_id = games.get_team_and_owner(team_name) team, owner_id = games.get_team_and_owner(team_name)
try: if new_pos < 0:
new_pos = int(command.split("\n")[3].strip()) raise CommandError("Hey, quit being cheeky. We're just trying to help. New position has to be a natural number, boss.")
except ValueError: elif owner_id != interaction.user.id and interaction.user.id not in config()["owners"]:
raise CommandError("Hey, quit being cheeky. We're just trying to help. Third line has to be a natural number, boss.")
if owner_id != msg.author.id and msg.author.id not in config()["owners"]:
raise CommandError("You're not authorized to mess with this team. Sorry, boss.") raise CommandError("You're not authorized to mess with this team. Sorry, boss.")
elif team is None:
raise CommandError("We can't find that team, boss. Typo?")
else: else:
if team.find_player(player_name)[2] is None or len(team.find_player(player_name)[2]) < new_pos: if team.find_player(player_name)[2] is None or len(team.find_player(player_name)[2]) < new_pos:
raise CommandError("You either gave us a number that was bigger than your current roster, or we couldn't find the player on the team. Try again.") raise CommandError("You either gave us a number that was bigger than your current roster, or we couldn't find the player on the team. Try again.")
if "batter" in command.split("\n")[0].lower(): if not is_pitcher:
roster = team.lineup roster = team.lineup
elif "pitcher" in command.split("\n")[0].lower():
roster = team.rotation
else: else:
roster = None roster = team.rotation
if (roster is not None and team.slide_player_spec(player_name, new_pos, roster)) or (roster is None and team.slide_player(player_name, new_pos)): if (roster is not None and team.slide_player_spec(player_name, new_pos, roster)) or (roster is None and team.slide_player(player_name, new_pos)):
await msg.channel.send(embed=build_team_embed(team)) await msg.channel.send(embed=build_team_embed(team))
@ -418,8 +457,6 @@ class MovePlayerCommand(Command):
else: else:
raise CommandError("You either gave us a number that was bigger than your current roster, or we couldn't find the player on the team. Try again.") raise CommandError("You either gave us a number that was bigger than your current roster, or we couldn't find the player on the team. Try again.")
except IndexError:
raise CommandError("Four lines, remember? Command, then team, then name, and finally, new spot on the lineup or rotation.")
class AddPlayerCommand(Command): class AddPlayerCommand(Command):
name = "addplayer" name = "addplayer"
@ -1598,10 +1635,10 @@ class TeamsInfoCommand(Command):
await msg.channel.send(f"We've got {len(games.get_all_teams())} teams! Thanks for asking.") await msg.channel.send(f"We've got {len(games.get_all_teams())} teams! Thanks for asking.")
commands = [ commands = [
IntroduceCommand(), IntroduceCommand(), #not needed
CountActiveGamesCommand(), CountActiveGamesCommand(), #owner only
TeamsInfoCommand(), TeamsInfoCommand(),
AssignOwnerCommand(), AssignOwnerCommand(), #owner only
ShowPlayerCommand(), #done ShowPlayerCommand(), #done
SaveTeamCommand(), #done SaveTeamCommand(), #done
AssignArchetypeCommand(), #done AssignArchetypeCommand(), #done
@ -1615,7 +1652,7 @@ commands = [
ReplacePlayerCommand(), ReplacePlayerCommand(),
DeleteTeamCommand(), DeleteTeamCommand(),
ShowTeamCommand(), #done ShowTeamCommand(), #done
SearchTeamsCommand(), SearchTeamsCommand(), #not needed
StartGameCommand(), #done StartGameCommand(), #done
StartRandomGameCommand(), #done StartRandomGameCommand(), #done
StartTournamentCommand(), StartTournamentCommand(),
@ -1642,8 +1679,8 @@ commands = [
LeagueReplaceTeamCommand(), LeagueReplaceTeamCommand(),
LeagueRenameCommand(), LeagueRenameCommand(),
LeagueForceStopCommand(), LeagueForceStopCommand(),
CreditCommand(), CreditCommand(), #done
RomanCommand(), RomanCommand(), #not needed
HelpCommand(), HelpCommand(),
StartDraftCommand(), StartDraftCommand(),
DraftFlagsCommand(), DraftFlagsCommand(),