Browse Source

Rework User.edit to have proper typing

pull/7139/head
Rapptz 4 years ago
parent
commit
6f3b8072d6
  1. 8
      discord/http.py
  2. 15
      discord/user.py

8
discord/http.py

@ -735,13 +735,7 @@ class HTTPClient:
return self.request(r, json=payload, reason=reason)
def edit_profile(self, username: Optional[str], avatar: Optional[bytes]) -> Response[user.User]:
payload = {}
if avatar is not None:
payload['avatar'] = avatar
if username is not None:
payload['username'] = username
def edit_profile(self, payload: Dict[str, Any]) -> Response[user.User]:
return self.request(Route('PATCH', '/users/@me'), json=payload)
def change_my_nickname(

15
discord/user.py

@ -22,10 +22,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import Optional, TYPE_CHECKING
from typing import Any, Dict, Optional, TYPE_CHECKING
import discord.abc
from .flags import PublicUserFlags
from .utils import snowflake_time, _bytes_to_base64_data
from .utils import snowflake_time, _bytes_to_base64_data, MISSING
from .enums import DefaultAvatar
from .colour import Colour
from .asset import Asset
@ -247,7 +247,7 @@ class ClientUser(BaseUser):
self._flags = data.get('flags', 0)
self.mfa_enabled = data.get('mfa_enabled', False)
async def edit(self, *, username: str = None, avatar: Optional[bytes] = None) -> None:
async def edit(self, *, username: str = MISSING, avatar: bytes = MISSING) -> None:
"""|coro|
Edits the current profile of the client.
@ -276,11 +276,14 @@ class ClientUser(BaseUser):
InvalidArgument
Wrong image format passed for ``avatar``.
"""
payload: Dict[str, Any] = {}
if username is not MISSING:
payload['username'] = username
if avatar is not None:
avatar = _bytes_to_base64_data(avatar)
if avatar is not MISSING:
payload['avatar'] = _bytes_to_base64_data(avatar)
data = await self._state.http.edit_profile(username=username, avatar=avatar)
data = await self._state.http.edit_profile(payload)
self._update(data)

Loading…
Cancel
Save