diff --git a/src/wechaty/user/contact.py b/src/wechaty/user/contact.py index abd485c9..9635dd0f 100644 --- a/src/wechaty/user/contact.py +++ b/src/wechaty/user/contact.py @@ -62,7 +62,7 @@ # pytype: disable=pyi-error from .url_link import UrlLink from .mini_program import MiniProgram - + log = get_logger('Contact') @@ -190,7 +190,7 @@ async def find(cls, Args: query: the query body to build filter - + Examples: >>> # 1. find contacts based query string, will match one of: contact_id, weixin, name and alias >>> # what's more, contact_id and weixin will follow extract match, name and alias will follow fuzzy match @@ -319,7 +319,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini Args: message: the message object to be sended to contact - + Examples: >>> contact = Contact.load('contact-id') >>> await contact.say('hello') @@ -331,7 +331,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini >>> await contact.say(MiniProgram('username', 'appid')) Returns: - Message: if the message is send successfully, return the message object, otherwise return None + Message: if the message is send successfully, return the message object, otherwise return None """ if not message: log.error('can"t say nothing') @@ -360,7 +360,7 @@ async def say(self, message: Union[str, Message, FileBox, Contact, UrlLink, Mini conversation_id=self.contact_id, file=message ) - + return None elif isinstance(message, UrlLink): # use this way to resolve circulation dependency import msg_id = await self.puppet.message_send_url( @@ -390,7 +390,7 @@ def name(self) -> str: Examples: >>> contact = Contact.load('contact-id') >>> name: str = contact.name - + Returns: str: name of contact, if the payload is None, return empty string """ @@ -403,7 +403,7 @@ async def alias(self, ) -> Union[None, str]: """ Get or set alias of contact. - + If new_alias is given, it will set alias to new_alias, otherwise return current alias @@ -527,7 +527,7 @@ def star(self) -> Optional[bool]: def gender(self) -> ContactGender: """ Return the gender of contact. - + Returns: ContactGender: the object of contact gender """ @@ -571,7 +571,7 @@ async def avatar(self, file_box: Optional[FileBox] = None) -> FileBox: Args: file_box: If given, it will set it as new avatar, else get the current avatar. Defaults to None. - + Examples: >>> contact = Contact.load('contact-id') >>> avatar = contact.avatar() @@ -627,7 +627,7 @@ def weixin(self) -> Optional[str]: Examples: >>> contact = Contact.load('contact-id') >>> weixin = contact.weixin() - + Returns: identifier: the weixin union identifier of contact """ diff --git a/src/wechaty/user/room.py b/src/wechaty/user/room.py index 85ea075a..31730bb8 100644 --- a/src/wechaty/user/room.py +++ b/src/wechaty/user/room.py @@ -194,7 +194,7 @@ def filter_func(room: Room) -> bool: @classmethod async def find_all(cls, - query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None) -> List[Room]: + query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None,force_sync:bool=False) -> List[Room]: """ find all rooms based on query, which can be string, RoomQueryFilter, or callable function @@ -228,9 +228,9 @@ async def find_all(cls, # 1. load rooms with concurrent tasks room_ids = await cls.get_puppet().room_search() rooms: List[Room] = [cls.load(room_id) for room_id in room_ids] - tasks: List[Task] = [asyncio.create_task(room.ready()) for room in rooms] + tasks: List[Task] = [asyncio.create_task(room.ready(force_sync)) for room in rooms] await gather_with_concurrency(PARALLEL_TASK_NUM, tasks) - + # 2. filter the rooms if not query: return rooms @@ -315,7 +315,7 @@ async def ready(self, force_sync: bool = False, load_members: bool = False) -> N Returns: None """ - if self.is_ready(): + if not force_sync and self.is_ready(): return if force_sync: diff --git a/src/wechaty/wechaty.py b/src/wechaty/wechaty.py index 1591943d..0972a64f 100644 --- a/src/wechaty/wechaty.py +++ b/src/wechaty/wechaty.py @@ -530,7 +530,7 @@ async def heartbeat_listener(payload: EventHeartbeatPayload) -> None: self.emit('heartbeat', payload.data) await self.on_heartbeat(payload) - puppet.on('heart-beat', heartbeat_listener) + puppet.on('heartbeat', heartbeat_listener) elif event_name == 'friendship': async def friendship_listener(payload: EventFriendshipPayload) -> None: