How to use the ehforwarderbot.chat.PrivateChat function in ehforwarderbot

To help you get started, we’ve selected a few ehforwarderbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blueset / efb-telegram-master / tests / mocks / slave.py View on Github external
self.chats_by_notification_state[notification].append(chat)
            self.chats_by_profile_picture[avatar is not None].append(chat)
            self.chats_by_alias[alias is not None].append(chat)
            self.chats.append(chat)

        name = "Unknown Chat"
        self.unknown_chat: PrivateChat = PrivateChat(
            channel=self,
            name=name,
            alias="不知道",
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name))),
            notification=ChatNotificationState.ALL
        )

        name = "Unknown Chat @ unknown channel"
        self.unknown_channel: PrivateChat = PrivateChat(
            module_id="__this_is_not_a_channel__",
            module_name="Unknown Channel",
            channel_emoji="‼️",
            name=name,
            alias="知らんでぇ",
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name))),
            notification=ChatNotificationState.ALL
        )

        name = "backup_chat"
        self.backup_chat: PrivateChat = PrivateChat(
            channel=self,
            name=name,
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name))),
            notification=ChatNotificationState.ALL
        )
github blueset / efb-telegram-master / tests / mocks / slave.py View on Github external
notification=ChatNotificationState.ALL
        )

        name = "Unknown Chat @ unknown channel"
        self.unknown_channel: PrivateChat = PrivateChat(
            module_id="__this_is_not_a_channel__",
            module_name="Unknown Channel",
            channel_emoji="‼️",
            name=name,
            alias="知らんでぇ",
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name))),
            notification=ChatNotificationState.ALL
        )

        name = "backup_chat"
        self.backup_chat: PrivateChat = PrivateChat(
            channel=self,
            name=name,
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name))),
            notification=ChatNotificationState.ALL
        )

        name = "backup_member"
        self.backup_member: ChatMember = ChatMember(
            self.chats_by_chat_type['GroupChat'][0],
            name=name,
            uid=ChatID(self.CHAT_ID_FORMAT.format(hash=hash(name)))
        )
github blueset / efb-telegram-master / tests / unit / test_etm_chat.py View on Github external
def test_etm_chat_conversion_private(db, slave):
    private_chat = slave.get_chat_by_criteria(chat_type='PrivateChat')
    assert isinstance(private_chat, PrivateChat)
    etm_private_chat = convert_chat(db, private_chat)
    assert isinstance(etm_private_chat, ETMPrivateChat)
    assert isinstance(etm_private_chat.other, ETMChatMember)
    assert not isinstance(etm_private_chat.other, ETMSelfChatMember)
    assert isinstance(etm_private_chat.self, ETMSelfChatMember)
    assert etm_private_chat.other in etm_private_chat.members
    assert etm_private_chat.self in etm_private_chat.members
    assert all(isinstance(i, ETMChatMember) for i in etm_private_chat.members)
    assert len(etm_private_chat.members) == len(private_chat.members)
