mirror of https://gitlab.com/litecord/litecord.git
change ready.relationships structure on gateway v9
This commit is contained in:
parent
d5348fd33b
commit
9a09311c68
|
|
@ -74,7 +74,7 @@ WebsocketProperties = collections.namedtuple(
|
|||
)
|
||||
|
||||
|
||||
def _complete_users_list(user_id: str, base_ready, user_ready) -> dict:
|
||||
def _complete_users_list(user_id: str, base_ready, user_ready, wsp) -> dict:
|
||||
"""Use the data we were already preparing to send in READY to construct
|
||||
the users array, saving on I/O cost."""
|
||||
|
||||
|
|
@ -100,6 +100,19 @@ def _complete_users_list(user_id: str, base_ready, user_ready) -> dict:
|
|||
|
||||
ready = {**base_ready, **user_ready}
|
||||
ready["users"] = [value for value in users_to_send.values()]
|
||||
|
||||
# relationship object structure changed in v9
|
||||
if wsp.v == 9:
|
||||
ready["relationships"] = []
|
||||
for relationship in user_ready["relationships"]:
|
||||
ready["relationships"].append(
|
||||
{
|
||||
"user_id": relationship["user"]["id"],
|
||||
"type": relationship["type"],
|
||||
"nickname": None, # TODO implement friend nicknames
|
||||
"id": relationship["id"],
|
||||
}
|
||||
)
|
||||
return ready
|
||||
|
||||
|
||||
|
|
@ -426,7 +439,9 @@ class GatewayWebsocket:
|
|||
"shard": [self.state.current_shard, self.state.shard_count],
|
||||
}
|
||||
|
||||
full_ready_data = _complete_users_list(user["id"], base_ready, user_ready)
|
||||
full_ready_data = _complete_users_list(
|
||||
user["id"], base_ready, user_ready, self.wsp
|
||||
)
|
||||
|
||||
if not self.state.bot:
|
||||
for guild in full_ready_data["guilds"]:
|
||||
|
|
|
|||
|
|
@ -49,19 +49,21 @@ async def _close(conn):
|
|||
await conn.close(1000, "test end")
|
||||
|
||||
|
||||
async def get_gw(test_cli) -> str:
|
||||
async def get_gw(test_cli, version: int) -> str:
|
||||
"""Get the Gateway URL."""
|
||||
gw_resp = await test_cli.get("/api/v6/gateway")
|
||||
gw_resp = await test_cli.get(f"/api/v{version}/gateway")
|
||||
gw_json = await gw_resp.json
|
||||
return gw_json["url"]
|
||||
|
||||
|
||||
async def gw_start(test_cli, *, etf=False):
|
||||
async def gw_start(test_cli, *, version: int = 6, etf=False):
|
||||
"""Start a websocket connection"""
|
||||
gw_url = await get_gw(test_cli)
|
||||
gw_url = await get_gw(test_cli, version)
|
||||
|
||||
if etf:
|
||||
gw_url = f"{gw_url}?encoding=etf"
|
||||
gw_url = f"{gw_url}?v={version}&encoding=etf"
|
||||
else:
|
||||
gw_url = f"{gw_url}?v={version}&encoding=json"
|
||||
|
||||
return await websockets.connect(gw_url)
|
||||
|
||||
|
|
@ -159,6 +161,29 @@ async def test_ready_fields(test_cli_user):
|
|||
await _close(conn)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ready_v9(test_cli_user):
|
||||
conn = await gw_start(test_cli_user.cli, version=9)
|
||||
await _json(conn)
|
||||
await _json_send(
|
||||
conn, {"op": OP.IDENTIFY, "d": {"token": test_cli_user.user["token"]}}
|
||||
)
|
||||
|
||||
try:
|
||||
ready = await _json(conn)
|
||||
assert isinstance(ready, dict)
|
||||
assert ready["op"] == OP.DISPATCH
|
||||
assert ready["t"] == "READY"
|
||||
|
||||
data = ready["d"]
|
||||
assert isinstance(data, dict)
|
||||
assert data["v"] == 9
|
||||
assert isinstance(data["user"], dict)
|
||||
assert isinstance(data["relationships"], list)
|
||||
finally:
|
||||
await _close(conn)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_heartbeat(test_cli_user):
|
||||
conn = await gw_start(test_cli_user.cli)
|
||||
|
|
|
|||
Loading…
Reference in New Issue