Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat: serialise any naff-objects passed in request payloads (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
LordOfPolls authored Sep 23, 2022
1 parent 4dd840f commit 4277624
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion naff/api/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from weakref import WeakValueDictionary

import aiohttp
import discord_typings
from aiohttp import BaseConnector, ClientSession, ClientWebSocketResponse, FormData
from multidict import CIMultiDictProxy

Expand Down Expand Up @@ -32,12 +33,12 @@
__api_version__,
)
from naff.client.errors import DiscordError, Forbidden, GatewayNotFound, HTTPException, NotFound, LoginError
from naff.client.mixins.serialization import DictSerializationMixin
from naff.client.utils.input_utils import response_decode, OverriddenJson
from naff.client.utils.serializer import dict_filter
from naff.models import CooldownSystem
from naff.models.discord.file import UPLOADABLE_TYPE
from .route import Route
import discord_typings

__all__ = ("HTTPClient",)

Expand Down Expand Up @@ -213,6 +214,13 @@ def _process_payload(

if isinstance(payload, dict):
payload = dict_filter(payload)

for k, v in payload.items():
if isinstance(v, DictSerializationMixin):
payload[k] = v.to_dict()
if isinstance(v, (list, tuple, set)):
payload[k] = [i.to_dict() if isinstance(i, DictSerializationMixin) else i for i in v]

else:
payload = [dict_filter(x) if isinstance(x, dict) else x for x in payload]

Expand Down

0 comments on commit 4277624

Please sign in to comment.