From 16177e6698bc69e27e60cfd558689749f3abcc0e Mon Sep 17 00:00:00 2001 From: Zomatree Date: Mon, 14 Feb 2022 05:51:46 +0000 Subject: [PATCH] fix missing inconsistancies --- revolt/channel.py | 14 ++++++++++++-- revolt/permissions.py | 2 +- revolt/user.py | 6 +++++- revolt/websocket.py | 24 +++++++++++++++--------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/revolt/channel.py b/revolt/channel.py index 3d98c59..782e942 100755 --- a/revolt/channel.py +++ b/revolt/channel.py @@ -99,15 +99,18 @@ class GroupDMChannel(Channel, Messageable, EditableChannel): The icon of the group dm channel permissions: :class:`ChannelPermissions` The permissions of the users inside the group dm channel + description: Optional[:class:`str`] + The description of the channel, if any """ - __slots__ = ("recipients", "name", "owner", "permissions", "icon") + __slots__ = ("recipients", "name", "owner", "permissions", "icon", "description") def __init__(self, data: GroupDMChannelPayload, state: State): super().__init__(data, state) self.recipients = [state.get_user(user_id) for user_id in data["recipients"]] self.name = data["name"] self.owner = state.get_user(data["owner"]) + self.description = data.get("description") if icon := data.get("icon"): self.icon = Asset(icon, state) @@ -119,13 +122,16 @@ class GroupDMChannel(Channel, Messageable, EditableChannel): else: self.permissions = ChannelPermissions._from_value(0) - def _update(self, *, name: Optional[str] = None, recipients: Optional[list[str]] = None): + def _update(self, *, name: Optional[str] = None, recipients: Optional[list[str]] = None, description: Optional[str] = None): if name: self.name = name if recipients: self.recipients = [self.state.get_user(user_id) for user_id in recipients] + if description: + self.description = description + async def set_default_permissions(self, permissions: ChannelPermissions) -> None: """Sets the default permissions for a group. Parameters @@ -154,6 +160,8 @@ class TextChannel(Channel, Messageable, EditableChannel): A dictionary of role id's to the permissions of that role in the text channel icon: Optional[:class:`Asset`] The icon of the text channel, if any + description: Optional[:class:`str`] + The description of the channel, if any """ def __init__(self, data: TextChannelPayload, state: State): super().__init__(data, state) @@ -232,6 +240,8 @@ class VoiceChannel(Channel, EditableChannel): A dictionary of role id's to the permissions of that role in the voice channel icon: Optional[:class:`Asset`] The icon of the voice channel, if any + description: Optional[:class:`str`] + The description of the channel, if any """ def __init__(self, data: VoiceChannelPayload, state: State): super().__init__(data, state) diff --git a/revolt/permissions.py b/revolt/permissions.py index c772870..8c009fc 100755 --- a/revolt/permissions.py +++ b/revolt/permissions.py @@ -42,7 +42,7 @@ class ChannelPermissions(Flags): @classmethod def all(cls) -> ChannelPermissions: - return cls._from_value(0b11111011) + return cls._from_value(0b11111111) @classmethod def view(cls) -> ChannelPermissions: diff --git a/revolt/user.py b/revolt/user.py index dd15793..4bcdef7 100755 --- a/revolt/user.py +++ b/revolt/user.py @@ -166,6 +166,9 @@ class User(Messageable): :class:`UserProfile` The user's profile """ + if profile := self.profile: + return profile + payload = await self.state.http.fetch_profile(self.id) if file := payload.get("background"): @@ -173,4 +176,5 @@ class User(Messageable): else: background = None - return UserProfile(payload.get("content"), background) + self.profile = UserProfile(payload.get("content"), background) + return self.profile diff --git a/revolt/websocket.py b/revolt/websocket.py index 278c9e0..739afec 100755 --- a/revolt/websocket.py +++ b/revolt/websocket.py @@ -6,9 +6,6 @@ from copy import copy from typing import TYPE_CHECKING, Callable, cast from .enums import RelationshipType -from .types import (ChannelCreateEventPayload, ChannelDeleteEventPayload, - ChannelDeleteTypingEventPayload, - ChannelStartTypingEventPayload, ChannelUpdateEventPayload) from .types import Message as MessagePayload from .types import (MessageDeleteEventPayload, MessageUpdateEventPayload, ServerDeleteEventPayload, ServerMemberJoinEventPayload, @@ -16,8 +13,11 @@ from .types import (MessageDeleteEventPayload, MessageUpdateEventPayload, ServerMemberUpdateEventPayload, ServerRoleDeleteEventPayload, ServerRoleUpdateEventPayload, ServerUpdateEventPayload, UserRelationshipEventPayload, - UserUpdateEventPayload) -from .user import Status + UserUpdateEventPayload, ChannelCreateEventPayload, ChannelDeleteEventPayload, + ChannelDeleteTypingEventPayload, + ChannelStartTypingEventPayload, ChannelUpdateEventPayload) +from .user import Status, UserProfile +from .channel import TextChannel, GroupDMChannel, VoiceChannel try: import ujson as json @@ -163,10 +163,12 @@ class WebsocketHandler: if clear := payload.get("clear"): if clear == "Icon": - pass # TODO + if isinstance(channel, (TextChannel, VoiceChannel, GroupDMChannel)): + channel.icon = None elif clear == "Description": - channel.description = None # type: ignore + if isinstance(channel, (TextChannel, VoiceChannel, GroupDMChannel)): + channel.description = None self.dispatch("channel_update", old_channel, channel) @@ -263,9 +265,13 @@ class WebsocketHandler: if clear := payload.get("clear"): if clear == "ProfileContent": - ... + if profile := user.profile: + user.profile = UserProfile(None, profile.background) + elif clear == "ProfileBackground": - ... + if profile := user.profile: + user.profile = UserProfile(profile.content, None) + elif clear == "StatusText": # user.status will never be none because they are trying to remove the text if user.status.presence is None: # type: ignore