Пример #1
0
def screenshot(bot: Bot, message: Message) -> None:
    for entity in message.parse_entities():
        if entity.type == 'url':
            url = message.parse_entity(entity)
            try:
                bot.send_chat_action(message.chat_id, ChatAction.UPLOAD_PHOTO)
                scrn = cpt.take_screenshot(url)
                scrn_url = upload(scrn)['secure_url']
                bot.send_photo(message.chat_id, scrn_url)
            except IllegalURL:
                message.reply_text(BOT_ILLEGAL_URL)
 def test_parse_entity(self):
     text = (b'\\U0001f469\\u200d\\U0001f469\\u200d\\U0001f467'
             b'\\u200d\\U0001f467\\U0001f431http://google.com'
             ).decode('unicode-escape')
     entity = MessageEntity(type=MessageEntity.URL, offset=13, length=17)
     message = Message(1,
                       self.from_user,
                       self.date,
                       self.chat,
                       text=text,
                       entities=[entity])
     assert message.parse_entity(entity) == 'http://google.com'
 def test_parse_entity(self):
     text = (b'\\U0001f469\\u200d\\U0001f469\\u200d\\U0001f467'
             b'\\u200d\\U0001f467\\U0001f431http://google.com').decode('unicode-escape')
     entity = MessageEntity(type=MessageEntity.URL, offset=13, length=17)
     message = Message(1, self.from_user, self.date, self.chat, text=text, entities=[entity])
     assert message.parse_entity(entity) == 'http://google.com'