track indirect ko source players

This commit is contained in:
xeals 2023-03-28 00:00:27 +11:00
parent a9f52351e7
commit c8f5803c83
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

40
main.py
View File

@ -79,7 +79,7 @@ def _init_db(conn: sqlite3.Connection):
UNIQUE(game, turn, player) UNIQUE(game, turn, player)
); );
CREATE TABLE IF NOT EXISTS indirect_knockouts( CREATE TABLE IF NOT EXISTS indirect_knockouts(
game, turn, player, name, source, source_user, game, turn, player, name, source, source_user, source_player,
UNIQUE(game, turn, player) UNIQUE(game, turn, player)
); );
CREATE TABLE IF NOT EXISTS games( CREATE TABLE IF NOT EXISTS games(
@ -183,32 +183,38 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
source = rest[1].replace("[from] ", "") source = rest[1].replace("[from] ", "")
source_user = None source_user = None
if source == "Recoil" or source.startswith("item: "): test_hazard = last_env_set.get((mon[0:1], source))
source_user = source.replace("item: ", "") if test_hazard:
source_user = test_hazard
if source_user:
LOG.debug(f"identified special source {source_user}")
else:
source_user = last_env_set.get((mon[0:1], source))
if source_user:
LOG.debug(f"identified hazard source {source_user}") LOG.debug(f"identified hazard source {source_user}")
else:
source_user = last_status_set.get((mon, source))
if 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}") LOG.debug(f"identified move source {source_user}")
else:
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}") LOG.error(f"missing source for {line}")
continue 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
conn.execute( conn.execute(
""" """
INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user) INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player)
VALUES(?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
(game, turn, player, mon, source, source_user), (game, turn, player, mon, source, source_user, source_player),
) )
case _: case _:
# LOG.debug(f"unhandled message {chunks[0]}") # LOG.debug(f"unhandled message {chunks[0]}")