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