mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
Added hypesquad house functionality
This commit is contained in:
parent
dace5aeaee
commit
ee57e89488
@ -29,7 +29,7 @@ from enum import Enum, IntEnum
|
||||
__all__ = ['ChannelType', 'MessageType', 'VoiceRegion', 'VerificationLevel',
|
||||
'ContentFilter', 'Status', 'DefaultAvatar', 'RelationshipType',
|
||||
'AuditLogAction', 'AuditLogActionCategory', 'UserFlags',
|
||||
'ActivityType', ]
|
||||
'ActivityType', 'HypeSquadHouse']
|
||||
|
||||
class ChannelType(Enum):
|
||||
text = 0
|
||||
@ -214,6 +214,9 @@ class UserFlags(Enum):
|
||||
staff = 1
|
||||
partner = 2
|
||||
hypesquad = 4
|
||||
hypesquad_bravery = 64
|
||||
hypesquad_brilliance = 128
|
||||
hypesquad_balance = 256
|
||||
|
||||
class ActivityType(IntEnum):
|
||||
unknown = -1
|
||||
@ -222,6 +225,10 @@ class ActivityType(IntEnum):
|
||||
listening = 2
|
||||
watching = 3
|
||||
|
||||
class HypeSquadHouse(Enum):
|
||||
bravery = 1
|
||||
brilliance = 2
|
||||
balance = 3
|
||||
|
||||
def try_enum(cls, val):
|
||||
"""A function that tries to turn the value into enum ``cls``.
|
||||
|
@ -766,3 +766,10 @@ class HTTPClient:
|
||||
|
||||
def get_user_profile(self, user_id):
|
||||
return self.request(Route('GET', '/users/{user_id}/profile', user_id=user_id))
|
||||
|
||||
def change_hypesquad_house(self, house_id):
|
||||
payload = {'house_id': house_id}
|
||||
return self.request(Route('POST', '/hypesquad/online'), json=payload)
|
||||
|
||||
def leave_hypesquad_house(self):
|
||||
return self.request(Route('DELETE', '/hypesquad/online'))
|
||||
|
@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from .utils import snowflake_time, _bytes_to_base64_data, parse_time, valid_icon_size
|
||||
from .enums import DefaultAvatar, RelationshipType, UserFlags
|
||||
from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse
|
||||
from .errors import ClientException, InvalidArgument
|
||||
|
||||
from collections import namedtuple
|
||||
@ -60,6 +60,10 @@ class Profile(namedtuple('Profile', 'flags user mutual_guilds connected_accounts
|
||||
def partner(self):
|
||||
return self._has_flag(UserFlags.partner)
|
||||
|
||||
@property
|
||||
def hypesquad_houses(self):
|
||||
flags = (UserFlags.hypesquad_bravery, UserFlags.hypesquad_brilliance, UserFlags.hypesquad_balance)
|
||||
return [house for house, flag in zip(HypeSquadHouse, flags) if self._has_flag(flag)]
|
||||
|
||||
_BaseUser = discord.abc.User
|
||||
|
||||
@ -337,6 +341,10 @@ class ClientUser(BaseUser):
|
||||
email: str
|
||||
The new email you wish to change to.
|
||||
Only applicable to user accounts.
|
||||
Optional[:class:`HypeSquadHouse`]
|
||||
The hypesquad house you wish to change to.
|
||||
Could be ``None`` to leave the current house.
|
||||
Only applicable to user accounts.
|
||||
username :str
|
||||
The new username you wish to change to.
|
||||
avatar: bytes
|
||||
@ -351,6 +359,7 @@ class ClientUser(BaseUser):
|
||||
Wrong image format passed for ``avatar``.
|
||||
ClientException
|
||||
Password is required for non-bot accounts.
|
||||
House field was not a HypeSquadHouse.
|
||||
"""
|
||||
|
||||
try:
|
||||
@ -382,6 +391,17 @@ class ClientUser(BaseUser):
|
||||
|
||||
http = self._state.http
|
||||
|
||||
if 'house' in fields:
|
||||
house = fields['house']
|
||||
if house is None:
|
||||
await http.leave_hypesquad_house()
|
||||
elif not isinstance(house, HypeSquadHouse):
|
||||
raise ClientException('`house` parameter was not a HypeSquadHouse')
|
||||
else:
|
||||
value = house.value
|
||||
|
||||
await http.change_hypesquad_house(value)
|
||||
|
||||
data = await http.edit_profile(**args)
|
||||
if not_bot_account:
|
||||
self.email = data['email']
|
||||
|
Loading…
x
Reference in New Issue
Block a user