github blueset / efb-wechat-slave / efb_wechat_slave / chats.py View on Github external
def __init__(self, channel: 'WeChatChannel'):
        self.channel: 'WeChatChannel' = channel
        self.logger: logging.Logger = logging.getLogger(__name__)

        # noinspection PyProtectedMember
        self._ = self.channel._

        self.MISSING_GROUP: GroupChat = GroupChat(
            channel=self.channel,
            uid=ChatID("__error_group__"),
            name=self._("Group Missing")
        )

        self.MISSING_CHAT: PrivateChat = PrivateChat(
            channel=self.channel,
            uid=ChatID("__error_chat__"),
            name=self._("Chat Missing")
        )

        self.efb_chat_objs: Dict[str, Chat] = {}
        # Cached Chat objects. Key: tuple(chat PUID, group PUID or None)

        # Load system chats
        self.system_chats: List[Chat] = []
        for i in channel.flag('system_chats_to_include'):
            self.system_chats.append(
                self.wxpy_chat_to_efb_chat(
                    wxpy.Chat(
                        wxpy.utils.wrap_user_name(i),
                        self.bot
github blueset / efb-telegram-master / efb_telegram_master / slave_message.py View on Github external
def generate_message_template(self, msg: Message, singly_linked: bool) -> str:
        msg_prefix = ""  # For group member name
        if isinstance(msg.chat, GroupChat):
            self.logger.debug("[%s] Message is from a group. Sender: %s", msg.uid, msg.author)
            msg_prefix = msg.author.long_name

        if singly_linked:
            if msg_prefix:  # if group message
                msg_template = f"{msg_prefix}:"
            else:
                if msg.chat != msg.author:
                    msg_template = f"{msg.author.long_name}:"
                else:
                    msg_template = ""
        elif isinstance(msg.chat, PrivateChat):
            emoji_prefix = msg.chat.channel_emoji + Emoji.USER
            name_prefix = msg.chat.long_name
            if msg.chat.other != msg.author:
                name_prefix += f", {msg.author.long_name}"
            msg_template = f"{emoji_prefix} {name_prefix}:"
        elif isinstance(msg.chat, GroupChat):
            emoji_prefix = msg.chat.channel_emoji + Emoji.GROUP
            name_prefix = msg.chat.long_name
            msg_template = f"{emoji_prefix} {msg_prefix} [{name_prefix}]:"
        elif isinstance(msg.chat, SystemChat):
            emoji_prefix = msg.chat.channel_emoji + Emoji.SYSTEM
            name_prefix = msg.chat.long_name
            if msg.chat.other != msg.author:
                name_prefix += f", {msg.author.long_name}"
            msg_template = f"{emoji_prefix} {name_prefix}:"
        else:
github blueset / efb-wechat-slave / efb_wechat_slave / chats.py View on Github external
member_name, member_alias = self.get_name_alias(member)
                        efb_chat.add_member(name=member_name, alias=member_alias, uid=member.puid,
                                            vendor_specific={'is_mp': False})
        elif chat == chat.bot.self:
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True}, other_is_self=True)
        elif isinstance(chat, wxpy.Group):
            efb_chat = GroupChat(channel=self.channel, uid=chat_id, name=chat_name,
                                 alias=chat_alias, vendor_specific={'is_mp': False})
            for i in chat.members:
                if i.user_name == self.bot.self.user_name:
                    continue
                member_name, member_alias = self.get_name_alias(i)
                efb_chat.add_member(name=member_name, alias=member_alias, uid=i.puid, vendor_specific={'is_mp': False})
        elif isinstance(chat, wxpy.MP):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True})
        elif isinstance(chat, wxpy.User):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': False})
        else:
            efb_chat = SystemChat(channel=self.channel, uid=chat_id, name=chat_name,
                                  alias=chat_alias, vendor_specific={'is_mp': False})

        efb_chat.vendor_specific.update(self.generate_vendor_specific(chat))
        if efb_chat.vendor_specific.get('is_muted', False):
            efb_chat.notification = ChatNotificationState.MENTIONS

        self.efb_chat_objs[cache_key] = efb_chat

        return efb_chat
github blueset / efb-wechat-slave / efb_wechat_slave / chats.py View on Github external
elif chat == chat.bot.self:
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True}, other_is_self=True)
        elif isinstance(chat, wxpy.Group):
            efb_chat = GroupChat(channel=self.channel, uid=chat_id, name=chat_name,
                                 alias=chat_alias, vendor_specific={'is_mp': False})
            for i in chat.members:
                if i.user_name == self.bot.self.user_name:
                    continue
                member_name, member_alias = self.get_name_alias(i)
                efb_chat.add_member(name=member_name, alias=member_alias, uid=i.puid, vendor_specific={'is_mp': False})
        elif isinstance(chat, wxpy.MP):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True})
        elif isinstance(chat, wxpy.User):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': False})
        else:
            efb_chat = SystemChat(channel=self.channel, uid=chat_id, name=chat_name,
                                  alias=chat_alias, vendor_specific={'is_mp': False})

        efb_chat.vendor_specific.update(self.generate_vendor_specific(chat))
        if efb_chat.vendor_specific.get('is_muted', False):
            efb_chat.notification = ChatNotificationState.MENTIONS

        self.efb_chat_objs[cache_key] = efb_chat

        return efb_chat
github blueset / efb-wechat-slave / efb_wechat_slave / chats.py View on Github external
efb_chat.alias = chat_alias
            efb_chat.vendor_specific = {'is_mp': isinstance(chat, wxpy.MP)}

            if isinstance(chat, wxpy.Group):
                # Update members if necessary
                remote_puids = {i.puid for i in chat.members}
                local_ids = {i.uid for i in efb_chat.members if not isinstance(i, SelfChatMember)}
                # Add missing members
                missing_puids = remote_puids - local_ids
                for member in chat.members:
                    if member.puid in missing_puids:
                        member_name, member_alias = self.get_name_alias(member)
                        efb_chat.add_member(name=member_name, alias=member_alias, uid=member.puid,
                                            vendor_specific={'is_mp': False})
        elif chat == chat.bot.self:
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True}, other_is_self=True)
        elif isinstance(chat, wxpy.Group):
            efb_chat = GroupChat(channel=self.channel, uid=chat_id, name=chat_name,
                                 alias=chat_alias, vendor_specific={'is_mp': False})
            for i in chat.members:
                if i.user_name == self.bot.self.user_name:
                    continue
                member_name, member_alias = self.get_name_alias(i)
                efb_chat.add_member(name=member_name, alias=member_alias, uid=i.puid, vendor_specific={'is_mp': False})
        elif isinstance(chat, wxpy.MP):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': True})
        elif isinstance(chat, wxpy.User):
            efb_chat = PrivateChat(channel=self.channel, uid=chat_id, name=chat_name,
                                   alias=chat_alias, vendor_specific={'is_mp': False})
        else: