Skip to content

hikari.impl.interaction_server#

Standard implementation of a REST based interactions server.

InteractionServer #

InteractionServer(*, dumps: JSONEncoder = data_binding.default_json_dumps, entity_factory: EntityFactory, executor: Optional[Executor] = None, loads: JSONDecoder = data_binding.default_json_loads, rest_client: RESTClient, public_key: Optional[bytes] = None)

Bases: InteractionServer

Standard implementation of hikari.api.interaction_server.InteractionServer.

PARAMETER DESCRIPTION
entity_factory

The entity factory instance this server should use.

TYPE: EntityFactory

dumps

The JSON encoder this server should use.

TYPE: JSONEncoder DEFAULT: default_json_dumps

loads

The JSON decoder this server should use.

TYPE: JSONDecoder DEFAULT: default_json_loads

public_key

The public key this server should use for verifying request payloads from Discord. If left as None then the client will try to work this out using rest_client.

TYPE: Optional[bytes] DEFAULT: None

rest_client

The client this should use for making REST requests.

TYPE: RESTClient

is_alive property #

is_alive: bool

Whether this interaction server is active.

aiohttp_hook async #

aiohttp_hook(request: Request) -> Response

Handle an AIOHTTP interaction request.

This method handles aiohttp specific detail before calling hikari.impl.interaction_server.InteractionServer.on_interaction with the data extracted from the request if it can and handles building an aiohttp response.

PARAMETER DESCRIPTION
request

The received request.

TYPE: Request

RETURNS DESCRIPTION
Response

The aiohttp response.

close async #

close() -> None

Gracefully close the server and any open connections.

get_listener #

get_listener(interaction_type: type[_InteractionT_co]) -> Optional[ListenerT[_InteractionT_co, InteractionResponseBuilder]]

Get the listener registered for an interaction.

PARAMETER DESCRIPTION
interaction_type

Type of the interaction to get the registered listener for.

TYPE: type[_InteractionT_co]

RETURNS DESCRIPTION
typing.Optional[ListenersT[hikari.interactions.base_interactions.PartialInteraction, hikari.api.special_endpoints.InteractionResponseBuilder]

The callback registered for the provided interaction type if found, else None.

join async #

join() -> None

Wait for the process to halt before continuing.

on_interaction async #

on_interaction(body: bytes, signature: bytes, timestamp: bytes) -> Response

Handle an interaction received from Discord as a REST server.

Note

If this server instance is alive then this will be called internally by the server but if the instance isn't alive then this may still be called externally to trigger interaction dispatch.

PARAMETER DESCRIPTION
body

The interaction payload.

TYPE: bytes

signature

Value of the "X-Signature-Ed25519" header used to verify the body.

TYPE: bytes

timestamp

Value of the "X-Signature-Timestamp" header used to verify the body.

TYPE: bytes

RETURNS DESCRIPTION
Response

Instructions on how the REST server calling this should respond to the interaction request.

set_listener #

set_listener(interaction_type: type[_InteractionT_co], listener: Optional[ListenerT[_InteractionT_co, InteractionResponseBuilder]], /, *, replace: bool = False) -> None

Set the listener callback for this interaction server.

PARAMETER DESCRIPTION
interaction_type

The type of interaction this listener should be registered for.

TYPE: type[_InteractionT_co]

listener

The asynchronous listener callback to set or None to unset the previous listener.

An asynchronous listener can be either a normal coroutine or an async generator which should yield exactly once. This allows sending an initial response to the request, while still later executing further logic.

TYPE: Optional[ListenerT[_InteractionT_co, InteractionResponseBuilder]]

replace

Whether this call should replace the previously set listener or not.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
TypeError

If replace is False when a listener is already set.

start async #

start(backlog: int = 128, host: Optional[Union[str, Sequence[str]]] = None, port: Optional[int] = None, path: Optional[str] = None, reuse_address: Optional[bool] = None, reuse_port: Optional[bool] = None, socket: Optional[socket] = None, shutdown_timeout: float = 60.0, ssl_context: Optional[SSLContext] = None) -> None

Start the bot and wait for the internal server to startup then return.

Note

For more information on the other parameters such as defaults see AIOHTTP's documentation.

PARAMETER DESCRIPTION
backlog

The number of unaccepted connections that the system will allow before refusing new connections.

TYPE: int DEFAULT: 128

host

TCP/IP host or a sequence of hosts for the HTTP server.

TYPE: Optional[Union[str, Sequence[str]]] DEFAULT: None

port

TCP/IP port for the HTTP server.

TYPE: Optional[int] DEFAULT: None

path

File system path for HTTP server unix domain socket.

TYPE: Optional[str] DEFAULT: None

reuse_address

Tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire.

TYPE: Optional[bool] DEFAULT: None

reuse_port

Tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are also bound to.

TYPE: Optional[bool] DEFAULT: None

socket

A pre-existing socket object to accept connections on.

TYPE: Optional[socket] DEFAULT: None

shutdown_timeout

A delay to wait, in seconds, for graceful server shutdown before forcefully disconnecting all open client sockets.

TYPE: float DEFAULT: 60.0

ssl_context

SSL context for HTTPS servers.

TYPE: Optional[SSLContext] DEFAULT: None