Added /log frame-check
Fixed game-summary error
This commit is contained in:
parent
8118b4a691
commit
1e9e79916f
@ -11,7 +11,7 @@ import pygsheets
|
|||||||
from sqlmodel import or_
|
from sqlmodel import or_
|
||||||
|
|
||||||
from api_calls import db_get
|
from api_calls import db_get
|
||||||
from command_logic.logic_gameplay import advance_runners, bunts, chaos, complete_game, doubles, flyballs, get_full_roster_from_sheets, get_lineups_from_sheets, checks_log_interaction, complete_play, get_scorebug_embed, groundballs, hit_by_pitch, homeruns, is_game_over, manual_end_game, popouts, read_lineup, show_defense_cards, singles, starting_pitcher_dropdown_view, steals, strikeouts, triples, undo_play, update_game_settings, walks, xchecks
|
from command_logic.logic_gameplay import advance_runners, bunts, chaos, complete_game, doubles, flyballs, frame_checks, get_full_roster_from_sheets, get_lineups_from_sheets, checks_log_interaction, complete_play, get_scorebug_embed, groundballs, hit_by_pitch, homeruns, is_game_over, manual_end_game, popouts, read_lineup, show_defense_cards, singles, starting_pitcher_dropdown_view, steals, strikeouts, triples, undo_play, update_game_settings, walks, xchecks
|
||||||
from dice import ab_roll
|
from dice import ab_roll
|
||||||
from exceptions import GameNotFoundException, GoogleSheetsException, TeamNotFoundException, PlayNotFoundException, GameException, log_exception
|
from exceptions import GameNotFoundException, GoogleSheetsException, TeamNotFoundException, PlayNotFoundException, GameException, log_exception
|
||||||
from helpers import DEFENSE_LITERAL, PD_PLAYERS_ROLE_NAME, get_channel, team_role, user_has_role, random_gif, random_from_list
|
from helpers import DEFENSE_LITERAL, PD_PLAYERS_ROLE_NAME, get_channel, team_role, user_has_role, random_gif, random_from_list
|
||||||
@ -436,6 +436,21 @@ class Gameplay(commands.Cog):
|
|||||||
buffer_message='Double logged' if this_play.starting_outs + this_play.outs < 3 and ((this_play.on_second and flyball_type == 'b') or (this_play.on_third and flyball_type == '?b')) else None
|
buffer_message='Double logged' if this_play.starting_outs + this_play.outs < 3 and ((this_play.on_second and flyball_type == 'b') or (this_play.on_third and flyball_type == '?b')) else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@group_log.command(name='frame-pitch', description=f'Walk/strikeout split; determined by home plate umpire')
|
||||||
|
async def log_frame_check(self, interaction: discord.Interaction):
|
||||||
|
with Session(engine) as session:
|
||||||
|
this_game, owner_team, this_play = await checks_log_interaction(session, interaction, command_name='log frame-check')
|
||||||
|
|
||||||
|
logger.info(f'log frame-check - this_play: {this_play}')
|
||||||
|
this_play = await frame_checks(session, interaction, this_play)
|
||||||
|
|
||||||
|
await self.complete_and_post_play(
|
||||||
|
session,
|
||||||
|
interaction,
|
||||||
|
this_play,
|
||||||
|
buffer_message='Frame check logged'
|
||||||
|
)
|
||||||
|
|
||||||
@group_log.command(name='single', description='Singles: *, **, ballpark, uncapped')
|
@group_log.command(name='single', description='Singles: *, **, ballpark, uncapped')
|
||||||
async def log_single(
|
async def log_single(
|
||||||
self, interaction: discord.Interaction, single_type: Literal['*', '**', 'ballpark', 'uncapped']):
|
self, interaction: discord.Interaction, single_type: Literal['*', '**', 'ballpark', 'uncapped']):
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from sqlalchemy import delete
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from api_calls import db_delete, db_get, db_post
|
from api_calls import db_delete, db_get, db_post
|
||||||
from dice import sa_fielding_roll
|
from dice import frame_plate_check, sa_fielding_roll
|
||||||
from exceptions import *
|
from exceptions import *
|
||||||
from helpers import DEFENSE_LITERAL, SBA_COLOR, get_channel
|
from helpers import DEFENSE_LITERAL, SBA_COLOR, get_channel
|
||||||
from in_game.game_helpers import legal_check
|
from in_game.game_helpers import legal_check
|
||||||
@ -349,7 +349,8 @@ def get_wpa(this_play: Play, next_play: Play):
|
|||||||
# print(f'manually setting new_win_ex to 1.0')
|
# print(f'manually setting new_win_ex to 1.0')
|
||||||
new_win_ex = 1.0
|
new_win_ex = 1.0
|
||||||
else:
|
else:
|
||||||
new_win_ex = WPA_DF.loc[f'{next_play.inning_half}_{next_play.inning_num}_{next_play.starting_outs}_out_{next_play.on_base_code}_obc_{new_rd}_home_run_diff'].home_win_ex
|
inning_num = 9 if next_play.inning_num > 9 else next_play.inning_num
|
||||||
|
new_win_ex = WPA_DF.loc[f'{next_play.inning_half}_{inning_num}_{next_play.starting_outs}_out_{next_play.on_base_code}_obc_{new_rd}_home_run_diff'].home_win_ex
|
||||||
# print(f'new_win_ex = {new_win_ex}')
|
# print(f'new_win_ex = {new_win_ex}')
|
||||||
|
|
||||||
old_win_ex = WPA_DF.loc[f'{this_play.inning_half}_{this_play.inning_num}_{this_play.starting_outs}_out_{this_play.on_base_code}_obc_{old_rd}_home_run_diff'].home_win_ex
|
old_win_ex = WPA_DF.loc[f'{this_play.inning_half}_{this_play.inning_num}_{this_play.starting_outs}_out_{this_play.on_base_code}_obc_{old_rd}_home_run_diff'].home_win_ex
|
||||||
@ -969,6 +970,30 @@ async def flyballs(session: Session, interaction: discord.Interaction, this_play
|
|||||||
return this_play
|
return this_play
|
||||||
|
|
||||||
|
|
||||||
|
async def frame_checks(session: Session, interaction: discord.Interaction, this_play: Play):
|
||||||
|
"""
|
||||||
|
Commits this_play
|
||||||
|
"""
|
||||||
|
this_roll = frame_plate_check(this_play.batter.team, this_play.game)
|
||||||
|
logger.info(f'this_roll: {this_roll}')
|
||||||
|
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embeds=this_roll.embeds
|
||||||
|
)
|
||||||
|
|
||||||
|
if this_roll.is_walk:
|
||||||
|
this_play = await walks(session, interaction, this_play, 'unintentional')
|
||||||
|
else:
|
||||||
|
this_play = await strikeouts(session, interaction, this_play)
|
||||||
|
|
||||||
|
session.add(this_play)
|
||||||
|
session.commit()
|
||||||
|
await asyncio.sleep(1.5)
|
||||||
|
|
||||||
|
session.refresh(this_play)
|
||||||
|
return this_play
|
||||||
|
|
||||||
async def check_uncapped_advance(session: Session, interaction: discord.Interaction, this_play: Play, lead_runner: Lineup, lead_base: int, trail_runner: Lineup, trail_base: int):
|
async def check_uncapped_advance(session: Session, interaction: discord.Interaction, this_play: Play, lead_runner: Lineup, lead_base: int, trail_runner: Lineup, trail_base: int):
|
||||||
this_game = this_play.game
|
this_game = this_play.game
|
||||||
outfielder = await show_outfield_cards(session, interaction, this_play)
|
outfielder = await show_outfield_cards(session, interaction, this_play)
|
||||||
@ -2162,7 +2187,7 @@ async def get_game_summary_embed(session: Session, interaction: discord.Interact
|
|||||||
|
|
||||||
for line in all_poop:
|
for line in all_poop:
|
||||||
poop_line = f'{player_name} - '
|
poop_line = f'{player_name} - '
|
||||||
player_name = f'{get_player_name_from_dict(tp['player'])}'
|
player_name = f'{get_player_name_from_dict(line['player'])}'
|
||||||
|
|
||||||
if 'hr' in line:
|
if 'hr' in line:
|
||||||
poop_line += f'{line["hit"]}-{line["ab"]}'
|
poop_line += f'{line["hit"]}-{line["ab"]}'
|
||||||
@ -2171,7 +2196,7 @@ async def get_game_summary_embed(session: Session, interaction: discord.Interact
|
|||||||
if tp['run'] != line['e_run']:
|
if tp['run'] != line['e_run']:
|
||||||
poop_line += f' ({line["e_run"]} ER)'
|
poop_line += f' ({line["e_run"]} ER)'
|
||||||
poop_line += f', {line["hit"]} H, {line["so"]} K'
|
poop_line += f', {line["hit"]} H, {line["so"]} K'
|
||||||
poop_line += f', {tp["re24"]:.2f} re24\n'
|
poop_line += f', {line["re24"]:.2f} re24\n'
|
||||||
poop_string += poop_line
|
poop_string += poop_line
|
||||||
|
|
||||||
if len(poop_string) > 0:
|
if len(poop_string) > 0:
|
||||||
|
|||||||
17
dice.py
17
dice.py
@ -36,6 +36,10 @@ class FieldingRoll(DiceRoll):
|
|||||||
error_result: Literal[1, 2, 3] | None = None
|
error_result: Literal[1, 2, 3] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class FrameRoll(DiceRoll):
|
||||||
|
is_walk: bool = False
|
||||||
|
|
||||||
|
|
||||||
def get_dice_embed(team: Team = None, embed_title: str = None):
|
def get_dice_embed(team: Team = None, embed_title: str = None):
|
||||||
if team:
|
if team:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
@ -2739,8 +2743,8 @@ def sa_fielding_roll(this_team: Team, this_play: Play, pos_code: str, def_rating
|
|||||||
return this_roll
|
return this_roll
|
||||||
|
|
||||||
|
|
||||||
def frame_plate_check(team: dict, game_id: int):
|
def frame_plate_check(team: Team, this_game: Game) -> FrameRoll:
|
||||||
tens_digit = (game_id // 10) % 10
|
tens_digit = (this_game.id // 10) % 10
|
||||||
half_tens = round(tens_digit / 2)
|
half_tens = round(tens_digit / 2)
|
||||||
d_twenty = random.randint(1, 20)
|
d_twenty = random.randint(1, 20)
|
||||||
roll_message = f'```md\n' \
|
roll_message = f'```md\n' \
|
||||||
@ -2765,11 +2769,18 @@ def frame_plate_check(team: dict, game_id: int):
|
|||||||
result_message = f'**{"WALK" if d_twenty <= this_ump["walk_d20"] else "STRIKEOUT"}**'
|
result_message = f'**{"WALK" if d_twenty <= this_ump["walk_d20"] else "STRIKEOUT"}**'
|
||||||
|
|
||||||
roll_embed = get_dice_embed()
|
roll_embed = get_dice_embed()
|
||||||
roll_embed.add_field(name=f'Pitch Framing roll for {team["gmname"]}', value=roll_message)
|
roll_embed.add_field(name=f'Pitch Framing roll for {team.gmname}', value=roll_message)
|
||||||
roll_embed.add_field(name=f'Umpire: {this_ump["name"]}', value=ump_message)
|
roll_embed.add_field(name=f'Umpire: {this_ump["name"]}', value=ump_message)
|
||||||
roll_embed.add_field(name='Result', value=result_message, inline=False)
|
roll_embed.add_field(name='Result', value=result_message, inline=False)
|
||||||
roll_embed.set_footer(text="This result will be logged automatically")
|
roll_embed.set_footer(text="This result will be logged automatically")
|
||||||
|
|
||||||
|
this_roll = FrameRoll(
|
||||||
|
embeds=[roll_embed],
|
||||||
|
d_twenty=d_twenty,
|
||||||
|
is_walk=d_twenty<=this_ump["walk_d20"]
|
||||||
|
)
|
||||||
|
return this_roll
|
||||||
|
|
||||||
return {'embed': roll_embed, 'is_walk': d_twenty <= this_ump['walk_d20']}
|
return {'embed': roll_embed, 'is_walk': d_twenty <= this_ump['walk_d20']}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user