当前位置: 首页>>代码示例>>Python>>正文


Python types.PeerChat方法代码示例

本文整理汇总了Python中telethon.tl.types.PeerChat方法的典型用法代码示例。如果您正苦于以下问题:Python types.PeerChat方法的具体用法?Python types.PeerChat怎么用?Python types.PeerChat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telethon.tl.types的用法示例。


在下文中一共展示了types.PeerChat方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_user

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_user(message):
    """Get user who sent message, searching if not found easily"""
    try:
        return await message.client.get_entity(message.from_id)
    except ValueError:  # Not in database. Lets go looking for them.
        logging.debug("user not in session cache. searching...")
    if isinstance(message.to_id, PeerUser):
        await message.client.get_dialogs()
        return await message.client.get_entity(message.from_id)
    if isinstance(message.to_id, (PeerChannel, PeerChat)):
        async for user in message.client.iter_participants(message.to_id, aggressive=True):
            if user.id == message.from_id:
                return user
        logging.error("WTF! user isn't in the group where they sent the message")
        return None
    logging.error("WTF! to_id is not a user, chat or channel")
    return None 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:19,代码来源:utils.py

示例2: get_entity_rows_by_id

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_entity_rows_by_id(self, key: int, exact: bool = True) -> Optional[Tuple[int, int]]:
        t = self.Entity.__table__
        if exact:
            rows = self.engine.execute(select([t.c.id, t.c.hash]).where(
                and_(t.c.session_id == self.session_id, t.c.id == key)))
        else:
            ids = (
                utils.get_peer_id(PeerUser(key)),
                utils.get_peer_id(PeerChat(key)),
                utils.get_peer_id(PeerChannel(key))
            )
            rows = self.engine.execute(select([t.c.id, t.c.hash])
                .where(
                and_(t.c.session_id == self.session_id, t.c.id.in_(ids))))

        try:
            return next(rows)
        except StopIteration:
            return None 
开发者ID:tulir,项目名称:telethon-session-sqlalchemy,代码行数:21,代码来源:core.py

示例3: ensure_id_marked

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def ensure_id_marked(eid, etype):
        """
        Given an entity ID and type (PeerUser, PeerChat, PeerChannel), return
        the marked ID regardless of whether the ID is already marked.
        """
        if etype == types.PeerUser:
            return eid
        if etype == types.PeerChat:
            if eid < 0:
                return eid
            return -eid
        if etype == types.PeerChannel:
            if str(eid).startswith('-100'):
                return eid
            # Append -100 at start. See telethon/utils.py get_peer_id.
            return -(eid + pow(10, math.floor(math.log10(eid) + 3))) 
开发者ID:expectocode,项目名称:telegram-export,代码行数:18,代码来源:baseformatter.py

示例4: get_entity

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_entity(self, context_id, at_date=None):
        """
        Return the entity (user, chat or channel) corresponding to this context
        ID, at the given date (like all the specific methods). Context ID must
        be marked in the Bot API style, as with get_messages_from_context.
        """
        peer_type = utils.resolve_id(context_id)[1]
        if peer_type == types.PeerUser:
            return self.get_user(context_id, at_date=at_date)
        elif peer_type == types.PeerChat:
            return self.get_chat(context_id, at_date=at_date)
        elif peer_type == types.PeerChannel:
            supergroup = self.get_supergroup(context_id, at_date=at_date)
            if not supergroup:
                return self.get_channel(context_id, at_date=at_date)
            return supergroup
        else:
            raise ValueError('Invalid ID {} given'.format(context_id)) 
开发者ID:expectocode,项目名称:telegram-export,代码行数:20,代码来源:baseformatter.py

示例5: get_chat

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_chat(self, cid, at_date=None):
        """
        Return the chat with given ID or return None. If at_date is set, get
        the chat as it was at the given date (to the best of our knowledge).
        at_date should be a UTC timestamp or datetime object.
        """
        at_date = self.get_timestamp(at_date)
        cid = self.ensure_id_marked(cid, types.PeerChat)

        cur = self.dbconn.cursor()
        query = (
            "SELECT ID, DateUpdated, Title, MigratedToID, PictureID FROM Chat"
        )
        row = self._fetch_at_date(cur, query, cid, at_date)
        if not row:
            return None
        chat = Chat(*row)
        return chat._replace(date_updated=datetime.datetime.fromtimestamp(chat.date_updated)) 
开发者ID:expectocode,项目名称:telegram-export,代码行数:20,代码来源:baseformatter.py

示例6: iter_resume_entities

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def iter_resume_entities(self, context_id):
        """
        Returns an iterator over the entities that need resuming for the
        given context_id. Note that the entities are *removed* once the
        iterator is consumed completely.
        """
        c = self.conn.execute("SELECT ID, AccessHash FROM ResumeEntity "
                              "WHERE ContextID = ?", (context_id,))
        row = c.fetchone()
        while row:
            kind = resolve_id(row[0])[1]
            if kind == types.PeerUser:
                yield types.InputPeerUser(row[0], row[1])
            elif kind == types.PeerChat:
                yield types.InputPeerChat(row[0])
            elif kind == types.PeerChannel:
                yield types.InputPeerChannel(row[0], row[1])
            row = c.fetchone()

        c.execute("DELETE FROM ResumeEntity WHERE ContextID = ?",
                  (context_id,)) 
