fix missing inconsistancies

This commit is contained in:
Zomatree
2022-02-14 05:51:46 +00:00
parent 40e9e3a26e
commit 16177e6698
4 changed files with 33 additions and 13 deletions
+12 -2
View File
@@ -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)
+1 -1
View File
@@ -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:
+5 -1
View File
@@ -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
+15 -9
View File
@@ -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