Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions hikari/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
)

import http
import json
import typing

import attrs
import msgspec.json

from hikari.internal import attrs_extensions
from hikari.internal import data_binding
Expand Down Expand Up @@ -334,8 +334,7 @@ def __str__(self) -> str:
try:
value += _dump_errors(self.errors).strip("\n")
except KeyError:
# Use the stdlib json.dumps here to be able to indent
value += json.dumps(self.errors, indent=2)
value += msgspec.json.format(data_binding.default_json_dumps(self.errors), indent=2).decode()

self._cached_str = value
return value
Expand Down
15 changes: 0 additions & 15 deletions hikari/impl/gateway_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
from hikari.impl import shard as shard_impl
from hikari.impl import voice as voice_impl
from hikari.internal import aio
from hikari.internal import data_binding
from hikari.internal import signals
from hikari.internal import time
from hikari.internal import typing_extensions
Expand Down Expand Up @@ -234,10 +233,6 @@ class GatewayBot(traits.GatewayBotAware):
proxy_settings
Custom proxy settings to use with network-layer logic
in your application to get through an HTTP-proxy.
dumps
The JSON encoder this application should use.
loads
The JSON decoder this application should use.
rest_url
Defaults to the Discord REST API URL if [`None`][]. Can be
overridden if you are attempting to point to an unofficial endpoint, or
Expand Down Expand Up @@ -292,14 +287,12 @@ class GatewayBot(traits.GatewayBotAware):
"_cache",
"_closed_event",
"_closing_event",
"_dumps",
"_entity_factory",
"_event_factory",
"_event_manager",
"_executor",
"_http_settings",
"_intents",
"_loads",
"_proxy_settings",
"_rest",
"_shards",
Expand All @@ -319,8 +312,6 @@ def __init__(
force_color: bool = False,
cache_settings: config_impl.CacheSettings | None = None,
http_settings: config_impl.HTTPSettings | None = None,
dumps: data_binding.JSONEncoder = data_binding.default_json_dumps,
loads: data_binding.JSONDecoder = data_binding.default_json_loads,
intents: intents_.Intents = intents_.Intents.ALL_UNPRIVILEGED,
auto_chunk_members: bool = True,
logs: None | str | int | dict[str, typing.Any] | os.PathLike[str] = "INFO",
Expand All @@ -342,8 +333,6 @@ def __init__(
self._intents = intents
self._proxy_settings = proxy_settings if proxy_settings is not None else config_impl.ProxySettings()
self._token = token.strip()
self._dumps = dumps
self._loads = loads

# Caching
cache_settings = cache_settings if cache_settings is not None else config_impl.CacheSettings()
Expand Down Expand Up @@ -375,8 +364,6 @@ def __init__(
http_settings=self._http_settings,
max_rate_limit=max_rate_limit,
proxy_settings=self._proxy_settings,
dumps=dumps,
loads=loads,
rest_url=rest_url,
max_retries=max_retries,
token=token,
Expand Down Expand Up @@ -1301,8 +1288,6 @@ async def _start_one_shard(
event_manager=self._event_manager,
event_factory=self._event_factory,
intents=self._intents,
dumps=self._dumps,
loads=self._loads,
initial_activity=activity,
initial_is_afk=afk,
initial_idle_since=idle_since,
Expand Down
17 changes: 4 additions & 13 deletions hikari/impl/interaction_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import aiohttp
import aiohttp.web
import aiohttp.web_runner
import msgspec

from hikari import applications
from hikari import errors
Expand Down Expand Up @@ -199,10 +200,6 @@ class InteractionServer(interaction_server.InteractionServer):
----------
entity_factory
The entity factory instance this server should use.
dumps
The JSON encoder this server should use.
loads
The JSON decoder this server should use.
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
Expand All @@ -214,12 +211,10 @@ class InteractionServer(interaction_server.InteractionServer):
__slots__: typing.Sequence[str] = (
"_application_fetch_lock",
"_close_event",
"_dumps",
"_entity_factory",
"_executor",
"_is_closing",
"_listeners",
"_loads",
"_nacl",
"_public_key",
"_rest_client",
Expand All @@ -230,10 +225,8 @@ class InteractionServer(interaction_server.InteractionServer):
def __init__(
self,
*,
dumps: data_binding.JSONEncoder = data_binding.default_json_dumps,
entity_factory: entity_factory_api.EntityFactory,
executor: concurrent.futures.Executor | None = None,
loads: data_binding.JSONDecoder = data_binding.default_json_loads,
rest_client: rest_api.RESTClient,
public_key: bytes | None = None,
) -> None:
Expand All @@ -250,12 +243,10 @@ def __init__(
self._application_fetch_lock: asyncio.Lock | None = None
# Building asyncio.Event when there isn't a running loop may lead to runtime errors.
self._close_event: asyncio.Event | None = None
self._dumps = dumps
self._entity_factory = entity_factory
self._executor = executor
self._is_closing = False
self._listeners: dict[type[base_interactions.PartialInteraction], typing.Any] = {}
self._loads = loads
self._nacl = nacl
self._rest_client = rest_client
self._server: aiohttp.web_runner.AppRunner | None = None
Expand Down Expand Up @@ -441,11 +432,11 @@ async def on_interaction(self, body: bytes, signature: bytes, timestamp: bytes)
return _Response(_BAD_REQUEST_STATUS, b"Invalid request signature")

try:
payload = self._loads(body)
payload = data_binding.default_json_loads(body)
assert isinstance(payload, dict)
interaction_type = int(payload["type"])

except (ValueError, TypeError):
except (msgspec.DecodeError, TypeError):
_LOGGER.exception("Received a request with an invalid JSON body")
return _Response(_BAD_REQUEST_STATUS, b"Invalid JSON body")

Expand Down Expand Up @@ -493,7 +484,7 @@ async def on_interaction(self, body: bytes, signature: bytes, timestamp: bytes)
return _Response(_NO_CONTENT_STATUS)

raw_payload, files = result.build(self._entity_factory)
payload = self._dumps(raw_payload)
payload = data_binding.default_json_dumps(raw_payload)

except Exception as exc: # noqa: BLE001 - Blind except
asyncio.get_running_loop().call_exception_handler(
Expand Down
Loading
Loading