Merge pull request 'fix: batch cleanup — dead code, bare excepts, empty stubs' (#104) from fix/batch-cleanup-group-a into main
All checks were successful
Build Docker Image / build (push) Successful in 1m5s

This commit is contained in:
Claude 2026-03-23 04:27:42 +00:00
commit 6b375e62af
5 changed files with 24 additions and 57 deletions

View File

@ -17,7 +17,6 @@ DB_URL = (
if "prod" in ENV_DATABASE
else "https://pddev.manticorum.com/api"
)
PLAYER_CACHE = {}
logger = logging.getLogger("discord_app")

View File

@ -1266,7 +1266,7 @@ async def checks_log_interaction(
f"Hm, I was not able to find a gauntlet team for you."
)
if not owner_team.id in [this_game.away_team_id, this_game.home_team_id]:
if owner_team.id not in [this_game.away_team_id, this_game.home_team_id]:
if interaction.user.id != 258104532423147520:
logger.exception(
f"{interaction.user.display_name} tried to run a command in Game {this_game.id} when they aren't a GM in the game."
@ -4307,22 +4307,17 @@ async def complete_game(
# Post game stats to API
try:
resp = await db_post("plays", payload=db_ready_plays)
await db_post("plays", payload=db_ready_plays)
except Exception as e:
await roll_back(db_game["id"], plays=True)
log_exception(e, msg="Unable to post plays to API, rolling back")
if len(resp) > 0:
pass
try:
resp = await db_post("decisions", payload={"decisions": db_ready_decisions})
await db_post("decisions", payload={"decisions": db_ready_decisions})
except Exception as e:
await roll_back(db_game["id"], plays=True, decisions=True)
log_exception(e, msg="Unable to post decisions to API, rolling back")
if len(resp) > 0:
pass
# Post game rewards (gauntlet and main team)
try:

View File

@ -1315,47 +1315,9 @@ def create_test_games():
session.commit()
def select_speed_testing():
with Session(engine) as session:
game_1 = session.exec(select(Game).where(Game.id == 1)).one()
ss_search_start = datetime.datetime.now()
man_ss = [x for x in game_1.lineups if x.position == 'SS' and x.active]
ss_search_end = datetime.datetime.now()
ss_query_start = datetime.datetime.now()
query_ss = session.exec(select(Lineup).where(Lineup.game == game_1, Lineup.position == 'SS', Lineup.active == True)).all()
ss_query_end = datetime.datetime.now()
manual_time = ss_search_end - ss_search_start
query_time = ss_query_end - ss_query_start
print(f'Manual Shortstops: time: {manual_time.microseconds} ms / {man_ss}')
print(f'Query Shortstops: time: {query_time.microseconds} ms / {query_ss}')
print(f'Game: {game_1}')
games = session.exec(select(Game).where(Game.active == True)).all()
print(f'len(games): {len(games)}')
def select_all_testing():
with Session(engine) as session:
game_search = session.exec(select(Team)).all()
for game in game_search:
print(f'Game: {game}')
# def select_specic_fields():
# with Session(engine) as session:
# games = session.exec(select(Game.id, Game.away_team, Game.home_team))
# print(f'Games: {games}')
# print(f'.all(): {games.all()}')
def main():
create_db_and_tables()
create_test_games()
# select_speed_testing()
# select_all_testing()
if __name__ == "__main__":

View File

@ -124,7 +124,7 @@ async def get_team_or_none(
logger.info(f'Refreshing this_team')
session.refresh(this_team)
return this_team
except:
except Exception:
logger.info(f'Team not found, adding to db')
session.add(db_team)
session.commit()
@ -235,7 +235,7 @@ async def get_player_or_none(session: Session, player_id: int, skip_cache: bool
logger.info(f'Refreshing this_player')
session.refresh(this_player)
return this_player
except:
except Exception:
session.add(db_player)
session.commit()
session.refresh(db_player)
@ -307,7 +307,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_card = db_bc
session.add(this_card)
@ -330,7 +330,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_vl_rating = db_vl
session.add(this_vl_rating)
@ -353,7 +353,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_vr_rating = db_vr
session.add(this_vr_rating)
@ -444,7 +444,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_card = db_bc
session.add(this_card)
@ -467,7 +467,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_vl_rating = db_vl
session.add(this_vl_rating)
@ -490,7 +490,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache:
# logger.info(f'Refreshing this_card')
# session.refresh(this_card)
# return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
this_vr_rating = db_vr
session.add(this_vr_rating)
@ -699,7 +699,7 @@ async def get_or_create_ai_card(session: Session, player: Player, team: Team, sk
logger.info(f'Refreshing this_card')
session.refresh(this_card)
return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
session.add(db_card)
session.commit()
@ -808,7 +808,7 @@ async def get_card_or_none(session: Session, card_id: int, skip_cache: bool = Fa
logger.info(f'Refreshing this_card')
session.refresh(this_card)
return this_card
except:
except Exception:
logger.info(f'Card not found, adding to db')
session.add(db_card)
session.commit()

11
ruff.toml Normal file
View File

@ -0,0 +1,11 @@
# Ruff configuration for paper-dynasty discord bot
# See https://docs.astral.sh/ruff/configuration/
[lint]
# F403/F405: star imports from exceptions.py are intentional — exceptions module
# exports a curated set of project exceptions via __all__
# F541: f-strings without placeholders — cosmetic, low risk
# F401: unused imports — many are re-exported or used conditionally
# F841: unused variables — often intentional in SQLModel session patterns
# E712: SQLAlchemy/SQLModel ORM comparisons to True/False require == syntax
ignore = ["F403", "F405", "F541", "F401", "F841", "E712"]