|
35 | 35 |
|
36 | 36 | from typing_extensions import Literal
|
37 | 37 |
|
38 |
| -import discord.abc |
| 38 | +from . import abc, utils |
39 | 39 | from .flags import PublicUserFlags
|
40 | 40 | from .utils import snowflake_time, _bytes_to_base64_data
|
41 | 41 | from .enums import DefaultAvatar, try_enum
|
|
52 | 52 | from .state import ConnectionState
|
53 | 53 |
|
54 | 54 |
|
55 |
| -_BaseUser = discord.abc.User |
| 55 | +_BaseUser = abc.User |
| 56 | +MISSING = utils.MISSING |
56 | 57 |
|
57 | 58 |
|
58 | 59 | class BaseUser(_BaseUser):
|
@@ -380,7 +381,11 @@ def _update(self, data: Dict[str, Any]) -> None:
|
380 | 381 | self._flags = data.get('flags', 0)
|
381 | 382 | self.mfa_enabled = data.get('mfa_enabled', False)
|
382 | 383 |
|
383 |
| - async def edit(self, **fields) -> None: |
| 384 | + async def edit( |
| 385 | + self, |
| 386 | + username: str = MISSING, |
| 387 | + avatar: bytes = MISSING |
| 388 | + ) -> None: |
384 | 389 | """|coro|
|
385 | 390 |
|
386 | 391 | Edits the current profile of the client.
|
@@ -410,28 +415,24 @@ async def edit(self, **fields) -> None:
|
410 | 415 | Wrong image format passed for ``avatar``.
|
411 | 416 | """
|
412 | 417 |
|
413 |
| - try: |
414 |
| - avatar_bytes = fields['avatar'] |
415 |
| - except KeyError: |
416 |
| - avatar = self.avatar |
417 |
| - else: |
418 |
| - if avatar_bytes is not None: |
419 |
| - avatar = _bytes_to_base64_data(avatar_bytes) |
| 418 | + payload = {} |
| 419 | + |
| 420 | + if username is not MISSING: |
| 421 | + payload['username'] = username |
| 422 | + |
| 423 | + if avatar is not MISSING: |
| 424 | + if avatar is None: |
| 425 | + payload['avatar'] = None |
420 | 426 | else:
|
421 |
| - avatar = None |
422 |
| - |
423 |
| - args = { |
424 |
| - 'username': fields.get('username', self.name), |
425 |
| - 'avatar': avatar |
426 |
| - } |
| 427 | + payload['avatar'] = _bytes_to_base64_data(avatar) |
427 | 428 |
|
428 | 429 | http = self._state.http
|
429 | 430 |
|
430 |
| - data = await http.edit_profile(**args) |
| 431 | + data = await http.edit_profile(payload) |
431 | 432 | self._update(data)
|
432 | 433 |
|
433 | 434 |
|
434 |
| -class User(BaseUser, discord.abc.Messageable): |
| 435 | +class User(BaseUser, abc.Messageable): |
435 | 436 | """Represents a Discord user.
|
436 | 437 |
|
437 | 438 | .. container:: operations
|
|
0 commit comments