tidyed up some half-inning and game end weirdness, fixed end_delay, added game end pings and summary embeds in discord
This commit is contained in:
parent
f4593e1a84
commit
1cf79ce861
1
games.py
1
games.py
|
@ -149,6 +149,7 @@ class game(object):
|
||||||
self.last_update = ({},0) #this is a ({outcome}, runs) tuple
|
self.last_update = ({},0) #this is a ({outcome}, runs) tuple
|
||||||
self.owner = None
|
self.owner = None
|
||||||
self.ready = False
|
self.ready = False
|
||||||
|
self.victory_lap = False
|
||||||
if length is not None:
|
if length is not None:
|
||||||
self.max_innings = length
|
self.max_innings = length
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -43,11 +43,11 @@ def update_loop():
|
||||||
if test_string == "Game not started.": #weather_emoji
|
if test_string == "Game not started.": #weather_emoji
|
||||||
state["update_emoji"] = "🍿" #weather_text
|
state["update_emoji"] = "🍿" #weather_text
|
||||||
state["update_text"] = "Play blall!" #they also need a timestamp
|
state["update_text"] = "Play blall!" #they also need a timestamp
|
||||||
state["delay"] -= 1
|
state["start_delay"] -= 1
|
||||||
|
|
||||||
state["display_top_of_inning"] = state["top_of_inning"]
|
state["display_top_of_inning"] = state["top_of_inning"]
|
||||||
|
|
||||||
if state["delay"] <= 0:
|
if state["start_delay"] <= 0:
|
||||||
if this_game.top_of_inning != state["top_of_inning"]:
|
if this_game.top_of_inning != state["top_of_inning"]:
|
||||||
state["update_pause"] = 2
|
state["update_pause"] = 2
|
||||||
state["pitcher"] = "-"
|
state["pitcher"] = "-"
|
||||||
|
@ -59,8 +59,15 @@ def update_loop():
|
||||||
if state["update_pause"] == 1:
|
if state["update_pause"] == 1:
|
||||||
state["update_emoji"] = "🍿"
|
state["update_emoji"] = "🍿"
|
||||||
if this_game.over:
|
if this_game.over:
|
||||||
|
state["display_inning"] -= 1
|
||||||
|
state["display_top_of_inning"] = False
|
||||||
winning_team = this_game.teams['home'].name if this_game.teams['home'].score > this_game.teams['away'].score else this_game.teams['away'].name
|
winning_team = this_game.teams['home'].name if this_game.teams['home'].score > this_game.teams['away'].score else this_game.teams['away'].name
|
||||||
state["update_text"] = f"{winning_team} wins{' with a victory lap' if state['victory_lap'] else ''}!"
|
if this_game.victory_lap and winning_team == this_game.teams['home'].name:
|
||||||
|
state["update_text"] = f"{winning_team} wins with a victory lap!"
|
||||||
|
elif winning_team == this_game.teams['home'].name:
|
||||||
|
state["update_text"] = f"{winning_team} wins, shaming {this_game.teams['away'].name}!"
|
||||||
|
else:
|
||||||
|
state["update_text"] = f"{winning_team} wins!"
|
||||||
state["pitcher"] = "-"
|
state["pitcher"] = "-"
|
||||||
state["batter"] = "-"
|
state["batter"] = "-"
|
||||||
elif this_game.top_of_inning:
|
elif this_game.top_of_inning:
|
||||||
|
@ -68,7 +75,7 @@ def update_loop():
|
||||||
else:
|
else:
|
||||||
if this_game.inning >= this_game.max_innings:
|
if this_game.inning >= this_game.max_innings:
|
||||||
if this_game.teams["home"].score > this_game.teams["away"].score:
|
if this_game.teams["home"].score > this_game.teams["away"].score:
|
||||||
state["victory_lap"] = True
|
this_game.victory_lap = True
|
||||||
state["update_text"] = f"Bottom of {this_game.inning}. {this_game.teams['home'].name} batting!"
|
state["update_text"] = f"Bottom of {this_game.inning}. {this_game.teams['home'].name} batting!"
|
||||||
|
|
||||||
elif state["update_pause"] != 1 and test_string != "Game not started.":
|
elif state["update_pause"] != 1 and test_string != "Game not started.":
|
||||||
|
@ -103,9 +110,12 @@ def update_loop():
|
||||||
|
|
||||||
states_to_send[game_time] = state
|
states_to_send[game_time] = state
|
||||||
|
|
||||||
if state["update_pause"] <= 1 and state["delay"] < 0:
|
if state["update_pause"] <= 1 and state["start_delay"] < 0:
|
||||||
if this_game.over:
|
if this_game.over:
|
||||||
|
state["update_pause"] = 2
|
||||||
|
if state["end_delay"] < 0:
|
||||||
master_games_dic.pop(game_time)
|
master_games_dic.pop(game_time)
|
||||||
|
state["end_delay"] -= 1
|
||||||
else:
|
else:
|
||||||
this_game.gamestate_update_full()
|
this_game.gamestate_update_full()
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ $(document).ready(function (){
|
||||||
$('#updateTarget .update_emoji').html(gamestate.update_emoji);
|
$('#updateTarget .update_emoji').html(gamestate.update_emoji);
|
||||||
$('#updateTarget .update_text').html(gamestate.update_text);
|
$('#updateTarget .update_text').html(gamestate.update_text);
|
||||||
|
|
||||||
$('#updateTarget .batting').html((gamestate.top_of_inning ? gamestate.away_name : gamestate.home_name) + " batting.");
|
$('#updateTarget .batting').html((gamestate.display_top_of_inning ? gamestate.away_name : gamestate.home_name) + " batting.");
|
||||||
|
|
||||||
gamediv.id = "";
|
gamediv.id = "";
|
||||||
};
|
};
|
||||||
|
|
|
@ -355,6 +355,7 @@ def config():
|
||||||
0000
|
0000
|
||||||
],
|
],
|
||||||
"prefix" : ["m;", "m!"],
|
"prefix" : ["m;", "m!"],
|
||||||
|
"simmadome_url" : "",
|
||||||
"soulscream channel id" : 0,
|
"soulscream channel id" : 0,
|
||||||
"game_freeze" : 0
|
"game_freeze" : 0
|
||||||
}
|
}
|
||||||
|
@ -370,6 +371,8 @@ def config():
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
db.initialcheck()
|
db.initialcheck()
|
||||||
print(f"logged in as {client.user} with token {config()['token']}")
|
print(f"logged in as {client.user} with token {config()['token']}")
|
||||||
|
watch_task = asyncio.create_task(game_watcher())
|
||||||
|
await watch_task
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_reaction_add(reaction, user):
|
async def on_reaction_add(reaction, user):
|
||||||
|
@ -557,9 +560,8 @@ async def watch_game(channel, newgame, user = None):
|
||||||
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)
|
||||||
|
|
||||||
if user is not None:
|
|
||||||
await channel.send(f"Game for {user.mention}:")
|
|
||||||
embed = await channel.send("Starting...")
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
weathers = games.all_weathers()
|
weathers = games.all_weathers()
|
||||||
newgame.weather = weathers[random.choice(list(weathers.keys()))]
|
newgame.weather = weathers[random.choice(list(weathers.keys()))]
|
||||||
|
@ -572,9 +574,13 @@ async def watch_game(channel, newgame, user = None):
|
||||||
"victory_lap" : False,
|
"victory_lap" : False,
|
||||||
"weather_emoji" : newgame.weather.emoji,
|
"weather_emoji" : newgame.weather.emoji,
|
||||||
"weather_text" : newgame.weather.name,
|
"weather_text" : newgame.weather.name,
|
||||||
"delay" : -1
|
"start_delay" : 3,
|
||||||
|
"end_delay" : 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await channel.send(f"{newgame.teams['away'].name} vs. {newgame.teams['home'].name}, starting at {config()['simmadome_url']}")
|
||||||
|
gamesarray.append((newgame, channel, user))
|
||||||
|
|
||||||
main_controller.master_games_dic[str(time.time() * 1000.0)] = (newgame, state_init)
|
main_controller.master_games_dic[str(time.time() * 1000.0)] = (newgame, state_init)
|
||||||
|
|
||||||
#while not newgame.over or newgame.top_of_inning != top_of_inning:
|
#while not newgame.over or newgame.top_of_inning != top_of_inning:
|
||||||
|
@ -869,6 +875,40 @@ async def team_pages(msg, all_teams, search_term=None):
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
async def game_watcher():
|
||||||
|
while True:
|
||||||
|
this_array = gamesarray.copy()
|
||||||
|
for i in range(0,len(this_array)):
|
||||||
|
game, channel, user = this_array[i]
|
||||||
|
if game.over:
|
||||||
|
title_string = f"{game.teams['away'].name} at {game.teams['home'].name} ended after {game.inning-1} innings"
|
||||||
|
if (game.inning - 1) > game.max_innings: #if extra innings
|
||||||
|
title_string += f" with {game.inning - (game.max_innings+1)} extra innings."
|
||||||
|
else:
|
||||||
|
title_string += "."
|
||||||
|
|
||||||
|
winning_team = game.teams['home'].name if game.teams['home'].score > game.teams['away'].score else game.teams['away'].name
|
||||||
|
winstring = f"{game.teams['away'].score} to {game.teams['home'].score}\n"
|
||||||
|
if game.victory_lap and winning_team == game.teams['home'].name:
|
||||||
|
winstring += f"{winning_team} wins with a victory lap!"
|
||||||
|
elif winning_team == game.teams['home'].name:
|
||||||
|
winstring += f"{winning_team} wins, shaming {game.teams['away'].name}!"
|
||||||
|
else:
|
||||||
|
winstring += f"{winning_team} wins!"
|
||||||
|
|
||||||
|
if user is not None:
|
||||||
|
await channel.send(f"{user.mention}'s game just ended.")
|
||||||
|
else:
|
||||||
|
await channel.send("A game started from this channel just ended.")
|
||||||
|
|
||||||
|
final_embed = discord.Embed(color=discord.Color.dark_purple(), title=title_string)
|
||||||
|
final_embed.add_field(name="Final score:", value=winstring)
|
||||||
|
await channel.send(embed=final_embed)
|
||||||
|
gamesarray.pop(i)
|
||||||
|
break
|
||||||
|
|
||||||
|
await asyncio.sleep(6)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
client.run(config()["token"])
|
client.run(config()["token"])
|
Loading…
Reference in New Issue
Block a user