From 93eafd21047cb60c5fac7c8e903c89d5e02d8315 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Wed, 3 Feb 2021 03:12:24 -0500 Subject: [PATCH] fixes #177: moveplayer now supports pitcher and batter arguments, just like addplayer (works as before without this argument) --- games.py | 20 ++++++++++++++++++++ the_prestige.py | 25 +++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/games.py b/games.py index 69d1d16..88f5ed9 100644 --- a/games.py +++ b/games.py @@ -114,6 +114,11 @@ class team(object): else: return (None, None, None) + def find_player_spec(self, name, roster): + for s_index in range(0,len(roster)): + if roster[s_index].name == name: + return (roster[s_index], s_index) + def average_stars(self): total_stars = 0 for _player in self.lineup: @@ -151,6 +156,21 @@ class team(object): return True else: return False + + def slide_player_spec(self, this_player_name, new_spot, roster): + index = None + for s_index in range(0,len(roster)): + if roster[s_index].name == this_player_name: + index = s_index + this_player = roster[s_index] + if index is None: + return False + elif new_spot <= len(roster): + roster.pop(index) + roster.insert(new_spot-1, this_player) + return True + else: + return False def add_lineup(self, new_player): if len(self.lineup) < 20: diff --git a/the_prestige.py b/the_prestige.py index a6f649d..515b1d9 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -370,13 +370,26 @@ class MovePlayerCommand(Command): if owner_id != msg.author.id and msg.author.id not in config()["owners"]: await msg.channel.send("You're not authorized to mess with this team. Sorry, boss.") return - elif not team.slide_player(player_name, new_pos): - await msg.channel.send("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.") - return else: - await msg.channel.send(embed=build_team_embed(team)) - games.update_team(team) - await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.") + if team.find_player(player_name)[2] is None or len(team.find_player(player_name)[2]) <= new_pos: + await msg.channel.send("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.") + return + + if "batter" in command.split("\n")[0].lower(): + roster = team.lineup + elif "pitcher" in command.split("\n")[0].lower(): + roster = team.rotation + else: + roster = None + + 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)) + games.update_team(team) + await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.") + else: + await msg.channel.send("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.") + return + except IndexError: await msg.channel.send("Four lines, remember? Command, then team, then name, and finally, new spot on the lineup or rotation.")