def wxpy_chat_to_efb_chat(self, chat: wxpy.Chat, recursive=True) -> EFBChat: # self.logger.debug("Converting WXPY chat %r, %sin recursive mode", chat, '' if recursive else 'not ') # self.logger.debug("WXPY chat with ID: %s, name: %s, alias: %s;", chat.puid, chat.nick_name, chat.alias) if chat is None: return self.MISSING_USER if chat.puid in self.efb_chat_objs: return self.efb_chat_objs[chat.puid] efb_chat = EFBChat(self.channel) efb_chat.chat_uid = chat.puid or "__invalid__" efb_chat.chat_name = ews_utils.wechat_string_unescape(chat.nick_name) efb_chat.chat_alias = None efb_chat.chat_type = ChatType.System efb_chat.vendor_specific = {'is_mp': False} if isinstance(chat, wxpy.Member): efb_chat.chat_type = ChatType.User efb_chat.is_chat = False efb_chat.chat_alias = chat.name # self.logger.debug("[WXPY: %s] Display name: %s;", chat.puid, chat.display_name) if recursive: efb_chat.group = self.wxpy_chat_to_efb_chat(chat.group, False) elif isinstance(chat, wxpy.Group): efb_chat.chat_type = ChatType.Group for i in chat.members: efb_chat.members.append(self.wxpy_chat_to_efb_chat(i, False)) efb_chat.members[-1].group = efb_chat elif isinstance(chat, wxpy.MP): efb_chat.chat_type = ChatType.User efb_chat.vendor_specific['is_mp'] = True elif isinstance(chat, wxpy.User): efb_chat.chat_type = ChatType.User efb_chat.chat_alias = chat.remark_name or efb_chat.chat_alias # self.logger.debug("[WXPY: %s] Remark name: %s;", chat.puid, chat.remark_name) if chat == chat.bot.self: efb_chat.self() efb_chat.chat_alias = efb_chat.chat_alias and ews_utils.wechat_string_unescape( efb_chat.chat_alias) efb_chat.vendor_specific.update(self.generate_vendor_specific(chat)) if efb_chat.vendor_specific.get('is_muted', False): efb_chat.notification = EFBChatNotificationState.MENTIONS # self.logger.debug('WXPY chat %s converted to EFBChat %s', chat.puid, efb_chat) if chat.puid: self.efb_chat_objs[chat.puid] = efb_chat return efb_chat
def wxpy_chat_to_efb_chat(self, chat: wxpy.Chat, recursive=True) -> Optional[EFBChat]: self.logger.debug("Converting WXPY chat %r, %sin recursive mode", chat, '' if recursive else 'not ') self.logger.debug("WXPY chat with ID: %s, name: %s, alias: %s;", chat.puid, chat.nick_name, chat.alias) if chat is None: return self.MISSING_USER efb_chat = EFBChat(self.channel) efb_chat.chat_uid = chat.puid or "__invalid__" efb_chat.chat_name = ews_utils.wechat_string_unescape(chat.nick_name) efb_chat.chat_alias = None efb_chat.chat_type = ChatType.System efb_chat.vendor_specific = {'is_mp': False, 'wxpy_object': chat} if isinstance(chat, wxpy.Member): efb_chat.chat_type = ChatType.User efb_chat.is_chat = False efb_chat.chat_alias = chat.display_name or efb_chat.chat_alias self.logger.debug("[WXPY: %s] Display name: %s;", chat.puid, chat.display_name) if recursive: efb_chat.group = self.wxpy_chat_to_efb_chat(chat.group, False) elif isinstance(chat, wxpy.Group): efb_chat.chat_type = ChatType.Group for i in chat.members: efb_chat.members.append(self.wxpy_chat_to_efb_chat(i, False)) efb_chat.members[-1].group = efb_chat elif isinstance(chat, wxpy.MP): efb_chat.chat_type = ChatType.User efb_chat.vendor_specific['is_mp'] = True elif isinstance(chat, wxpy.User): efb_chat.chat_type = ChatType.User efb_chat.chat_alias = chat.remark_name or efb_chat.chat_alias self.logger.debug("[WXPY: %s] Remark name: %s;", chat.puid, chat.remark_name) if chat == chat.bot.self: efb_chat.self() efb_chat.chat_alias = efb_chat.chat_alias and ews_utils.wechat_string_unescape(efb_chat.chat_alias) self.logger.debug('WXPY chat %s converted to EFBChat %s', chat.puid, efb_chat) return efb_chat