Skip to content

Instantly share code, notes, and snippets.

@mrtolkien
Created April 29, 2021 02:14
Show Gist options
  • Save mrtolkien/68b9f37546f3f1b6ba27f47fa91f66c4 to your computer and use it in GitHub Desktop.
Save mrtolkien/68b9f37546f3f1b6ba27f47fa91f66c4 to your computer and use it in GitHub Desktop.
LCU driver usage example
from lcu_driver import MultipleClientConnector
@connector.ws.register("/lol-champ-select/v1/session")
async def champ_select_listener(connection, event):
# Happens sometimes, need to properly analyze it
if not event.data:
return
# This is simply an ongoing draft, we exit after having written the draft
if event.data["timer"].get("phase") not in ["", "FINALIZATION", "GAME_STARTING"]:
return
# In custom games (even TR), gameId is 0 during all champ select and can’t be used
# We query the lobby information instead that gives us a lobby ID
lobby_information = await (
await connection.request("get", "/lol-lobby/v2/lobby")
).json()
# This happens at the very end of the draft, after swaps
if event.data["timer"]["phase"] == "GAME_STARTING":
# We upload the final draft to GSheets
upload_draft_to_gsheets(
picks_bans=picks_bans,
lobby_information=lobby_information,
patch=float(event.data.get("patch") or 0),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment