Exemple #1
0
    def compute():
        query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
        print('%s: Computing for: %s' % (threading.current_thread().name, query_string))

        articles = [InlineQueryResultArticle(
                        id='abcde', title='Telegram', input_message_content=InputTextMessageContent(message_text='Telegram is a messaging app')),
                    dict(type='article',
                        id='fghij', title='Google', input_message_content=dict(message_text='Google is a search engine'))]

        photo1_url = 'https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'
        photo2_url = 'https://www.telegram.org/img/t_logo.png'
        photos = [InlineQueryResultPhoto(
                      id='12345', photo_url=photo1_url, thumb_url=photo1_url),
                  dict(type='photo',
                      id='67890', photo_url=photo2_url, thumb_url=photo2_url)]

        result_type = query_string[-1:].lower()

        if result_type == 'a':
            return articles
        elif result_type == 'p':
            return photos
        else:
            results = articles if random.randint(0,1) else photos
            if result_type == 'b':
                return dict(results=results, switch_pm_text='Back to Bot', switch_pm_parameter='Optional start parameter')
            else:
                return dict(results=results)
Exemple #2
0
        def compute():
            query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
            result = []
            s = query_string.lower().strip()
            for k,v in longstrings.photos.items():
                if k.find(s)!=-1:
                    result.append(InlineQueryResultPhoto(id=k,photo_url=v,thumb_url=v))

            return result
Exemple #3
0
    def compute():
        articles = [InlineQueryResultArticle(
                       id='abc', title='HK', input_message_content=InputTextMessageContent(message_text='Hong Kong'), url='https://www.google.com', hide_url=True),
                   {'type': 'article',
                       'id': 'def', 'title': 'SZ', 'input_message_content': {'message_text': 'Shenzhen'}, 'url': 'https://www.yahoo.com'}]

        photos = [InlineQueryResultPhoto(
                      id='123', photo_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf', thumb_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'),
                  {'type': 'photo',
                      'id': '345', 'photo_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'thumb_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'caption': 'Caption', 'title': 'Title', 'input_message_content': {'message_text': 'Shenzhen'}}]

        results = random.choice([articles, photos])
        return results
	def _build_image_response(self, response):
		results = []
		for it in response["items"]:
			image = it["image"]
			results += [InlineQueryResultPhoto(
					id = self._build_result_id(it["link"]),
					photo_url = it["link"],
					thumb_url = image["thumbnailLink"],
					photo_width = image["width"],
					photo_height = image["height"],
					title = it["title"],
					description = it["snippet"])]
		return results if results else self.RESPONSE_NO_RESULTS
        async def compute_answer():
            query_id, from_id, query_string = telepot.glance(
                msg, flavor='inline_query')

            def get_error_query():
                return [
                    InlineQueryResultArticle(
                        id="latex_start",
                        title='Invalid LaTex',
                        description="Couldn't parse your input.",
                        input_message_content=InputTextMessageContent(
                            message_text=
                            "Sorry, I lost my way around. Didn't mean to send this."
                        ),
                        type='article')
                ]

            if len(msg['query']) < 1:
                results = [
                    InlineQueryResultArticle(
                        id="latex_start",
                        title='Enter LaTeX',
                        description=
                        "Waiting to process your equation. No need to add math mode, "
                        "I'll take care of that.",
                        input_message_content=InputTextMessageContent(
                            message_text=
                            "Sorry, I lost my way around. Didn't mean to send this."
                        ),
                        thumb_url=
                        'http://a1.mzstatic.com/eu/r30/Purple69/v4/b2/f2/92/b2f292f4-a27f'
                        '-7ecc-fa20-19d84095e035/icon256.png',
                        thumb_width=256,
                        thumb_height=256,
                        type='article')
                ]
            else:
                try:
                    jpg_url, width, height = await latex_generator.process(
                        str(msg['from']['id']), msg['query'])
                except UnboundLocalError:  # probably failed to generate file
                    results = get_error_query()
                else:
                    results = [
                        InlineQueryResultPhoto(id='Formatted equation',
                                               photo_url=jpg_url,
                                               thumb_url=jpg_url,
                                               photo_height=height,
                                               photo_width=width)
                    ]
            return results
Exemple #6
0
def inline_photo_from_card(card):
    """Build a InlineQueryResultPhoto from the given card dict."""
    markup_keyboard = InlineKeyboardMarkup(inline_keyboard=[
        [  # looks quite awkward. Is a list of lists for button rows
            InlineKeyboardButton(text=card['name'], url=card['scryfall_uri'])
        ]
    ])

    arguments = dict(id=(card['id']),
                     photo_width=672,
                     photo_height=936,
                     reply_markup=markup_keyboard)
    try:
        yield InlineQueryResultPhoto(**arguments,
                                     photo_url=card['image_uris']['png'],
                                     thumb_url=card['image_uris']['small'])
    except KeyError:
        for face in card['card_faces']:
            args = dict(**arguments,
                        photo_url=face['image_uris']['png'],
                        thumb_url=face['image_uris']['small'])
            args['id'] = ''.join(e for e in f"{card['id']}-{face['name']}"
                                 if e.isalnum())
            yield InlineQueryResultPhoto(**args)
Exemple #7
0
    def compute():
        _, _, query_string = telepot.glance(msg, flavor='inline_query')
        print('Inline Query:', query_string)

        split = query_string.split(' ', 1)
        if len(split) > 1:
            text = u'我可能是%s了假%s' % tuple(split)

            img = Image.open('bg.jpg')
            draw = ImageDraw.Draw(img)
            draw.text((5, 10), text, font=font, fill=(0, 0, 0))

            out = BytesIO()
            img.save(out, format='JPEG')
            out.seek(0)

            r = requests.post('https://ptpb.pw/',
                              files={'c': out},
                              data={'sunset': 120},
                              timeout=5)
            out.close()

            if r.status_code == requests.codes.ok:  # pylint: disable=I0011,E1101
                # print(r.text)
                width, height = img.size
                url = find_between(r.text, 'url: ', '\n')
                resultid = find_between(r.text, 'digest: ', '\n')
                results = [
                    InlineQueryResultPhoto(id=resultid,
                                           photo_url=url,
                                           thumb_url=url,
                                           photo_width=width,
                                           photo_height=height)
                ]
            else:
                threading.currentThread().cancel()
                return
        else:
            results = [
                InlineQueryResultArticle(
                    id='usage',
                    title='使用说明',
                    description='输入"用 机器人"即可生成"我可能是用了假机器人"',
                    input_message_content=InputTextMessageContent(
                        message_text='输入"用 机器人"即可生成"我可能是用了假机器人"'))
            ]

        return (results, 3600 * 2)  # (results, cache_time)
Exemple #8
0
 def compute():
     query_id, from_id, query_string = telepot.glance(msg,
                                                      flavor='inline_query')
     print('Inline Query:', query_id, from_id, query_string)
     reqpost = create_image(query_id, query_string)
     articles = [
         InlineQueryResultPhoto(id=reqpost["name"][0:64],
                                title='AltoEnBot',
                                photo_url=reqpost["img_url"],
                                thumb_url=reqpost["img_url"],
                                photo_width=reqpost["img_width"],
                                photo_height=reqpost["img_height"],
                                caption="Creado con @altoenbot")
     ]
     print reqpost["img_url"]
     return articles
Exemple #9
0
    def compute():
        query_id, from_id, query_string = telepot.glance(msg,
                                                         flavor='inline_query')
        print('Inline Query:', query_id, from_id, query_string)

        meme_parts = query_string.split(':')

        meme_id = keymap[(meme_parts[0].lower()).replace(" ", "")]

        meme_text = meme_parts[1].split('@')

        if len(meme_text) < 2:
            meme_text.append("")

        articles = []

        if meme_id:

            payload = {
                'template_id': meme_id,
                'username': imgflip_login,
                'password': imgflip_login,
                'text0': meme_text[0],
                'text1': meme_text[1]
            }

            r = requests.post(base_url + 'caption_image', data=payload)

            # print r.text

            r = r.json()
            if r['success']:
                url = r["data"]["url"].replace("\\", "")

                # print url

                articles = [
                    InlineQueryResultPhoto(id='abc',
                                           title=query_string,
                                           photo_url=url,
                                           type='photo',
                                           thumb_url=url,
                                           photo_width=100,
                                           photo_height=100)
                ]

        return articles
Exemple #10
0
def answer(msg):
    flavor = telepot.flavor(msg)

    if flavor == 'inline_query':
        query_id, from_id, query = telepot.glance2(msg, flavor=flavor)

        if from_id != USER_ID:
            print('Unauthorized user:'******'InlineQuery')

        articles = [InlineQueryResultArticle(
                       id='abc', title='HK', message_text='Hong Kong', url='https://www.google.com', hide_url=True),
                   {'type': 'article',
                       'id': 'def', 'title': 'SZ', 'message_text': 'Shenzhen', 'url': 'https://www.yahoo.com'}]

        photos = [InlineQueryResultPhoto(
                      id='123', photo_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf', thumb_url='https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'),
                  {'type': 'photo',
                      'id': '345', 'photo_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'thumb_url': 'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd', 'caption': 'Caption', 'title': 'Title', 'message_text': 'Message Text'}]

        results = random.choice([articles, photos])

        yield from bot.answerInlineQuery(query_id, results, cache_time=20, is_personal=True, next_offset='5')

    elif flavor == 'chosen_inline_result':
        result_id, from_id, query = telepot.glance2(msg, flavor=flavor)

        if from_id != USER_ID:
            print('Unauthorized user:'******'ChosenInlineResult')

        print('Chosen inline query:')
        pprint.pprint(msg)

    else:
        raise telepot.BadFlavor(msg)
Exemple #11
0
def compute(inline_query):
    articles = [
        InlineQueryResultArticle(id='abc',
                                 title='HK',
                                 message_text='Hong Kong',
                                 url='https://www.google.com',
                                 hide_url=True), {
                                     'type': 'article',
                                     'id': 'def',
                                     'title': 'SZ',
                                     'message_text': 'Shenzhen',
                                     'url': 'https://www.yahoo.com'
                                 }
    ]

    photos = [
        InlineQueryResultPhoto(
            id='123',
            photo_url=
            'https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf',
            thumb_url=
            'https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'
        ), {
            'type': 'photo',
            'id': '345',
            'photo_url':
            'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd',
            'thumb_url':
            'https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd',
            'caption': 'Caption',
            'title': 'Title',
            'message_text': 'Message Text'
        }
    ]

    results = random.choice([articles, photos])
    return dict(results=results,
                cache_time=20,
                is_personal=True,
                next_offset='5')
Exemple #12
0
async def inline(message, matches, chat_id, step):
    query_id, from_id, query = telepot.glance(message, flavor='inline_query')
    response = requests.get(query)
    soup = BeautifulSoup(response.text, "html.parser")
    image = soup.find("meta", {"property": "og:image"})
    video = soup.find("meta", {"property": "og:video"})
    if video:
        width = soup.find("meta", {"property": "og:video:width"})
        height = soup.find("meta", {"property": "og:video:height"})
        return [
            InlineQueryResultVideo(id=str(uuid.uuid4()),
                                   description='Instagram Video',
                                   title="Instagram Video",
                                   mime_type="video/mp4",
                                   thumb_url=image['content'],
                                   video_url=video['content'],
                                   video_width=int(width['content']),
                                   video_height=int(height['content']))
        ]
    elif image:
        return [
            InlineQueryResultPhoto(id=str(uuid.uuid4()),
                                   title="Instagram Photo",
                                   photo_url=image['content'],
                                   photo_width=300,
                                   photo_height=300,
                                   thumb_url=image['content'])
        ]
    else:
        return [
            InlineQueryResultArticle(
                id=str(uuid.uuid4()),
                title='Error',
                description="Not Found",
                input_message_content=InputTextMessageContent(
                    message_text="لینک اشتباهه 😞",
                    parse_mode="Markdown"),
                thumb_url="http://siyanew.com/bots/custom.jpg")
        ]
Exemple #13
0
def on_inline_query(msg):
    query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
    print ('Inline Query:', query_id, from_id, query_string)

    wikipedia.set_lang("en")
    query_var = wikipedia.search(f'{query_string}')
    query_value = query_var[0]
    query_title = str(query_value)
    zvalue = googlesearch.search(f'{query_string}', lang='en')
    try:
        query_photo_url= zvalue[0]
    except:
        query_photo_url = wikipedia.page(f'{query_string}').url
    try:
        qlan2 = wikipedia.summary(f'{query_title}', sentences=2,auto_suggest=False, redirect=False)
    except:
        qlan2 = wikipedia.summary(f'{query_title}', sentences=2,auto_suggest=True, redirect=True)

    articles = [InlineQueryResultArticle(id='abc',title=f'{query_string}',input_message_content=InputTextMessageContent(message_text=f'{qlan2}'))]
    photos = [InlineQueryResultPhoto(id='12345', photo_url=query_photo_url, thumb_url=query_photo_url)]

    bot.answerInlineQuery(query_id, articles,photos)
Exemple #14
0
    def compute():
        query_id, from_id, query_string = telepot.glance(msg,
                                                         flavor='inline_query')
        print('%s: Computing for: %s' %
              (threading.current_thread().name, query_string))

        articles = [
            InlineQueryResultArticle(
                id='abcde',
                title='🦋Unsplash',
                input_message_content=InputTextMessageContent(
                    message_text=
                    'Unsplash is a website dedicated to sharing stock photography under the Unsplash license. The website claims over 110,000 contributing photographers and generates more than 11 billion photo impressions per month on their growing library of over 1.5 million photos.'
                )),
            dict(
                type='article',
                id='fghij',
                title='🐲Developer',
                input_message_content=dict(
                    message_text=
                    'This bot will help you to download images from unplash.com and also from google data base you can find me on @brows000'
                )),
            dict(
                type='article',
                id='dgsfe',
                title='🧩API',
                input_message_content=dict(
                    message_text=
                    'What is unsplash API? The Unsplash API is a modern JSON API that surfaces all of the info you ll need to build any experience for your users. It"s so simple to use that we even run unsplash.com on it! Get a photo Search photos List new photos.'
                )),
            dict(
                type='article',
                id='fghij',
                title='🔰how does it work',
                input_message_content=dict(
                    message_text=
                    'This bot is download image from specific url you have to send the url first before doing any thing so search image using google or unsplash then send the link and the bot will downlode it also you can forward images with links then the bot will do the rest.'
                ))
        ]

        photo1_url = 'https://images.unsplash.com/photo-1596519115568-19f1bd10afde?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo2_url = 'https://images.unsplash.com/photo-1590893384683-cb427aad218b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo3_url = 'https://images.unsplash.com/photo-1596641314492-dd437d0d5463?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo4_url = 'https://images.unsplash.com/photo-1596880630573-28c5371f7eb1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo5_url = 'https://images.unsplash.com/photo-1596806031968-7ff4df83c356?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo6_url = 'https://images.unsplash.com/photo-1596872595556-2586eeb6982e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo9_url = 'https://images.unsplash.com/photo-1588863746368-508ae44a7917?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo10_url = 'https://images.unsplash.com/photo-1588863746368-508ae44a7917?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo11_url = 'https://images.unsplash.com/photo-1596574620648-98e00b6a09e3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo12_url = 'https://images.unsplash.com/photo-1596718802962-2b4225d41955?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photo13_url = 'https://images.unsplash.com/photo-1596878276931-02dfa8ba94a7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'
        photos = [
            InlineQueryResultPhoto(id='12345',
                                   photo_url=photo1_url,
                                   thumb_url=photo1_url),
            dict(type='photo',
                 id='67890',
                 photo_url=photo2_url,
                 thumb_url=photo2_url),
            dict(type='photo',
                 id='53437',
                 photo_url=photo3_url,
                 thumb_url=photo3_url),
            dict(type='photo',
                 id='51826',
                 photo_url=photo4_url,
                 thumb_url=photo4_url),
            dict(type='photo',
                 id='43433',
                 photo_url=photo5_url,
                 thumb_url=photo5_url),
            dict(type='photo',
                 id='87665',
                 photo_url=photo6_url,
                 thumb_url=photo6_url),
            dict(type='photo',
                 id='54653',
                 photo_url=photo11_url,
                 thumb_url=photo11_url),
            dict(type='photo',
                 id='34524',
                 photo_url=photo10_url,
                 thumb_url=photo10_url),
            dict(type='photo',
                 id='75676',
                 photo_url=photo9_url,
                 thumb_url=photo9_url),
            dict(type='photo',
                 id='63547',
                 photo_url=photo12_url,
                 thumb_url=photo12_url),
            dict(type='photo',
                 id='54527',
                 photo_url=photo13_url,
                 thumb_url=photo13_url),
            dict(type='photo',
                 id='84658',
                 photo_url=inline_url,
                 thumb_url=inline_url)
        ]

        result_type = query_string[-1:].lower()

        if result_type == 'a':
            return articles
        elif result_type == 'p':
            return photos
        else:
            results = articles if random.randint(0, 1) else photos
            if result_type == 'b':
                return dict(results=results,
                            switch_pm_text='Back to Bot',
                            switch_pm_parameter='Optional_start_parameter')
            else:
                return dict(results=results)
Exemple #15
0
    def compute():
        query_id, from_id, query_string = telepot.glance(msg,
                                                         flavor='inline_query')
        print('Inline Query:', query_id, from_id, query_string)

        responses = retrieve_something_from_subreddit(query_string)

        json_data = subprocess.run(
            ["curl", "-XPOST", "-d", gfycat_credentials, gfycat_auth],
            capture_output=True).stdout
        gfycat_bearer = json.loads(json_data)

        count = 0
        for response in responses:
            try:
                urlFormat = response.url[-4:]

                if response.url[:5] == 'https':
                    gfycat = response.url[8:14]
                else:
                    gfycat = response.url[7:13]

                if count == 0:
                    if response.url[-3:] == 'gif' or response.url[
                            -4:] == 'gifv':
                        articles = [
                            InlineQueryResultGif(id=response.id,
                                                 type='gif',
                                                 title=response.title,
                                                 gif_width=10,
                                                 gif_height=10,
                                                 gif_url=response.url,
                                                 thumb_url=response.url)
                        ]
                    elif gfycat == 'gfycat':
                        pos_id = [
                            pos for pos, char in enumerate(response.url)
                            if char == '/'
                        ]
                        gfycat_id = response.url[pos_id[-1] + 1:]

                        json_data = subprocess.run([
                            "curl", "-X", "GET",
                            "https://api.gfycat.com/v1/gfycats/" + gfycat_id,
                            "-H", "Authorization: Bearer " +
                            gfycat_bearer["access_token"]
                        ],
                                                   capture_output=True).stdout
                        gfycat_json = json.loads(json_data)

                        articles = [
                            InlineQueryResultGif(
                                id=response.id,
                                type='gif',
                                title=response.title,
                                gif_width=10,
                                gif_height=10,
                                gif_url=gfycat_json["gfyItem"]["max5mbGif"],
                                thumb_url=gfycat_json["gfyItem"]["max1mbGif"])
                        ]
                    elif response.url[-3:] == 'png' or response.url[
                            -3:] == 'jpg' or (response.url[8:17] == "i.redd.it"
                                              and response.url[-3:] != "gif"):
                        articles = [
                            InlineQueryResultPhoto(id=response.id,
                                                   type='photo',
                                                   photo_url=response.url,
                                                   thumb_url=response.url,
                                                   photo_width=10,
                                                   photo_height=10)
                        ]
                    #elif response.url[8:17] == "v.redd.it":
                    #    articles = [InlineQueryResultVideo(
                    #                    id=response.id,
                    #                    type='video',
                    #                    title=response.title,
                    #                    video_url=response.url,
                    #                    thumb_url=response.url,
                    #                    video_width=50,
                    #                    video_height=50,
                    #                    mime_type='video/mp4'
                    #                )]
                    else:
                        articles = [
                            InlineQueryResultArticle(
                                id=response.id,
                                title=response.title,
                                thumb_url=response.url,
                                input_message_content=InputTextMessageContent(
                                    message_text=response.url +
                                    ' powered by: ' +
                                    response.subreddit_name_prefixed))
                        ]
                    count += 1
                else:
                    if response.url[-3:] == 'gif' or response.url[
                            -4:] == 'gifv':
                        articles += [
                            InlineQueryResultGif(id=response.id,
                                                 type='gif',
                                                 title=response.title,
                                                 gif_width=10,
                                                 gif_height=10,
                                                 gif_url=response.url,
                                                 thumb_url=response.url)
                        ]
                    elif gfycat == 'gfycat':
                        pos_id = [
                            pos for pos, char in enumerate(response.url)
                            if char == '/'
                        ]
                        gfycat_id = response.url[pos_id[-1] + 1:]

                        json_data = subprocess.run([
                            "curl", "-X", "GET",
                            "https://api.gfycat.com/v1/gfycats/" + gfycat_id,
                            "-H", "Authorization: Bearer " +
                            gfycat_bearer["access_token"]
                        ],
                                                   capture_output=True).stdout
                        gfycat_json = json.loads(json_data)

                        articles += [
                            InlineQueryResultGif(
                                id=response.id,
                                type='gif',
                                title=response.title,
                                gif_width=10,
                                gif_height=10,
                                gif_url=gfycat_json["gfyItem"]["max5mbGif"],
                                thumb_url=gfycat_json["gfyItem"]["max1mbGif"])
                        ]
                    elif response.url[-3:] == 'png' or response.url[
                            -3:] == 'jpg' or (response.url[8:17] == "i.redd.it"
                                              and response.url[-3:] != "gif"):
                        articles += [
                            InlineQueryResultPhoto(id=response.id,
                                                   type='photo',
                                                   photo_url=response.url,
                                                   thumb_url=response.url,
                                                   photo_width=10,
                                                   photo_height=10)
                        ]
                    #elif response.url[8:17] == "v.redd.it":
                    #    articles += [InlineQueryResultVideo(
                    #                    id=response.id,
                    #                    type='video',
                    #                    title=response.title,
                    #                    video_url=response.url,
                    #                    thumb_url=response.url,
                    #                    video_width=50,
                    #                    video_height=50,
                    #                    mime_type='video/mp4'
                    #                )]
                    else:
                        articles += [
                            InlineQueryResultArticle(
                                id=response.id,
                                title=response.title,
                                thumb_url=response.url,
                                input_message_content=InputTextMessageContent(
                                    message_text=response.url +
                                    ' powered by: ' +
                                    response.subreddit_name_prefixed))
                        ]
            except Exception as e:
                print("Error at " + response.url)
                print(e)
        return articles
Exemple #16
0
    def compute():

        query_id, from_id, query_string = telepot.glance(msg,
                                                         flavor='inline_query')

        print('%s: Computing for: %s' %
              (threading.current_thread().name, query_string))

        articles = [
            InlineQueryResultArticle(
                id='abcde',
                title='Compartilhe',
                input_message_content=InputTextMessageContent(
                    message_text='Conheca o windows bot @Windows_BetaRoBot')),
            dict(
                type='article',
                id='fghij',
                title='Nosso Grupo',
                input_message_content=dict(
                    message_text=
                    'entre em meu grupo https://t.me/joinchat/D7lDSUQoqgaVljLOpIviHg'
                ))
        ]

        photo1_url = 'https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf'

        photo2_url = 'https://www.telegram.org/img/t_logo.png'

        photos = [
            InlineQueryResultPhoto(id='12345',
                                   photo_url=photo1_url,
                                   thumb_url=photo1_url),
            dict(type='photo',
                 id='67890',
                 photo_url=photo2_url,
                 thumb_url=photo2_url)
        ]

        result_type = query_string[-1:].lower()

        if result_type == 'a':

            return articles

        elif result_type == 'p':

            return photos

        else:

            results = articles if random.randint(0, 1) else photos

            if result_type == 'b':

                return dict(results=results,
                            switch_pm_text='Back to Bot',
                            switch_pm_parameter='Optional start parameter')

            else:

                return dict(results=results)