def pictoInline(bot, update): query = update.inline_query.query if not query: return results = list() picto_list = getListPictos(['ES', 'EN', 'FR', 'IT', 'DE', 'CA'], query, force="false") if picto_list != []: for picto in picto_list: results.append( telegram.InlineQueryResultPhoto( id=picto_list.index(picto), title=picto['name'], photo_url=picto['imagePNGURL'], thumb_url=picto['thumbnailURL'], caption=picto['name'], input_message_content=telegram.InputTextMessageContent( picto['imagePNGURL']))) else: results.append( telegram.InlineQueryResultPhoto( id=0, title="UPPSSS", photo_url= "http://www.arasaac.org/repositorio/originales/5526.png", thumb_url= "http://www.arasaac.org/repositorio/originales/5526.png", caption="No pictogram were found", input_message_content=telegram.InputTextMessageContent( "No pictogram found"))) bot.answerInlineQuery(update.inline_query.id, results)
def inlinequery(update, context): """Handle the inline query.""" query = update.inline_query.query url = "https://db.ygoprodeck.com/api/v7/cardinfo.php?fname=" + query + "&language=" + lang page = requests.get(url) if page.status_code == 200: card_src = json.loads(page.text) results = [] for index, name in enumerate(card_src['data'], start=0): if index == 48: break caption = caption_gen(name) caption_trunc = (caption[:1024] + '...') if len(caption) > 1024 else caption results.append( telegram.InlineQueryResultPhoto( type="photo", id=uuid4(), photo_url=name['card_images'][0]['image_url'], thumb_url=name['card_images'][0]['image_url_small'], title=name['name'], description=caption_trunc, caption=caption_trunc, parse_mode='MarkdownV2')) update.inline_query.answer(results)
def inline_query(bot, update): query = update.inline_query.query key_word = query.split()[0] if not re.search(r"\d", key_word): briefs = Functions.search_by_actress(key_word, 20) else: briefs = [Functions.get_brief(key_word)] if not briefs: return results = [ telegram.InlineQueryResultPhoto( uuid4(), brief.preview_img_url, brief.preview_img_url, caption="\n".join( filter(lambda x: x, (brief.code, brief.title, brief.actress)))) for brief in briefs ] update.inline_query.answer(results)
def handle_inline(self, bot, context: Context): query = context.query if context.update.inline_query.offset != "": offset = int(context.update.inline_query.offset) else: offset = 0 try: res: octobot.Catalog = self.function(query, offset, 50, bot, context) except CatalogCantGoDeeper: return if res is None: return inline_res = [] for item in res: if item.photo is not None: if item.parse_mode is None or item.parse_mode.lower( ) != "html": item.parse_mode = 'html' item.text = html.escape(item.text) text = add_photo_to_text(item.text, item.photo) res_kwargs = dict(id=item.item_id, photo_url=item.photo[0].url, photo_width=item.photo[0].width, photo_height=item.photo[0].height, thumb_url=item.photo[-1].url, title=item.title, description=item.description, reply_markup=item.reply_markup) if res.photo_primary: res_kwargs['caption'] = text res_kwargs['parse_mode'] = item.parse_mode else: res_kwargs[ 'input_message_content'] = telegram.InputTextMessageContent( text, parse_mode=item.parse_mode) if isinstance(item, octobot.CatalogKeyPhoto): inline_res.append( telegram.InlineQueryResultPhoto(**res_kwargs)) else: inline_res.append( telegram.InlineQueryResultArticle(**res_kwargs)) else: inline_res.append( telegram.InlineQueryResultArticle( item.item_id, title=item.title, description=item.description, input_message_content=telegram.InputTextMessageContent( item.text, parse_mode=item.parse_mode))) context.update.inline_query.answer( inline_res, cache_time=(360 if Settings.production else 0), next_offset=res.next_offset)
def inline(bot, update): print('received inline query for "' + update.inline_query.query + '"') cards = fetch_inline(update.inline_query.query) results = [ telegram.InlineQueryResultPhoto( id=hex(random.getrandbits(64))[2:], photo_url=c['full'], thumb_url=c['thumb'], title='test', description='test', photo_width=488, photo_height=680, caption="[" + c['name'] + "](" + c['url'] + ")", parse_mode=telegram.ParseMode.MARKDOWN) for c in cards ] bot.answerInlineQuery(update.inline_query.id, results=results)
def inlineR(update, context): query = update.inline_query.query results = [] try: images = subredditImg(query, count=40) except Exception: results.append( tg.InlineQueryResultArticle(0, "No", tg.InputTextMessageContent("No!"))) else: if len(images) == 0: results.append(tg.InlineQueryResultArticle( 0, "No", "No!", )) else: for img in images: results.append(tg.InlineQueryResultPhoto(img, img, img)) finally: update.inline_query.answer(results)