Python telethon.tl.types.InputPeerChannel() Examples

The following are 7 code examples of telethon.tl.types.InputPeerChannel(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module telethon.tl.types , or try the search function .
Example #1
Source File: dumper.py    From telegram-export with Mozilla Public License 2.0 6 votes vote down vote up
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,)) 
Example #2
Source File: dumper.py    From telegram-export with Mozilla Public License 2.0 6 votes vote down vote up
def save_resume_entities(self, context_id, entities):
        """
        Saves the given entities for resuming at a later point.
        """
        rows = []
        for ent in entities:
            ent = get_input_peer(ent)
            if isinstance(ent, types.InputPeerUser):
                rows.append((context_id, ent.user_id, ent.access_hash))
            elif isinstance(ent, types.InputPeerChat):
                rows.append((context_id, ent.chat_id, None))
            elif isinstance(ent, types.InputPeerChannel):
                rows.append((context_id, ent.channel_id, ent.access_hash))
        c = self.conn.cursor()
        c.executemany("INSERT OR REPLACE INTO ResumeEntity "
                      "VALUES (?,?,?)", rows) 
Example #3
Source File: downloader.py    From telegram-export with Mozilla Public License 2.0 5 votes vote down vote up
def enqueue_entities(self, entities):
        """
        Enqueues the given iterable of entities to be dumped later by a
        different coroutine. These in turn might enqueue profile photos.
        """
        for entity in entities:
            eid = utils.get_peer_id(entity)
            self._displays[eid] = utils.get_display_name(entity)
            if isinstance(entity, types.User):
                if entity.deleted or entity.min:
                    continue  # Empty name would cause IntegrityError
            elif isinstance(entity, types.Channel):
                if entity.left:
                    continue  # Getting full info triggers ChannelPrivateError
            elif not isinstance(entity, (types.Chat,
                                         types.InputPeerUser,
                                         types.InputPeerChat,
                                         types.InputPeerChannel)):
                # Drop UserEmpty, ChatEmpty, ChatForbidden and ChannelForbidden
                continue

            if eid in self._checked_entity_ids:
                continue
            else:
                self._checked_entity_ids.add(eid)
                if isinstance(entity, (types.User, types.InputPeerUser)):
                    self._user_queue.put_nowait(entity)
                else:
                    self._chat_queue.put_nowait(entity) 
Example #4
Source File: superblock.py    From BotHub with Apache License 2.0 5 votes vote down vote up
def on_mentioned(event):
    if not event.message.from_id:  # Channel messages don't have a from_id
        return
    if event.from_id not in blocked_user_ids:
        return

    peer = await borg.get_input_entity(event.chat_id)
    if isinstance(peer, InputPeerChannel):
        o = tlf.channels.ReadMessageContentsRequest(peer, [event.message.id])
    else:
        o = tlf.messages.ReadMessageContentsRequest([event.message.id])
    await borg(o) 
Example #5
Source File: sed.py    From BotHub with Apache License 2.0 5 votes vote down vote up
def group_has_sedbot(group):
    if isinstance(group, types.InputPeerChannel):
        full = await borg(functions.channels.GetFullChannelRequest(group))
    elif isinstance(group, types.InputPeerChat):
        full = await borg(functions.messages.GetFullChatRequest(group.chat_id))
    else:
        return False

    return any(KNOWN_RE_BOTS.match(x.username or '') for x in full.users) 
Example #6
Source File: sed.py    From X-tra-Telegram with Apache License 2.0 5 votes vote down vote up
def group_has_sedbot(group):
    if isinstance(group, types.InputPeerChannel):
        full = await bot(functions.channels.GetFullChannelRequest(group))
    elif isinstance(group, types.InputPeerChat):
        full = await bot(functions.messages.GetFullChatRequest(group.chat_id))
    else:
        return False

    return any(KNOWN_RE_BOTS.match(x.username or '') for x in full.users) 
Example #7
Source File: util.py    From tgfilestream with GNU Affero General Public License v3.0 5 votes vote down vote up
def unpack_id(file_id: int) -> Tuple[TypeInputPeer, int]:
    is_group = file_id & group_bit
    is_channel = file_id & channel_bit
    chat_id = file_id >> chat_id_offset & pack_bit_mask
    msg_id = file_id >> msg_id_offset & pack_bit_mask
    if is_channel:
        peer = InputPeerChannel(channel_id=chat_id, access_hash=0)
    elif is_group:
        peer = InputPeerChat(chat_id=chat_id)
    else:
        peer = InputPeerUser(user_id=chat_id, access_hash=0)
    return peer, msg_id