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 inline_rate(bot, update): query = update.inline_query.query query_list = query.split(" ") results = list() parser_classes = utils.get_parser_classes() parsers = [parser(cache=default_cache) for parser in parser_classes] for parser in parsers: # Best exchange rate in inline mode # TODO: write wrapper function to handle inputs like this one if len(query_list) == 2 and "best" in query_list: # TODO: this feature is experimental and # not-optimized at all, it is SLOW # Mutating original list is not a great ideas temp_list = query_list[:] temp_list.remove("best") currency = temp_list[0] if currency.upper() not in parser.allowed_currencies: continue best = utils.get_best_currencies(currency) buy_msg = _("Buy {}: <b>{}</b> - {}") buy_msg = buy_msg.format(best["buy"][1].iso, best["buy"][0], best["buy"][1].buy) # TODO: add allignment sell_msg = _("Sell {}: <b>{}</b> - {}") sell_msg = sell_msg.format(best["sell"][1].iso, best["sell"][0], best["sell"][1].sell) msg = "\n".join([buy_msg, sell_msg]) res = telegram.InputTextMessageContent( msg, parse_mode=telegram.ParseMode.HTML) result = telegram.InlineQueryResultArticle( id=uuid.uuid4(), title=_("Best rate"), input_message_content=res) bot.answerInlineQuery(update.inline_query.id, [result]) return if query.upper() not in parser.allowed_currencies: continue cur_value = cache_proxy.get_currency(parser, query.upper()) bank_name = parser.name text = "{}\n<b>{}</b>: {}".format(bank_name, query.upper(), cur_value.sell) mes_content = telegram.InputTextMessageContent( text, parse_mode=telegram.ParseMode.HTML) result = telegram.InlineQueryResultArticle( id=uuid.uuid4(), title=parser.name, input_message_content=mes_content) results.append(result) bot.answerInlineQuery(update.inline_query.id, 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 setUp(self): self.id = 'id' self.type = 'contact' self.phone_number = 'phone_number' self.first_name = 'first_name' self.last_name = 'last_name' self.thumb_url = 'thumb url' self.thumb_width = 10 self.thumb_height = 15 self.input_message_content = telegram.InputTextMessageContent('input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup([[ telegram.InlineKeyboardButton('reply_markup') ]]) self.json_dict = { 'id': self.id, 'type': self.type, 'phone_number': self.phone_number, 'first_name': self.first_name, 'last_name': self.last_name, 'thumb_url': self.thumb_url, 'thumb_width': self.thumb_width, 'thumb_height': self.thumb_height, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def setUp(self): self.id = 'id' self.type = 'document' self.document_url = 'document url' self.title = 'title' self.caption = 'caption' self.mime_type = 'mime type' self.description = 'description' self.thumb_url = 'thumb url' self.thumb_width = 10 self.thumb_height = 15 self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'id': self.id, 'type': self.type, 'document_url': self.document_url, 'title': self.title, 'caption': self.caption, 'mime_type': self.mime_type, 'description': self.description, 'thumb_url': self.thumb_url, 'thumb_width': self.thumb_width, 'thumb_height': self.thumb_height, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def setUp(self): self.id = 'id' self.type = 'venue' self.latitude = 'latitude' self.longitude = 'longitude' self.title = 'title' self._address = 'address' # nose binds self.address for testing self.foursquare_id = 'foursquare id' self.thumb_url = 'thumb url' self.thumb_width = 10 self.thumb_height = 15 self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'id': self.id, 'type': self.type, 'latitude': self.latitude, 'longitude': self.longitude, 'title': self.title, 'address': self._address, 'foursquare_id': self.foursquare_id, 'thumb_url': self.thumb_url, 'thumb_width': self.thumb_width, 'thumb_height': self.thumb_height, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def setUp(self): self.id = 'id' self.type = 'article' self.title = 'title' self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.url = 'url' self.hide_url = True self.description = 'description' self.thumb_url = 'thumb url' self.thumb_height = 10 self.thumb_width = 15 self.json_dict = { 'type': self.type, 'id': self.id, 'title': self.title, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), 'url': self.url, 'hide_url': self.hide_url, 'description': self.description, 'thumb_url': self.thumb_url, 'thumb_height': self.thumb_height, 'thumb_width': self.thumb_width }
def setUp(self): self._id = 'id' self.type = 'mpeg4_gif' self.mpeg4_url = 'mpeg4 url' self.mpeg4_width = 10 self.mpeg4_height = 15 self.mpeg4_duration = 1 self.thumb_url = 'thumb url' self.title = 'title' self.caption = 'caption' self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'type': self.type, 'id': self._id, 'mpeg4_url': self.mpeg4_url, 'mpeg4_width': self.mpeg4_width, 'mpeg4_height': self.mpeg4_height, 'mpeg4_duration': self.mpeg4_duration, 'thumb_url': self.thumb_url, 'title': self.title, 'caption': self.caption, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def setUp(self): self.id = 'id' self.type = 'location' self.latitude = 'latitude' self.longitude = 'longitude' self.title = 'title' self.thumb_url = 'thumb url' self.thumb_width = 10 self.thumb_height = 15 self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'id': self.id, 'type': self.type, 'latitude': self.latitude, 'longitude': self.longitude, 'title': self.title, 'thumb_url': self.thumb_url, 'thumb_width': self.thumb_width, 'thumb_height': self.thumb_height, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def handle_inline_spoiler(update: tg.Update, context: tg_ext.CallbackContext): query = update.inline_query.query if (len(query) < 1): return quotes = [ "That's not a prediction. That's a Spoiler...", "Spoiler, we die in the end...", "Is it a Spoiler? I don't know... Im not a car guy.", "How do I Spoil?", "Random quote? Nope - just a Spoiler.", "Experience is a gread Spoiler of pleasures.", "You see, but you do not observe. The Spoiler is clear.", "Chewbacca dies, but the real Spoiler is below.", "Spoiler ahead, everyone aboard!", "Spoiler warning" ] results = [ tg.InlineQueryResultArticle( id=uuid.uuid4(), title="Send", input_message_content=tg.InputTextMessageContent( message_text=random.choice(quotes)), reply_markup=tg.InlineKeyboardMarkup(inline_keyboard=[[ tg.InlineKeyboardButton(text='Show me', callback_data=query) ]])) ] update.inline_query.answer(results=results)
def makeres(gt): gameid = str(uuid.uuid4().hex)[:8] butts = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton(text = "Join", switch_inline_query_current_chat = "join " + gameid)]]) return telegram.InlineQueryResultArticle(id= str(gt) + "_" + str(gameid), title= "Create new *" + str(gt) + "*", reply_markup = butts, input_message_content = telegram.InputTextMessageContent(message_text="Play a game of *" + gt + "* with me!", parse_mode="Markdown"))
def to_result(self): return t.InlineQueryResultArticle( id=uuid4(), title=self.title, input_message_content=t.InputTextMessageContent( self.text, 'HTML' ), )
def add_inline_result(self): result = telegram.InlineQueryResultArticle( id=uuid4(), title=self.inline_title, input_message_content=telegram.InputTextMessageContent( self.message), reply_markup=telegram.InlineKeyboardMarkup(self.keyboard), url="", description="") self.inline_results.append(result)
def strikethrough(): text = strike_text(query) desc = text results.append( tg.InlineQueryResultArticle( id=uuid4(), title='Strikethrough', description=desc, input_message_content=tg.InputTextMessageContent( text, parse_mode=tg.ParseMode.MARKDOWN)))
def get_inline_result(self): """ Content that users will send to others to allow them to cast votes """ return telegram.InlineQueryResultDocument(id=self.id, title=self.question, description=("live ranked-pairs poll" if self.live_results else "ranked-pairs poll with results at end") + "\n" + " / ".join(self.options), input_message_content=telegram.InputTextMessageContent(message_text=self.get_html_repr(), parse_mode=telegram.ParseMode.HTML), reply_markup=self.get_public_buttons(), mime_type="application/zip", document_url=DM_URL) # URL actually only used to generate the preview
def markdown_prev(): text = query desc = text results.append( tg.InlineQueryResultArticle( id=uuid4(), title='Markdown (Preview)', description=desc, input_message_content=tg.InputTextMessageContent( text, parse_mode=tg.ParseMode.MARKDOWN, disable_web_page_preview=False)))
def vaporwave(): text = '' for i in list(query): text += chr(0xFEE0 + ord(i)) desc = text results.append( tg.InlineQueryResultArticle( id=uuid4(), # seriously, if this is overused, it should be removed # IGNORE THIS LINE title='Vaporwave', description=desc, input_message_content=tg.InputTextMessageContent(text)))
def subs(): subs_used = sub_all.findall(query) # list of subs used in query text = query desc = ', '.join(subs_used) for sub in subs_used: text = subs_re[sub].sub(subs_dict[sub], text, count=1) if subs_used: results.append( tg.InlineQueryResultArticle( id=uuid4(), title='xxSubs', # desc is all instances that were substituted description=desc, input_message_content=tg.InputTextMessageContent(text))) else: results.append( tg.InlineQueryResultArticle( id=uuid4(), title='/subs', # desc is all instances that were substituted description='Gives a list of substitutions.', input_message_content=tg.InputTextMessageContent('/subs')))
def vortaro(): nonlocal query nonlocal results if query: if query.startswith('v: '): query = query[3:] matches = search_espdic(query) if 'matches' in locals(): exact, fuzzy = matches matches = exact + fuzzy matches = matches[:tg.constants.MAX_INLINE_QUERY_RESULTS] # reset results to only show dictionary entries results = list() for match in matches: results.append( tg.InlineQueryResultArticle( id=uuid4(), title=match['eo'], description=match['en'], input_message_content=tg.InputTextMessageContent( '*{}*: _{}_'.format(match['eo'], match['en']), parse_mode=tg.ParseMode.MARKDOWN))) if not 'matches' in locals() or not matches: usage = [ 'Por serĉi la Esperanto-angla vortaro: `v: <vorto>`', 'To search the Esperanto-English dictionary: `v: <vorto>`', 'Iksa sistemo uzeblas. / X-system is usable.', ] results.append( tg.InlineQueryResultArticle( id=uuid4(), title='Vortaro / Dictionary', description='v: <vorto | word>', input_message_content=tg.InputTextMessageContent( '\n'.join(usage), parse_mode=tg.ParseMode.MARKDOWN)))
def generate_inline_answer(self, text): "Generates inline 'buttons' via so-called article buttons." ret = [] # generated text - everything for the two variants msgs = (self.convert(text), self.convert_no_spaces(text)) for t, d, m, i in zip(self.titles, self.descs, msgs, self.imgs): # first we indicate we use markdown in message that will be sent r = telegram.InputTextMessageContent(m, parse_mode="Markdown") # then we generate result with that message and strings set above result = telegram.InlineQueryResultArticle(id=t, title=t, description=d, input_message_content=r, thumb_url=i) ret.append(result) return ret
def setUp(self): self.id = 'id' self.type = 'sticker' self.sticker_file_id = 'sticker file id' self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'type': self.type, 'id': self.id, 'sticker_file_id': self.sticker_file_id, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def get_inline_query_definition_result( definition: complete_definition.CompleteDefinition ) -> telegram.InlineQueryResultArticle: reply_markup = telegram.InlineKeyboardMarkup( definition.inline_keyboard_buttons) return telegram.InlineQueryResultArticle( id=str(uuid.uuid4()), title=definition.title, thumb_url=constants.DEX_THUMBNAIL_URL, url=definition.url, hide_url=True, reply_markup=reply_markup, input_message_content=telegram.InputTextMessageContent( message_text=definition.html, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True))
def handle_inline_query(update: tg.Update, context: tg_ext.CallbackContext): from bot.inline import CallbackCommands query = update.inline_query.query results = [ tg.InlineQueryResultArticle( id=uuid.uuid4(), title="Send", input_message_content=tg.InputTextMessageContent( message_text='Spoiler'), reply_markup=tg.InlineKeyboardMarkup(inline_keyboard=[[ tg.InlineKeyboardButton( text='Show', callback_data=json.dumps( [CallbackCommands.DISPLAY_SPOILER, query])) ]])) ] update.inline_query.answer(results=results)
def setUp(self): self._id = 'id' self.type = 'audio' self.audio_file_id = 'audio file id' self.caption = 'caption' self.input_message_content = telegram.InputTextMessageContent('input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'type': self.type, 'id': self._id, 'audio_file_id': self.audio_file_id, 'caption': self.caption, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def inline_query_handler(bot, update): query = update.inline_query.query inline_query_id = update.inline_query.id if len(query) < 3: bot.answerInlineQuery(inline_query_id, []) return query_result = table.scan( FilterExpression=Attr('first_name').contains(query.upper()) | Attr('last_name').contains(query.upper()))['Items'] query_articles = list( map( lambda x: telegram.InlineQueryResultArticle( x['username'], '%s %s' % (x['first_name'] or '', x['last_name'] or ''), telegram.InputTextMessageContent('%s %s' % (x['first_name'], x[ 'last_name']))), query_result)) bot.answerInlineQuery(inline_query_id, query_articles)
def setUp(self): self.id = 'id' self.type = 'voice' self.voice_url = 'voice url' self.title = 'title' self.voice_duration = 'voice_duration' self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'type': self.type, 'id': self.id, 'voice_url': self.voice_url, 'title': self.title, 'voice_duration': self.voice_duration, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
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)
def inlineQuery(update): projectId = update.inline_query.query print(projectId) response = requests.get("https://chamranteam.ir/api/project_name/{}".format(projectId)) if response.status_code == 200: projectInfo = response.json() if projectInfo['creator_photo'] is not "None": projectInfo['creator_photo'] = "https://chamranteam.ir" + projectInfo['creator_photo'] query = update.inline_query.query results = [ telegram.InlineQueryResultArticle( id=uuid4(), title=projectInfo['creator'], description=projectInfo['project_name'], thumb_url=projectInfo['creator_photo'], input_message_content=telegram.InputTextMessageContent( projectInfo['project_name'])),] update.inline_query.answer(results, cache_time=15) else: print(response.json()) return
def setUp(self): self.id = 'id' self.type = 'document' self.document_file_id = 'document file id' self.title = 'title' self.caption = 'caption' self.description = 'description' self.input_message_content = telegram.InputTextMessageContent( 'input_message_content') self.reply_markup = telegram.InlineKeyboardMarkup( [[telegram.InlineKeyboardButton('reply_markup')]]) self.json_dict = { 'id': self.id, 'type': self.type, 'document_file_id': self.document_file_id, 'title': self.title, 'caption': self.caption, 'description': self.description, 'input_message_content': self.input_message_content.to_dict(), 'reply_markup': self.reply_markup.to_dict(), }
def find_posts(regex, entries=None): lastLink = None links = [] counter = 1 if entries: for entry in entries: title = entry['title'] desc = entry['description'] link = entry['link'] mt = re.search(regex, title, flags=re.I) md = desc if desc == None else re.search(regex, desc, flags=re.I) if mt or md: content = telegram.InputTextMessageContent(link) links.append(InlineQueryResultArticle(str(counter), title, content, url=link, description=desc, thumb_url=thumb_url_sample)) counter += 1 if counter > 50: break else: links = response_sample return links[0:50]