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: else:
return (None, None, None) 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): def average_stars(self):
total_stars = 0 total_stars = 0
for _player in self.lineup: for _player in self.lineup:
@ -151,6 +156,21 @@ class team(object):
return True return True
else: else:
return False 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): def add_lineup(self, new_player):
if len(self.lineup) < 20: if len(self.lineup) < 20:

View file

@ -370,13 +370,26 @@ class MovePlayerCommand(Command):
if owner_id != msg.author.id and msg.author.id not in config()["owners"]: 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.") await msg.channel.send("You're not authorized to mess with this team. Sorry, boss.")
return 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: else:
await msg.channel.send(embed=build_team_embed(team)) if team.find_player(player_name)[2] is None or len(team.find_player(player_name)[2]) <= new_pos:
games.update_team(team) 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.")
await msg.channel.send("Paperwork signed, stamped, copied, and faxed up to the goddess. Xie's pretty quick with this stuff.") 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: except IndexError:
await msg.channel.send("Four lines, remember? Command, then team, then name, and finally, new spot on the lineup or rotation.") await msg.channel.send("Four lines, remember? Command, then team, then name, and finally, new spot on the lineup or rotation.")