How to use the telethon.utils.get_input_peer function in Telethon

To help you get started, we’ve selected a few Telethon 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 LonamiWebs / Telethon / telethon / events / chataction.py View on Github external
async def get_input_users(self):
            """
            Returns `input_users` but will make an API call if necessary.
            """
            self._input_users = None
            if self._input_users is None:
                await self.action_message._reload_message()
                self._input_users = [
                    utils.get_input_peer(u)
                    for u in self.action_message.action_entities
                    if isinstance(u, (types.User, types.UserEmpty))]

            return self._input_users or []
github LonamiWebs / Telethon / telethon / client / auth.py View on Github external
def _on_login(self, user):
        """
        Callback called whenever the login or sign up process completes.

        Returns the input user parameter.
        """
        self._bot = bool(user.bot)
        self._self_input_peer = utils.get_input_peer(user, allow_self=False)
        self._authorized = True

        return user
github LonamiWebs / Telethon / telethon / tl / custom / message.py View on Github external
# This way there's no need to worry about get/setattr.
        self.__dict__ = original.__dict__
        self.original_message = original
        self.stringify = original.stringify
        self.to_dict = original.to_dict
        self._client = client
        self._text = None
        self._reply_message = None
        self._buttons = None
        self._buttons_flat = None
        self._buttons_count = None

        self._sender_id = original.from_id
        self._sender = entities.get(self._sender_id)
        if self._sender:
            self._input_sender = get_input_peer(self._sender)
            if not getattr(self._input_sender, 'access_hash', True):
                self._input_sender = None
        else:
            self._input_sender = None

        # Determine the right chat where the message
        # was sent, not *to which ID* it was sent.
        if not original.out and isinstance(original.to_id, types.PeerUser):
            self._chat_peer = types.PeerUser(self._sender_id)
        else:
            self._chat_peer = original.to_id

        self._broadcast = bool(original.post)
        self._chat = entities.get(self.chat_id)
        self._input_chat = input_chat
        if not self._input_chat and self._chat:
github uwinx / pomegranate / garnet / events / chataction.py View on Github external
async def get_input_users(self):
            """
            Returns `input_users` but will make an API call if necessary.
            """
            self._input_users = None
            if self._input_users is None:
                await self.action_message._reload_message()
                self._input_users = [
                    utils.get_input_peer(u)
                    for u in self.action_message.action_entities
                    if isinstance(u, (types.User, types.UserEmpty))]

            return self._input_users or []
github LonamiWebs / Telethon / telethon / tl / custom / draft.py View on Github external
def __init__(self, client, entity, draft):
        self._client = client
        self._peer = get_peer(entity)
        self._entity = entity
        self._input_entity = get_input_peer(entity) if entity else None

        if not draft or not isinstance(draft, DraftMessage):
            draft = DraftMessage('', None, None, None, None)

        self._text = markdown.unparse(draft.message, draft.entities)
        self._raw_text = draft.message
        self.date = draft.date
        self.link_preview = not draft.no_webpage
        self.reply_to_msg_id = draft.reply_to_msg_id
github LonamiWebs / Telethon / telethon / client / users.py View on Github external
Example
            .. code-block:: python

                me = await client.get_me()
                print(me.username)
        """
        if input_peer and self._self_input_peer:
            return self._self_input_peer

        try:
            me = (await self(
                functions.users.GetUsersRequest([types.InputUserSelf()])))[0]

            self._bot = me.bot
            if not self._self_input_peer:
                self._self_input_peer = utils.get_input_peer(
                    me, allow_self=False
                )

            return self._self_input_peer if input_peer else me
        except errors.UnauthorizedError:
            return None
github LonamiWebs / Telethon / telethon / tl / entity_database.py View on Github external
def _add_full_entity(self, entity):
        """Adds a "full" entity (User, Chat or Channel, not "Input*"),
           despite the value of self.enabled and self.enabled_full.

           Not to be confused with UserFull, ChatFull, or ChannelFull,
           "full" means simply not "Input*".
        """
        marked_id = utils.get_peer_id(
            utils.get_input_peer(entity, allow_self=False), add_mark=True
        )
        try:
            old_entity = self._entities[marked_id]
            old_entity.__dict__.update(entity.__dict__)  # Keep old references

            # Update must delete old username and phone
            username = getattr(old_entity, 'username', None)
            if username:
                del self._username_id[username.lower()]

            phone = getattr(old_entity, 'phone', None)
            if phone:
                del self._phone_id[phone]
        except KeyError:
            # Add new entity
            self._entities[marked_id] = entity
github expectocode / telegram-export / telegram_export / dumper.py View on Github external
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)