How to use the telethon.tl.functions 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 / client / chats.py View on Github external
async def _init(
            self, entity, offset, max_id
    ):
        entity = await self.client.get_input_entity(entity)
        ty = helpers._entity_type(entity)
        if ty == helpers._EntityType.USER:
            self.request = functions.photos.GetUserPhotosRequest(
                entity,
                offset=offset,
                max_id=max_id,
                limit=1
            )
        else:
            self.request = functions.messages.SearchRequest(
                peer=entity,
                q='',
                filter=types.InputMessagesFilterChatPhotos(),
                min_date=None,
                max_date=None,
                offset_id=0,
                add_offset=offset,
                limit=1,
                max_id=max_id,
github LonamiWebs / Telethon / telethon / tl / custom / message.py View on Github external
# Click by text
                    await message.click(text='👍')

                    # Click by data
                    await message.click(data=b'payload')
        """
        if not self._client:
            return

        if data:
            if not await self.get_input_chat():
                return None

            try:
                return await self._client(
                    functions.messages.GetBotCallbackAnswerRequest(
                        peer=self._input_chat,
                        msg_id=self.id,
                        data=data
                    )
                )
            except errors.BotTimeout:
                return None

        if sum(int(x is not None) for x in (i, text, filter)) >= 2:
            raise ValueError('You can only set either of i, text or filter')

        if not await self.get_buttons():
            return  # Accessing the property sets self._buttons[_flat]

        if text is not None:
            if callable(text):
github LonamiWebs / Telethon / telethon / client / chats.py View on Github external
if ty == helpers._EntityType.CHANNEL:
            # If we try to set these permissions in a megagroup, we
            # would get a RIGHT_FORBIDDEN. However, it makes sense
            # that an admin can post messages, so we want to avoid the error
            if post_messages or edit_messages:
                # TODO get rid of this once sessions cache this information
                if entity.channel_id not in self._megagroup_cache:
                    full_entity = await self.get_entity(entity)
                    self._megagroup_cache[entity.channel_id] = full_entity.megagroup

                if self._megagroup_cache[entity.channel_id]:
                    post_messages = None
                    edit_messages = None

            perms = locals()
            return await self(functions.channels.EditAdminRequest(entity, user, types.ChatAdminRights(**{
                # A permission is its explicit (not-None) value or `is_admin`.
                # This essentially makes `is_admin` be the default value.
                name: perms[name] if perms[name] is not None else is_admin
                for name in perm_names
            }), rank=title or ''))

        elif ty == helpers._EntityType.CHAT:
            # If the user passed any permission in a small
            # group chat, they must be a full admin to have it.
            if is_admin is None:
                is_admin = any(locals()[x] for x in perm_names)

            return await self(functions.messages.EditChatAdminRequest(
                entity, user, is_admin=is_admin))

        else:
github kandnub / TG-UserBot / userbot / plugins / blacklist.py View on Github external
):
            return
        elif sender_id in blacklistedUsers:
            if sender_id not in temp_banlist:
                await ban_user(event, 'blacklisted', blacklisted_text)
            return
        elif GlobalBlacklist.tgid and sender_id in GlobalBlacklist.tgid:
            index = GlobalBlacklist.tgid.index(sender_id)
            if await ban_user(event, 'tgid', sender_id, index, True):
                return
        elif localbl and localbl.tgid and sender_id in localbl.tgid:
            index = localbl.tgid.index(sender_id)
            if await ban_user(event, 'tgid', sender_id, index):
                return

        user = await client(functions.users.GetFullUserRequest(id=sender))
        if not user.about:
            return
        if GlobalBlacklist.bio:
            for index, value in enumerate(GlobalBlacklist.bio):
                bio = await escape_string(value)
                if re.search(bio, user.about, flags=re.I):
                    await ban_user(event, 'bio', value, index, True)
                    break
        elif (
            localbl and hasattr(localbl, 'bio') and
            localBlacklists[event.chat_id].bio
        ):
            for index, value in enumerate(localBlacklists[chat_id].bio):
                bio = await escape_string(value)
                if re.search(bio, user.about, flags=re.I):
                    await ban_user(event, 'bio', value, index)
github LonamiWebs / Telethon / telethon / client / auth.py View on Github external
code = input('enter code: ')
                await client.sign_in(phone, code)
        """
        me = await self.get_me()
        if me:
            return me

        if phone and not code and not password:
            return await self.send_code_request(phone)
        elif code:
            phone, phone_code_hash = \
                self._parse_phone_and_hash(phone, phone_code_hash)

            # May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
            # PhoneCodeHashEmptyError or PhoneCodeInvalidError.
            request = functions.auth.SignInRequest(
                phone, phone_code_hash, str(code)
            )
        elif password:
            pwd = await self(functions.account.GetPasswordRequest())
            request = functions.auth.CheckPasswordRequest(
                pwd_mod.compute_check(pwd, password)
            )
        elif bot_token:
            request = functions.auth.ImportBotAuthorizationRequest(
                flags=0, bot_auth_token=bot_token,
                api_id=self.api_id, api_hash=self.api_hash
            )
        else:
            raise ValueError(
                'You must provide a phone and a code the first time, '
                'and a password only if an RPCError was raised before.'
github LonamiWebs / Telethon / telethon / client / uploads.py View on Github external
# Needed when a Message is passed to send_message and it has media.
        if 'entities' in kwargs:
            msg_entities = kwargs['entities']
        else:
            caption, msg_entities =\
                await self._parse_message_text(caption, parse_mode)

        file_handle, media = await self._file_to_media(
            file, force_document=force_document,
            progress_callback=progress_callback,
            attributes=attributes, thumb=thumb,
            voice_note=voice_note, video_note=video_note
        )

        markup = self.build_reply_markup(buttons)
        request = functions.messages.SendMediaRequest(
            entity, media, reply_to_msg_id=reply_to, message=caption,
            entities=msg_entities, reply_markup=markup, silent=silent
        )
        msg = self._get_response_message(request, await self(request), entity)

        return msg
github LonamiWebs / Telethon / telethon / tl / custom / message.py View on Github external
`telethon.tl.custom.messagebutton.MessageButton` argument.

            data (`bytes`):
                This argument overrides the rest and will not search any
                buttons. Instead, it will directly send the request to
                behave as if it clicked a button with said data. Note
                that if the message does not have this data, it will
                ``raise DataInvalidError``.
        """
        if data:
            if not await self.get_input_chat():
                return None

            try:
                return await self._client(
                    functions.messages.GetBotCallbackAnswerRequest(
                        peer=self._input_chat,
                        msg_id=self.id,
                        data=data
                    )
                )
            except BotTimeout:
                return None

        if sum(int(x is not None) for x in (i, text, filter)) >= 2:
            raise ValueError('You can only set either of i, text or filter')

        if not await self.get_buttons():
            return  # Accessing the property sets self._buttons[_flat]

        if text is not None:
            if callable(text):