hikari.impl.interaction_server#
Standard implementation of a REST based interactions server.
Module Contents#
- class hikari.impl.interaction_server.InteractionServer(*, dumps=data_binding.default_json_dumps, entity_factory, executor=None, loads=data_binding.default_json_loads, rest_client, public_key=None)[source]#
Bases:
hikari.api.interaction_server.InteractionServer
Standard implementation of
hikari.api.interaction_server.InteractionServer
.- Parameters:
- entity_factory
hikari.api.entity_factory.EntityFactory
The entity factory instance this server should use.
- entity_factory
- Other Parameters:
- dumps
hikari.internal.data_binding.JSONEncoder
The JSON encoder this server should use. Defaults to
hikari.internal.data_binding.default_json_dumps
.- loads
hikari.internal.data_binding.JSONDecoder
The JSON decoder this server should use. Defaults to
hikari.internal.data_binding.default_json_loads
.- public_key
bytes
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 usingrest_client
.- rest_client
hikari.api.rest.RESTClient
The client this should use for making REST requests.
- dumps
- async aiohttp_hook(request)[source]#
Handle an AIOHTTP interaction request.
This method handles aiohttp specific detail before calling
InteractionServer.on_interaction
with the data extracted from the request if it can and handles building an aiohttp response.- Parameters:
- request
aiohttp.web.Request
The received request.
- request
- Returns:
aiohttp.web.Response
The aiohttp response.
- get_listener(interaction_type, /)[source]#
- get_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], /) hikari.api.interaction_server.ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilderT] | None
- get_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], /) hikari.api.interaction_server.ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder] | None
- get_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], /) hikari.api.interaction_server.ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT] | None
- get_listener(interaction_type: Type[_InteractionT_co], /) hikari.api.interaction_server.ListenerT[_InteractionT_co, hikari.api.special_endpoints.InteractionResponseBuilder] | None
Get the listener registered for an interaction.
- Parameters:
- interaction_type
typing.Type
[hikari.interactions.base_interactions.PartialInteraction
] Type of the interaction to get the registered listener for.
- interaction_type
- Returns:
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
.
- async on_interaction(body, signature, timestamp)[source]#
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.
- Parameters:
- Returns:
hikari.api.interaction_server.Response
Instructions on how the REST server calling this should respond to the interaction request.
- set_listener(interaction_type, listener, /, *, replace=False)[source]#
- set_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], listener: hikari.api.interaction_server.ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilderT] | None, /, *, replace: bool = False) None
- set_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], listener: hikari.api.interaction_server.ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder] | None, /, *, replace: bool = False) None
- set_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], listener: hikari.api.interaction_server.ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT] | None, /, *, replace: bool = False) None
Set the listener callback for this interaction server.
- Parameters:
- interaction_type
typing.Type
[hikari.interactions.base_interactions.PartialInteraction
] The type of interaction this listener should be registered for.
- listener
typing.Optional
[ListenerT
[hikari.interactions.base_interactions.PartialInteraction
,hikari.api.special_endpoints.InteractionResponseBuilder
]] 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.
- interaction_type
- Other Parameters:
- replacebool
Whether this call should replace the previously set listener or not. This call will raise a
ValueError
if set toFalse
when a listener is already set.
- Raises:
- async start(backlog=128, host=None, port=None, path=None, reuse_address=None, reuse_port=None, socket=None, shutdown_timeout=60.0, ssl_context=None)[source]#
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.
- Other Parameters:
- backlog
int
The number of unaccepted connections that the system will allow before refusing new connections.
- host
typing.Optional
[typing.Union
[str
,aiohttp.web.HostSequence
]] TCP/IP host or a sequence of hosts for the HTTP server.
- port
typing.Optional
[int
] TCP/IP port for the HTTP server.
- path
typing.Optional
[str
] File system path for HTTP server unix domain socket.
- reuse_address
typing.Optional
[bool] Tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire.
- reuse_port
typing.Optional
[bool] Tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are also bound to.
- socket
typing.Optional
[socket.socket
] A pre-existing socket object to accept connections on.
- shutdown_timeout
float
A delay to wait for graceful server shutdown before forcefully disconnecting all open client sockets. This defaults to 60 seconds.
- ssl_context
typing.Optional
[ssl.SSLContext
] SSL context for HTTPS servers.
- backlog