fixes #177: moveplayer now supports pitcher and batter arguments, just like addplayer (works as before without this argument)

This commit is contained in:
Sakimori 2021-02-03 03:12:24 -05:00
parent b556e023c4
commit 93eafd2104
2 changed files with 39 additions and 6 deletions

View file

@ -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:
@ -152,6 +157,21 @@ class team(object):
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:
self.lineup.append(new_player)

View file

@ -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):
else:
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.")