當前位置: 首頁>>代碼示例>>Python>>正文


Python types.PeerChannel方法代碼示例

本文整理匯總了Python中telethon.tl.types.PeerChannel方法的典型用法代碼示例。如果您正苦於以下問題:Python types.PeerChannel方法的具體用法?Python types.PeerChannel怎麽用?Python types.PeerChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telethon.tl.types的用法示例。


在下文中一共展示了types.PeerChannel方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_user

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [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 PeerChannel [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 PeerChannel [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 PeerChannel [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_channel

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def get_channel(self, cid, at_date=None):
        """
        Return the channel with given ID or return None. If at_date is set, get
        the channel 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.PeerChannel)
        cur = self.dbconn.cursor()
        query = (
            "SELECT ID, DateUpdated, About, Title, Username, "
            "PictureID, PinMessageID FROM Channel"
        )
        row = self._fetch_at_date(cur, query, cid, at_date)
        if not row:
            return None
        channel = Channel(*row)
        return channel._replace(date_updated=datetime.datetime.fromtimestamp(channel.date_updated)) 
開發者ID:expectocode,項目名稱:telegram-export,代碼行數:20,代碼來源:baseformatter.py

示例6: get_supergroup

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def get_supergroup(self, sid, at_date=None):
        """
        Return the supergroup with given ID or return None. If at_date is set,
        get the supergroup 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)
        sid = self.ensure_id_marked(sid, types.PeerChannel)
        cur = self.dbconn.cursor()
        query = (
            "SELECT ID, DateUpdated, About, Title, Username, "
            "PictureID, PinMessageID FROM Supergroup"
        )
        row = self._fetch_at_date(cur, query, sid, at_date)
        if not row:
            return None
        supergroup = Supergroup(*row)
        return supergroup._replace(date_updated=datetime.datetime.fromtimestamp(
            supergroup.date_updated)) 
開發者ID:expectocode,項目名稱:telegram-export,代碼行數:21,代碼來源:baseformatter.py

示例7: iter_resume_entities

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [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

示例8: bancmd

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def bancmd(self, message):
        """Ban the user from the group"""
        if not isinstance(message.to_id, PeerChannel):
            return await utils.answer(message, self.strings["not_supergroup"])
        if message.is_reply:
            user = await utils.get_user(await message.get_reply_message())
        else:
            args = utils.get_args(message)
            if len(args) == 0:
                return await utils.answer(message, self.strings["ban_none"])
            user = await self.client.get_entity(args[0])
        if not user:
            return await utils.answer(message, self.strings["who"])
        logger.debug(user)
        try:
            await self.client(EditBannedRequest(message.chat_id, user.id,
                                                ChatBannedRights(until_date=None, view_messages=True)))
        except BadRequestError:
            await utils.answer(message, self.strings["not_admin"])
        else:
            await self.allmodules.log("ban", group=message.chat_id, affected_uids=[user.id])
            await utils.answer(message, self.strings["banned"].format(utils.escape_html(ascii(user.first_name)))) 
開發者ID:friendly-telegram,項目名稱:modules-repo,代碼行數:24,代碼來源:admin_tools.py

示例9: unbancmd

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def unbancmd(self, message):
        """Lift the ban off the user."""
        if not isinstance(message.to_id, PeerChannel):
            return await utils.answer(message, self.strings["unban_not_supergroup"])
        if message.is_reply:
            user = await utils.get_user(await message.get_reply_message())
        else:
            args = utils.get_args(message)
            if len(args) == 0:
                return await utils.answer(message, self.strings["unban_none"])
            user = await self.client.get_entity(args[0])
        if not user:
            return await utils.answer(message, self.strings["who"])
        logger.debug(user)
        try:
            await self.client(EditBannedRequest(message.chat_id, user.id,
                              ChatBannedRights(until_date=None, view_messages=False)))
        except BadRequestError:
            await utils.answer(message, self.strings["not_admin"])
        else:
            await self.allmodules.log("unban", group=message.chat_id, affected_uids=[user.id])
            await utils.answer(message, self.strings["unbanned"].format(utils.escape_html(ascii(user.first_name)))) 
開發者ID:friendly-telegram,項目名稱:modules-repo,代碼行數:24,代碼來源:admin_tools.py

示例10: get_entity_rows_by_id

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [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

示例11: _chat_consumer

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def _chat_consumer(self, queue, bar):
        while self._running:
            start = time.time()
            chat = await queue.get()
            if isinstance(chat, (types.Chat, types.PeerChat)):
                self._dump_full_entity(chat)
            else:  # isinstance(chat, (types.Channel, types.PeerChannel)):
                self._dump_full_entity(await self.client(
                    functions.channels.GetFullChannelRequest(chat)
                ))
            queue.task_done()
            bar.update(1)
            await asyncio.sleep(max(CHAT_FULL_DELAY - (time.time() - start), 0),
                                loop=self.loop) 
開發者ID:expectocode,項目名稱:telegram-export,代碼行數:16,代碼來源:downloader.py

示例12: get_channel_user_count

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [as 別名]
def get_channel_user_count(self, channel):
        data = await self.client.get_entity(PeerChannel(-channel))
        users = await self.client.get_participants(data)
        return users.total

    # =======================
    # Get channel by group ID
    # ======================= 
開發者ID:paulpierre,項目名稱:informer,代碼行數:10,代碼來源:informer.py

示例13: filter_message

# 需要導入模塊: from telethon.tl import types [as 別名]
# 或者: from telethon.tl.types import PeerChannel [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.PeerChannel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。