开发者ID:expectocode,项目名称:telegram-export,代码行数:23,代码来源:dumper.py

示例7: get_entity_rows_by_id

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_entity_rows_by_id(self, key: int, exact: bool = True) -> Optional[Tuple[int, int]]:
        if exact:
            query = self._db_query(self.Entity, self.Entity.id == key)
        else:
            ids = (
                utils.get_peer_id(PeerUser(key)),
                utils.get_peer_id(PeerChat(key)),
                utils.get_peer_id(PeerChannel(key))
            )
            query = self._db_query(self.Entity, self.Entity.id.in_(ids))

        row = query.one_or_none()
        return (row.id, row.hash) if row else None 
开发者ID:tulir,项目名称:telethon-session-sqlalchemy,代码行数:15,代码来源:orm.py

示例8: _get_name

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def _get_name(self, peer_id):
        if peer_id is None:
            return ''

        name = self._displays.get(peer_id)
        if name:
            return name

        c = self.dumper.conn.cursor()
        _, kind = utils.resolve_id(peer_id)
        if kind == types.PeerUser:
            row = c.execute('SELECT FirstName, LastName FROM User '
                            'WHERE ID = ?', (peer_id,)).fetchone()
            if row:
                return '{} {}'.format(row[0] or '',
                                      row[1] or '').strip()
        elif kind == types.PeerChat:
            row = c.execute('SELECT Title FROM Chat '
                            'WHERE ID = ?', (peer_id,)).fetchone()
            if row:
                return row[0]
        elif kind == types.PeerChannel:
            row = c.execute('SELECT Title FROM Channel '
                            'WHERE ID = ?', (peer_id,)).fetchone()
            if row:
                return row[0]
            row = c.execute('SELECT Title FROM Supergroup '
                            'WHERE ID = ?', (peer_id,)).fetchone()
            if row:
                return row[0]
        return '' 
开发者ID:expectocode,项目名称:telegram-export,代码行数:33,代码来源:downloader.py

示例9: get_channel_all_users

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_channel_all_users(self, channel_id):
        # TODO: this function is not complete
        channel = self.client.get_entity(PeerChat(channel_id))
        users = self.client.get_participants(channel)
        print('total users: {}'.format(users.total))
        for user in users:
            if user.username is not None and not user.is_self:
                print(utils.get_display_name(user), user.username, user.id, user.bot, user.verified, user.restricted, user.first_name, user.last_name, user.phone, user.is_self)

    # =====================
    # Get # of participants
    # ===================== 
开发者ID:paulpierre,项目名称:informer,代码行数:14,代码来源:informer.py

示例10: get_channel_info_by_group_id

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def get_channel_info_by_group_id(self, id):
        channel = self.client.get_entity(PeerChat(id))

        return {
            'channel_id': channel.id,
            'channel_title': channel.title,
            'is_broadcast': False,
            'is_mega_group': False,
            'channel_access_hash': None,
        }

    # ==========================
    # Get channel by channel URL
    # ========================== 
开发者ID:paulpierre,项目名称:informer,代码行数:16,代码来源:informer.py

示例11: filter_message

# 需要导入模块: from telethon.tl import types [as 别名]
# 或者: from telethon.tl.types import PeerChat [as 别名]
def filter_message(self, event):
        # If this is a channel, grab the channel ID
        if isinstance(event.message.to_id, PeerChannel):
            channel_id = event.message.to_id.channel_id
        # If this is a group chat, grab the chat ID
        elif isinstance(event.message.to_id, PeerChat):
            channel_id = event.message.chat_id
        else:
            # Message comes neither from a channel or chat, lets skip
            return

        # Channel values from the API are signed ints, lets get ABS for consistency
        channel_id = abs(channel_id)

        message = event.raw_text

        # Lets check to see if the message comes from our channel list
        if channel_id in self.channel_list:

            # Lets iterate through our keywords to monitor list
            for keyword in self.keyword_list:

                # If it matches the regex then voila!
                if re.search(keyword['regex'], message, re.IGNORECASE):
                    logging.info(
                        'Filtering: {}\n\nEvent raw text: {} \n\n Data: {}'.format(channel_id, event.raw_text, event))

                    # Lets send the notification with all the pertinent information in the params
                    await self.send_notification(message_obj=event.message, event=event, sender_id=event.sender_id, channel_id=channel_id, keyword=keyword['name'], keyword_id=keyword['id'])

    # ====================
    # Handle notifications
    # ==================== 
开发者ID:paulpierre,项目名称:informer,代码行数:35,代码来源:informer.py


注:本文中的telethon.tl.types.PeerChat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。