curious.core.gateway¶
Websocket gateway code.
Functions
open_websocket (token, url, *[, shard_id, …]) |
Opens a new connection to Discord. |
Classes
GatewayHandler (gw_state) |
Represents a gateway handler - something that is connected to Discord’s websocket and handles incoming events and parses them as appropriate. |
GatewayOp |
Represents the opcode mapping for the gateway. |
HeartbeatStats ([heartbeats, heartbeat_acks, …]) |
Represents the statistics for the gateway’s heartbeat counters. |
-
class
curious.core.gateway.
GatewayHandler
(gw_state: curious.core.gateway._GatewayState)[source]¶ Bases:
object
Represents a gateway handler - something that is connected to Discord’s websocket and handles incoming events and parses them as appropriate.
You don’t want to create this class directly; use
open_gateway()
instead.async with open_gateway("wss://gateway.discord.gg", token="token", shard_id=0, shard_count=1) as gateway: async for event in gateway.events(): ...
-
await
_start_heatbeat_events
(heartbeat_interval)[source]¶ Starts heartbeating.
Parameters: heartbeat_interval ( float
) – The number of seconds between each heartbeat.
-
await
close
(code=1000, reason='Client closed connection', *, reconnect=False, clear_session_id=True)[source]¶ Close the current websocket connection.
Parameters:
-
async for ... in
events
()[source]¶ Returns an async generator used to iterate over the events received by this websocket.
Return type: AsyncGenerator
[None
,Any
]
-
await
open
()[source]¶ Opens a new connection to Discord.
Warning
This only opens the websocket.
Return type: None
-
await
send_guild_chunks
(guild_ids)[source]¶ Sends GUILD_MEMBER_CHUNK packets to Discord.
Return type: None
-
await
send_resume
()[source]¶ Sends a RESUME to Discord, attempting to resume the connection from where we left off.
Return type: None
-
await
-
class
curious.core.gateway.
GatewayOp
[source]¶ Bases:
enum.IntEnum
Represents the opcode mapping for the gateway.
-
class
curious.core.gateway.
HeartbeatStats
(heartbeats=0, heartbeat_acks=0, last_heartbeat_time=0, last_ack_time=0)[source]¶ Bases:
object
Represents the statistics for the gateway’s heartbeat counters.
-
class
curious.core.gateway.
_GatewayState
(token, gateway_url, shard_id, shard_count, session_id=None, sequence=0)[source]¶ Bases:
object
Represents the gateway state for the current gateway.
-
async with
curious.core.gateway.
open_websocket
(token, url, *, shard_id=0, shard_count=1)[source]¶ Opens a new connection to Discord.
This is an async context manager; for example, using Trio for nursery management:
async with trio.open_nursery() as nursery: async with open_websocket(token, url, task_group=nursery) as gateway: # example for changing presence nursery.start_soon(some_gw_handler, gateway) async for event in gateway.events(): # handle events, etc. ...
Parameters: Return type: Returns: An async context manager that yields a
GatewayHandler
.