Gateway¶
Internal API
These classes are for internal use only.
Users should interact with Client and other public API classes instead.
Client¶
gateway
¶
logger = logging.getLogger('scurrypy.gateway')
module-attribute
¶
MIN_BACKOFF = 5
module-attribute
¶
EventQueueProtocol
¶
Bases: Protocol
flowchart TD
scurrypy.core.gateway.EventQueueProtocol[EventQueueProtocol]
click scurrypy.core.gateway.EventQueueProtocol href "" "scurrypy.core.gateway.EventQueueProtocol"
Internal contract for the GatewayClient's event queue used by the Client. Meant for testing.
GatewayClientProtocol
¶
Bases: Protocol
flowchart TD
scurrypy.core.gateway.GatewayClientProtocol[GatewayClientProtocol]
click scurrypy.core.gateway.GatewayClientProtocol href "" "scurrypy.core.gateway.GatewayClientProtocol"
Internal contract for the GatewayClient used by the Client. Meant for testing.
GatewayClient
¶
Bases: GatewayClientProtocol
flowchart TD
scurrypy.core.gateway.GatewayClient[GatewayClient]
scurrypy.core.gateway.GatewayClientProtocol[GatewayClientProtocol]
scurrypy.core.gateway.GatewayClientProtocol --> scurrypy.core.gateway.GatewayClient
click scurrypy.core.gateway.GatewayClient href "" "scurrypy.core.gateway.GatewayClient"
click scurrypy.core.gateway.GatewayClientProtocol href "" "scurrypy.core.gateway.GatewayClientProtocol"
shard_id: int = 0
instance-attribute
¶
total_shards: int = 0
instance-attribute
¶
seq: int | None = None
instance-attribute
¶
session_id: str | None = None
instance-attribute
¶
allow_resume: bool = False
instance-attribute
¶
reconnect_immediately: bool = False
instance-attribute
¶
backoff: int = MIN_BACKOFF
instance-attribute
¶
metrics: GatewayMetrics = GatewayMetrics(0.0, 0.0)
instance-attribute
¶
heartbeat_task: asyncio.Task[Any] | None = None
instance-attribute
¶
heartbeat_interval: int = 0
instance-attribute
¶
event_queue: asyncio.Queue[tuple[str, JSON]] = asyncio.Queue()
instance-attribute
¶
base_url = 'wss://gateway.discord.gg'
instance-attribute
¶
url_params = '?v=10&encoding=json'
instance-attribute
¶
ws: websockets.ClientConnection
property
¶
wait_reconnect
async
¶
Sleep for exponentially increasing time between reconnects.
start
async
¶
Start this websocket's connection.
Parameters:
-
token(str) –the bot's token
-
intents(int) –the bot's intents
connect_ws
async
¶
Connect to Discord's Gateway (websocket).
send
async
¶
Send data through the websocket.
Parameters:
-
data(dict) –data to send
receive
async
¶
Receive data through the websocket.
Returns:
-
dict–websocket data
heartbeat
async
¶
Heartbeat task to keep connection alive.
identify
async
¶
Send an IDENTIFY payload to handshake for bot.
Parameters:
-
token(str) –the bot's token
-
intents(int) –the bot's intents
Raises:
-
ConnectionError–invalid intents
resume
async
¶
Send a RESUME payload to resume a connection.
Parameters:
-
token(str) –the bot's token
close_ws
async
¶
Close the websocket connection if one is still open and cancels heartbeat.
Events¶
gateway_events
¶
SessionStartLimit
dataclass
¶
flowchart TD
scurrypy.events.gateway_events.SessionStartLimit[SessionStartLimit]
scurrypy.events.base_event.Event[Event]
scurrypy.core.model.DataModel[DataModel]
scurrypy.events.base_event.Event --> scurrypy.events.gateway_events.SessionStartLimit
scurrypy.core.model.DataModel --> scurrypy.events.base_event.Event
scurrypy.core.model.DataModel --> scurrypy.events.gateway_events.SessionStartLimit
click scurrypy.events.gateway_events.SessionStartLimit href "" "scurrypy.events.gateway_events.SessionStartLimit"
click scurrypy.events.base_event.Event href "" "scurrypy.events.base_event.Event"
click scurrypy.core.model.DataModel href "" "scurrypy.core.model.DataModel"
Represents the Session Start Limit object.
GatewayEvent
dataclass
¶
flowchart TD
scurrypy.events.gateway_events.GatewayEvent[GatewayEvent]
scurrypy.events.base_event.Event[Event]
scurrypy.core.model.DataModel[DataModel]
scurrypy.events.base_event.Event --> scurrypy.events.gateway_events.GatewayEvent
scurrypy.core.model.DataModel --> scurrypy.events.base_event.Event
scurrypy.core.model.DataModel --> scurrypy.events.gateway_events.GatewayEvent
click scurrypy.events.gateway_events.GatewayEvent href "" "scurrypy.events.gateway_events.GatewayEvent"
click scurrypy.events.base_event.Event href "" "scurrypy.events.base_event.Event"
click scurrypy.core.model.DataModel href "" "scurrypy.core.model.DataModel"
Represents the Gateway Event object.