def build_efb_chat_as_anonymous_user(self, context): efb_chat = EFBChat(self.channel) anonymous_data = context['anonymous'] efb_chat.chat_uid = 'anonymous' + '_' + anonymous_data['flag'] efb_chat.chat_name = '[Anonymous] ' + anonymous_data['name'] efb_chat.chat_type = ChatType.User efb_chat.is_chat = False efb_chat.vendor_specific = { 'is_anonymous': True, 'anonymous_id': anonymous_data['id'] } efb_chat.group = self.build_efb_chat_as_group(context) return efb_chat
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 build_efb_chat_as_user(self, context, is_chat): efb_chat = EFBChat(self.channel) uid = context['user_id'] efb_chat.chat_uid = 'private' + '_' + str(uid) chat_name = '' if 'nickname' not in context: i: dict = self.channel.QQClient.get_stranger_info(uid) chat_name = i['nickname'] else: chat_name = context['nickname'] efb_chat.chat_name = chat_name efb_chat.chat_alias = None if 'alias' not in context else context[ 'alias'] efb_chat.chat_type = ChatType.User efb_chat.is_chat = is_chat efb_chat.vendor_specific = {'is_anonymous': False} if not is_chat and context['message_type'] != 'private': efb_chat.group = self.build_efb_chat_as_group(context) 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