Merge pull request #39 from robbyblum/master

issue #35 fix hopefully ("can't display 0 star player" bug)
This commit is contained in:
Sakimori 2020-12-26 20:27:27 -05:00 committed by GitHub
commit 6e8a54cead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,6 +137,7 @@ async def on_message(msg):
if innings < 2: if innings < 2:
await msg.channel.send("Anything less than 2 innings isn't even an outing. Try again.") await msg.channel.send("Anything less than 2 innings isn't even an outing. Try again.")
return return
elif innings > 30 and msg.author.id not in config()["owners"]: elif innings > 30 and msg.author.id not in config()["owners"]:
await msg.channel.send("Y'all can't behave, so we've limited games to 30 innings. Ask xvi to start it with more if you really want to.") await msg.channel.send("Y'all can't behave, so we've limited games to 30 innings. Ask xvi to start it with more if you really want to.")
@ -147,7 +148,7 @@ async def on_message(msg):
elif command.startswith("setupgame"): elif command.startswith("setupgame"):
if len(gamesarray) > 45: if len(gamesarray) > 45:
await msg.channel.send("We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap.") await msg.channel.send("We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap."
return return
elif config()["game_freeze"]: elif config()["game_freeze"]:
await msg.channel.send("Patch incoming. We're not allowing new games right now.") await msg.channel.send("Patch incoming. We're not allowing new games right now.")
@ -165,7 +166,7 @@ async def on_message(msg):
await game_task await game_task
elif command.startswith("saveteam\n"): elif command.startswith("saveteam\n"):
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:
save_task = asyncio.create_task(save_team_batch(msg, command)) save_task = asyncio.create_task(save_team_batch(msg, command))
await save_task await save_task
else: else:
@ -173,7 +174,7 @@ async def on_message(msg):
await msg.channel.send(f"{name} already exists. Try a new name, maybe?") await msg.channel.send(f"{name} already exists. Try a new name, maybe?")
elif command.startswith("showteam "): elif command.startswith("showteam "):
team = games.get_team(command.split(" ",1)[1]) team = games.get_team(command.split(" ",1)[1])
if team is not None: if team is not None:
await msg.channel.send(embed=build_team_embed(team)) await msg.channel.send(embed=build_team_embed(team))
else: else:
@ -203,9 +204,9 @@ async def on_message(msg):
"saveteam":("m;saveteam", """To save an entire team, send this command at the top of a list, with lines seperated by newlines (shift+enter in discord, or copy+paste from notepad) "saveteam":("m;saveteam", """To save an entire team, send this command at the top of a list, with lines seperated by newlines (shift+enter in discord, or copy+paste from notepad)
- the first line of the list is your team's name (cannot contain emoji) - the first line of the list is your team's name (cannot contain emoji)
- the second is your team's slogan - the second is your team's slogan
- the rest of the lines are your players' names - the rest of the lines are your players' names
- the last player is designated your pitcher - the last player is designated your pitcher
if you did it correctly, you'll get a team embed with a prompt to confirm. Hit the 👍 and it'll be saved."""), if you did it correctly, you'll get a team embed with a prompt to confirm. Hit the 👍 and it'll be saved."""),
"showteam":("m;showteam [name]", "You can view any saved team with this command"), "showteam":("m;showteam [name]", "You can view any saved team with this command"),
"showallteams":("m;showallteams", "This displays a paginated list of all teams available for `startgame`"), "showallteams":("m;showallteams", "This displays a paginated list of all teams available for `startgame`"),
"searchteams":("m;searchteams [searchterm]", "Displays paginated list of all teams whose names contain `searchterm`"), "searchteams":("m;searchteams [searchterm]", "Displays paginated list of all teams whose names contain `searchterm`"),
@ -271,7 +272,7 @@ async def setup_game(channel, owner, newgame):
def nameinput(msg): def nameinput(msg):
return msg.content.startswith(newgame.name) and msg.channel == channel #if author or willing participant and in correct channel return msg.content.startswith(newgame.name) and msg.channel == channel #if author or willing participant and in correct channel
while newgame.teams["away"].pitcher == None: while newgame.teams["away"].pitcher == None:
try: try:
@ -385,7 +386,7 @@ async def watch_game(channel, game):
occupied_base = discord.utils.get(client.emojis, id = 790899850320543745) occupied_base = discord.utils.get(client.emojis, id = 790899850320543745)
out_emoji = discord.utils.get(client.emojis, id = 791578957241778226) out_emoji = discord.utils.get(client.emojis, id = 791578957241778226)
in_emoji = discord.utils.get(client.emojis, id = 791578957244792832) in_emoji = discord.utils.get(client.emojis, id = 791578957244792832)
newgame = game newgame = game
embed = await channel.send("Starting...") embed = await channel.send("Starting...")
await asyncio.sleep(1) await asyncio.sleep(1)
@ -417,7 +418,7 @@ async def watch_game(channel, game):
if state == "Game not started.": if state == "Game not started.":
new_embed.add_field(name="🍿", value="Play blall!", inline=False) new_embed.add_field(name="🍿", value="Play blall!", inline=False)
elif newgame.top_of_inning != top_of_inning: elif newgame.top_of_inning != top_of_inning:
pause = 2 pause = 2
new_embed.set_field_at(4, name="Pitcher:", value="-", inline=False) new_embed.set_field_at(4, name="Pitcher:", value="-", inline=False)
@ -433,11 +434,11 @@ async def watch_game(channel, game):
if newgame.teams["home"].score > newgame.teams["away"].score: #if home team is winning at the bottom of the last inning if newgame.teams["home"].score > newgame.teams["away"].score: #if home team is winning at the bottom of the last inning
victory_lap = True victory_lap = True
new_embed.add_field(name="🍿", value=f"Bottom of {newgame.inning}. {newgame.teams['home'].name} batting!", inline=False) new_embed.add_field(name="🍿", value=f"Bottom of {newgame.inning}. {newgame.teams['home'].name} batting!", inline=False)
if pause != 1 and state != "Game not started.": if pause != 1 and state != "Game not started.":
punc = "" punc = ""
if newgame.last_update[0]["defender"] != "": if newgame.last_update[0]["defender"] != "":
punc = ". " punc = ". "
updatestring = f"{newgame.last_update[0]['batter']} {newgame.last_update[0]['text'].value} {newgame.last_update[0]['defender']}{punc}" updatestring = f"{newgame.last_update[0]['batter']} {newgame.last_update[0]['text'].value} {newgame.last_update[0]['defender']}{punc}"
if newgame.last_update[1] > 0: if newgame.last_update[1] > 0:
@ -450,7 +451,7 @@ async def watch_game(channel, game):
basemessage += str(occupied_base) + "\n" basemessage += str(occupied_base) + "\n"
else: else:
basemessage += str(empty_base) + "\n" basemessage += str(empty_base) + "\n"
basemessage_b = "" basemessage_b = ""
if newgame.bases[3] is not None: if newgame.bases[3] is not None:
basemessage += str(occupied_base) basemessage += str(occupied_base)
@ -465,11 +466,11 @@ async def watch_game(channel, game):
new_embed.add_field(name="Bases:", value=basemessage, inline = False) new_embed.add_field(name="Bases:", value=basemessage, inline = False)
await embed.edit(content=None, embed=new_embed) await embed.edit(content=None, embed=new_embed)
top_of_inning = newgame.top_of_inning top_of_inning = newgame.top_of_inning
if pause <= 1: if pause <= 1:
newgame.gamestate_update_full() newgame.gamestate_update_full()
pause -= 1 pause -= 1
await asyncio.sleep(6) await asyncio.sleep(6)
@ -495,12 +496,12 @@ async def watch_game(channel, game):
final_embed.add_field(name="Final score:", value=scorestring) final_embed.add_field(name="Final score:", value=scorestring)
await embed.edit(content=None, embed=final_embed) await embed.edit(content=None, embed=final_embed)
await embed.unpin() await embed.unpin()
gamesarray.pop(gamesarray.index((newgame,use_emoji_names))) #cleanup is important! gamesarray.pop(gamesarray.index((newgame,use_emoji_names))) #cleanup is important!
newgame.add_stats() newgame.add_stats()
del newgame del newgame
def build_team_embed(team): def build_team_embed(team):
embed = discord.Embed(color=discord.Color.purple(), title=team.name) embed = discord.Embed(color=discord.Color.purple(), title=team.name)
lineup_string = "" lineup_string = ""
@ -518,15 +519,13 @@ def build_star_embed(player_json):
for key in starkeys.keys(): for key in starkeys.keys():
embedstring = "" embedstring = ""
starstring = str(player_json[key]) starstring = str(player_json[key])
if ".5" in starstring: starnum = int(starstring[0])
starnum = int(starstring[0]) addhalf = ".5" in starstring
addhalf = True
else:
starnum = int(player_json[key])
addhalf = False
embedstring += "" * starnum embedstring += "" * starnum
if addhalf: if addhalf:
embedstring += "" embedstring += ""
elif starnum == 0: # why check addhalf twice, amirite
embedstring += "⚪️"
embed.add_field(name=starkeys[key], value=embedstring, inline=False) embed.add_field(name=starkeys[key], value=embedstring, inline=False)
return embed return embed