space matches

This commit is contained in:
xeals 2023-04-03 20:23:17 +10:00
parent 641ddef209
commit 25b80a71a1
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

View File

@ -136,8 +136,10 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
match chunks:
case ["player", id, username, *rest]:
players[id] = username
case ["turn", turn]:
turn = int(turn)
case ["move", user, move, target]:
last_move = (user, target)
player, user = resolve_mon(user)
@ -150,6 +152,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
""",
(game, turn, team(player), move, user, target),
)
case ["switch", name, specie, *rest]:
player, name = resolve_mon(name)
conn.execute(
@ -168,6 +171,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
""",
(game, team(player), name, specie.split(", ")[0]),
)
case ["faint", mon]:
player, mon = resolve_mon(mon)
conn.execute(
@ -178,6 +182,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
""",
(game, turn, team(player), mon),
)
case ["win", player]:
conn.execute(
"""
@ -187,18 +192,21 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
""",
(team(player), game),
)
case ["-sidestart", side, env]:
if not last_move:
LOG.warning(f"missing previous move for {line}")
continue
LOG.debug(f"{line} <- {last_move}")
last_env_set[(side[0:1], env.replace("move: ", ""))] = last_move[0]
case ["-status", mon, cond]:
if not last_move or last_move[1] != mon:
LOG.warning(f"missing previous move for {line}")
continue
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"
@ -248,6 +256,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
team(source_player),
),
)
case _:
# LOG.debug(f"unhandled message {chunks[0]}")
pass