diff --git a/main.py b/main.py index 10538cf..d9ffabd 100755 --- a/main.py +++ b/main.py @@ -207,55 +207,53 @@ def parse_log(game: str, log: str, into: sqlite3.Connection): LOG.debug(f"{line} <- {last_move}") last_status_set[(mon, cond)] = last_move[0] - case ["-damage", mon, *rest]: - # rest is new_hp and sometimes a source (if not from a move) - # in a knockout, new_hp is "0 fnt" - if rest[0] == "0 fnt" and len(rest) > 1: - LOG.debug(f"tracing source for {line}") - source = rest[1].replace("[from] ", "") - source_user = None + case ["-damage", mon, "0 fnt", from_]: + # mon has fainted from an indirect damage source + LOG.debug(f"tracing source for {line}") + source = from_.replace("[from] ", "") + source_user = None - test_hazard = last_env_set.get((mon[0:1], source)) - if test_hazard: - source_user = test_hazard - LOG.debug(f"identified hazard source {source_user}") + test_hazard = last_env_set.get((mon[0:1], source)) + if test_hazard: + source_user = test_hazard + LOG.debug(f"identified hazard source {source_user}") - test_status = last_status_set.get((mon, source)) - if test_status: - source_user = test_status - LOG.debug(f"identified move source {source_user}") + test_status = last_status_set.get((mon, source)) + if test_status: + source_user = test_status + LOG.debug(f"identified move source {source_user}") - if source == "Recoil" or source.startswith("item: "): - LOG.debug(f"identified special source {source}") - source = source.replace("item: ", "") - source_user = "self" + if source == "Recoil" or source.startswith("item: "): + LOG.debug(f"identified special source {source}") + source = source.replace("item: ", "") + source_user = "self" - if not source_user: - LOG.error(f"missing source for {line}") - continue + if not source_user: + LOG.error(f"missing source for {line}") + continue - player, mon = resolve_mon(mon) - if source_user.startswith("p1") or source_user.startswith("p2"): - source_player, source_user = resolve_mon(source_user) - else: - source_player = None + player, mon = resolve_mon(mon) + if source_user.startswith("p1") or source_user.startswith("p2"): + source_player, source_user = resolve_mon(source_user) + else: + source_player = None - conn.execute( - """ - INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player) - VALUES(?, ?, ?, ?, ?, ?, ?) - ON CONFLICT DO NOTHING - """, - ( - game, - turn, - team(player), - mon, - source, - source_user, - team(source_player), - ), - ) + conn.execute( + """ + INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player) + VALUES(?, ?, ?, ?, ?, ?, ?) + ON CONFLICT DO NOTHING + """, + ( + game, + turn, + team(player), + mon, + source, + source_user, + team(source_player), + ), + ) case _: # LOG.debug(f"unhandled message {chunks[0]}")