加入头像信息
This commit is contained in:
23
robot.py
23
robot.py
@@ -179,7 +179,8 @@ class Robot(Job):
|
||||
|
||||
# 登录成功后加载联系人信息
|
||||
self.allContacts = self.get_all_contacts()
|
||||
self.contact_manager.set_contacts(self.allContacts)
|
||||
self.head_images =self.get_all_head_images()
|
||||
self.contact_manager.set_contacts(self.allContacts,self.head_images)
|
||||
|
||||
self.message_storage = MessageStorage(self.ipad_bot)
|
||||
|
||||
@@ -371,13 +372,16 @@ class Robot(Job):
|
||||
wxid = member.get("UserName", "")
|
||||
nick_name = member.get("NickName", "")
|
||||
displayName = member.get("DisplayName", "")
|
||||
small_head_img_url = member.get("SmallHeadImgUrl", "")
|
||||
#如果displayName不为空,使用displayName
|
||||
if displayName:
|
||||
nick_name = displayName
|
||||
if wxid:
|
||||
self.allContacts[wxid] = nick_name
|
||||
|
||||
self.contact_manager.set_contacts(self.allContacts)
|
||||
self.head_images[wxid] = small_head_img_url
|
||||
|
||||
self.contact_manager.set_contacts(self.allContacts,self.head_images)
|
||||
self.LOG.info(f"已更新群 {group_id} 的成员信息")
|
||||
except Exception as e:
|
||||
self.LOG.error(f"获取群成员信息失败: {e}")
|
||||
@@ -508,6 +512,16 @@ class Robot(Job):
|
||||
self.LOG.error(f"获取联系人信息失败: {e}")
|
||||
return {}
|
||||
|
||||
def get_all_head_images(self) -> dict:
|
||||
"""获取所有的联系人头像信息"""
|
||||
try:
|
||||
# 从数据库获取所有联系人的头像信息
|
||||
head_images = self.contacts_db.get_all_contacts_avatar()
|
||||
return head_images
|
||||
except Exception as e:
|
||||
self.LOG.error(f"获取所有联系人头像信息失败: {e}")
|
||||
return {}
|
||||
|
||||
async def refresh_contacts_db(self):
|
||||
"""刷新联系人信息"""
|
||||
# 获取用户所有的联系人,并保存到数据库
|
||||
@@ -551,13 +565,16 @@ class Robot(Job):
|
||||
wxid = member.get("UserName", "")
|
||||
nick_name = member.get("NickName", "")
|
||||
displayName = member.get("DisplayName", "")
|
||||
small_head_img_url = member.get("SmallHeadImgUrl", "")
|
||||
#如果displayName不为空,使用displayName
|
||||
if displayName:
|
||||
nick_name = displayName
|
||||
if wxid:
|
||||
self.allContacts[wxid] = nick_name
|
||||
|
||||
self.contact_manager.set_contacts(self.allContacts)
|
||||
self.head_images[wxid] = small_head_img_url
|
||||
|
||||
self.contact_manager.set_contacts(self.allContacts,self.head_images)
|
||||
self.LOG.info(f"已更新群 {group_id} 的成员信息")
|
||||
else:
|
||||
self.LOG.error(f"获取群 {group_id} 信息失败,证明用户无该群信息,删除群的相关资料。")
|
||||
|
||||
Reference in New Issue
Block a user