Skip to content

修复微信电脑版在群中@机器人时候的一些bug #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/wechaty/user/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,21 +450,25 @@ async def mention_list(self) -> List[Contact]:
# Use mention list if mention list is available
# otherwise, process the message and get the mention list


if self.payload is not None and self.payload.mention_ids is not None:
async def id_to_contact(contact_id: str) -> Contact:
contact = self.wechaty.Contact.load(contact_id)
await contact.ready()
return contact

# TODO -> change to python async best practice
contacts = [
await id_to_contact(contact_id)
for contact_id in self.payload.mention_ids]
mention_ids = self.payload.mention_ids
contact_list = await self.get_cached_contacts()
contacts = [contact for contact in contact_list if contact.contact_id in mention_ids]
return contacts

# TODO -> have to check that mention_id is not in room situation
return []

async def get_cached_contacts(self) -> List[Contact]:
"""
Get cached contacts or load them from Wechaty.
"""
if not hasattr(self, '_cached_contacts'):
contact_list = await self.wechaty.Contact.find_all()
self._cached_contacts = {contact.contact_id: contact for contact in contact_list}
return list(self._cached_contacts.values())

async def mention_text(self) -> str:
"""
get mention text
Expand Down