mirror of https://gitlab.com/litecord/litecord.git
gateway.websocket: add GatewayWebsocket.send_op
This commit is contained in:
parent
800da730df
commit
bf8eca95b1
|
|
@ -139,6 +139,16 @@ class GatewayWebsocket:
|
||||||
else:
|
else:
|
||||||
await self.ws.send(encoded.decode())
|
await self.ws.send(encoded.decode())
|
||||||
|
|
||||||
|
async def send_op(self, op_code: int, data: Any):
|
||||||
|
"""Send a packet but just the OP code information is filled in."""
|
||||||
|
await self.send({
|
||||||
|
'op': op_code,
|
||||||
|
'd': data,
|
||||||
|
|
||||||
|
't': None,
|
||||||
|
's': None
|
||||||
|
})
|
||||||
|
|
||||||
def _check_ratelimit(self, key: str, ratelimit_key: str):
|
def _check_ratelimit(self, key: str, ratelimit_key: str):
|
||||||
ratelimit = self.ext.ratelimiter.get_ratelimit(f'_ws.{key}')
|
ratelimit = self.ext.ratelimiter.get_ratelimit(f'_ws.{key}')
|
||||||
bucket = ratelimit.get_bucket(ratelimit_key)
|
bucket = ratelimit.get_bucket(ratelimit_key)
|
||||||
|
|
@ -169,14 +179,11 @@ class GatewayWebsocket:
|
||||||
# random heartbeat intervals
|
# random heartbeat intervals
|
||||||
interval = randint(40, 46) * 1000
|
interval = randint(40, 46) * 1000
|
||||||
|
|
||||||
await self.send({
|
await self.send_op(OP.HELLO, {
|
||||||
'op': OP.HELLO,
|
|
||||||
'd': {
|
|
||||||
'heartbeat_interval': interval,
|
'heartbeat_interval': interval,
|
||||||
'_trace': [
|
'_trace': [
|
||||||
'lesbian-server'
|
'lesbian-server'
|
||||||
],
|
],
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
self._hb_start(interval)
|
self._hb_start(interval)
|
||||||
|
|
@ -416,9 +423,7 @@ class GatewayWebsocket:
|
||||||
self._hb_start((46 + 3) * 1000)
|
self._hb_start((46 + 3) * 1000)
|
||||||
cliseq = payload.get('d')
|
cliseq = payload.get('d')
|
||||||
self.state.last_seq = cliseq
|
self.state.last_seq = cliseq
|
||||||
await self.send({
|
await self.send_op(OP.HEARTBEAT_ACK, None)
|
||||||
'op': OP.HEARTBEAT_ACK,
|
|
||||||
})
|
|
||||||
|
|
||||||
async def _connect_ratelimit(self, user_id: int):
|
async def _connect_ratelimit(self, user_id: int):
|
||||||
if self._check_ratelimit('connect', user_id):
|
if self._check_ratelimit('connect', user_id):
|
||||||
|
|
@ -512,10 +517,7 @@ class GatewayWebsocket:
|
||||||
async def invalidate_session(self, resumable: bool = True):
|
async def invalidate_session(self, resumable: bool = True):
|
||||||
"""Invalidate the current session and signal that
|
"""Invalidate the current session and signal that
|
||||||
to the client."""
|
to the client."""
|
||||||
await self.send({
|
await self.send_op(OP.INVALID_SESSION, resumable)
|
||||||
'op': OP.INVALID_SESSION,
|
|
||||||
'd': resumable,
|
|
||||||
})
|
|
||||||
|
|
||||||
if not resumable and self.state:
|
if not resumable and self.state:
|
||||||
# since the state will be removed from
|
# since the state will be removed from
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue