Finish writing _update_state
Add attributes
This commit is contained in:
parent
faaf2ecb39
commit
a90a615139
62
lib/room.py
62
lib/room.py
@ -1,16 +1,27 @@
|
||||
# TODO Add Room class
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Dict
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from .client import Client
|
||||
from .content import MRoomPowerLevelsContent
|
||||
from .events import StateEvent
|
||||
from .content import (
|
||||
MRoomPowerLevelsContent,
|
||||
MRoomAliasesContent,
|
||||
MRoomBotOptionsContent,
|
||||
MRoomCanonicalAliasContent,
|
||||
MRoomCreateContent,
|
||||
MRoomHistoryVisibilityContent,
|
||||
MRoomJoinRulesContent,
|
||||
MRoomNameContent,
|
||||
MRoomRelatedGroupsContent,
|
||||
MRoomTopicContent
|
||||
)
|
||||
from .utils import PreviousRoom
|
||||
|
||||
|
||||
class Room:
|
||||
def __init__(self, room_id: str, client: Client):
|
||||
def __init__(self, room_id: str, client):
|
||||
from .client import Client
|
||||
self.id = room_id
|
||||
self.client = client
|
||||
self.client: Client = client
|
||||
self.groups: Optional[List[str]] = None
|
||||
self.topic: str = ''
|
||||
self.join_rule: Optional[str] = None
|
||||
@ -23,9 +34,17 @@ class Room:
|
||||
self.avatar_url: str = ''
|
||||
self.canonical_alias: Optional[str] = None
|
||||
self.power_levels: Optional[MRoomPowerLevelsContent] = None
|
||||
self.bot_options: Optional[Dict[str, dict]] = None
|
||||
self.federated: bool = True
|
||||
self.predecessor: Optional[PreviousRoom] = None
|
||||
self.heroes: Optional[List[str]] = None
|
||||
self.joined_member_count: Optional[int] = None
|
||||
self.invited_member_count: Optional[int] = None
|
||||
|
||||
async def update_state(self, state_events: List[StateEvent] = None):
|
||||
if not state_events or any([state_event.room.id != self.id for state_event in state_events]):
|
||||
async def update_state(self, state_events: list = None):
|
||||
from .events import StateEvent
|
||||
|
||||
if not state_events or any([state_event.room_id != self.id for state_event in state_events]):
|
||||
path = self.client.api.build_url(f'rooms/{self.id}/state')
|
||||
state_events = await self.client.api.send('GET', path)
|
||||
|
||||
@ -35,5 +54,28 @@ class Room:
|
||||
|
||||
self._update_state(event)
|
||||
|
||||
def _update_state(self, event: StateEvent):
|
||||
pass
|
||||
def _update_state(self, event):
|
||||
content = event.content
|
||||
if isinstance(content, MRoomTopicContent):
|
||||
self.topic = content.topic
|
||||
elif isinstance(content, MRoomNameContent):
|
||||
self.name = content.name
|
||||
elif isinstance(content, MRoomRelatedGroupsContent):
|
||||
self.groups = content.groups
|
||||
elif isinstance(content, MRoomJoinRulesContent):
|
||||
self.join_rule = content.join_rule
|
||||
elif isinstance(content, MRoomHistoryVisibilityContent):
|
||||
self.history_visibility = content.history_visibility
|
||||
elif isinstance(content, MRoomCreateContent):
|
||||
self.creator = content.creator
|
||||
self.federated = content.m_federate
|
||||
self.version = content.room_version
|
||||
self.predecessor = content.predecessor
|
||||
elif isinstance(content, MRoomCanonicalAliasContent):
|
||||
self.canonical_alias = content.alias
|
||||
elif isinstance(content, MRoomAliasesContent):
|
||||
self.aliases = content.aliases
|
||||
elif isinstance(content, MRoomBotOptionsContent):
|
||||
self.bot_options = content.options
|
||||
elif isinstance(content, MRoomPowerLevelsContent):
|
||||
self.power_levels = content
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user