Ejemplo n.º 1
0
 def build_efb_chat_as_group(self, context):
     efb_chat = EFBChat(self.channel)
     efb_chat.chat_type = ChatType.Group
     is_discuss = False if context['message_type'] == 'group' else True
     chat_uid = context['discuss_id'] if is_discuss else context['group_id']
     if not is_discuss:
         efb_chat.chat_uid = 'group' + '_' + str(chat_uid)
         i = self.channel.QQClient.get_group_info(chat_uid)
         if i is not None:
             efb_chat.chat_name = i[
                 'group_name'] if 'group_name' not in context else context[
                     'group_name']
         else:
             efb_chat.chat_name = chat_uid
         efb_chat.vendor_specific = {'is_discuss': False}
         # todo Add user to efb_chat.member
     else:
         efb_chat.chat_uid = 'discuss' + '_' + str(chat_uid)
         efb_chat.chat_name = 'Discuss Group' + '_' + str(chat_uid)
         # todo Find a way to distinguish from different discuss group
         efb_chat.vendor_specific = {'is_discuss': True}
     return efb_chat
Ejemplo n.º 2
0
 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
Ejemplo n.º 4
0
 def get_efb_chats(self):
     chat_list = requests.get(user_url % (self.hostname, self.port)).json()
     result = []
     for chat_item in chat_list:
         efb_chat = EFBChat(self.channel)
         efb_chat.chat_uid = chat_item["userId"]
         title = chat_item["title"]
         if title.startswith("[Group] "):
             efb_chat.chat_name = title[8:]
             efb_chat.chat_type = ChatType.Group
         else:
             efb_chat.chat_name = title
             efb_chat.chat_type = ChatType.User
         efb_chat.chat_alias = None
         efb_chat.is_chat = True
         efb_chat.vendor_specific = {'is_anonymous': False}
         result.append(efb_chat)
     return result
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
Archivo: chats.py Proyecto: Z0-0Z/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