def test_InlineQueryResultCachedPhoto_with_markup(): markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid', title='Title', reply_markup=markup) json_str = iq.to_json() assert 'aa' in json_str assert 'Fileid' in json_str assert 'Title' in json_str assert 'caption' not in json_str assert 'reply_markup' in json_str
def inline_coin_flipping(query): lg.language = find_language(query.from_user.id) if query.query.lower() == 'c' or query.query.lower() == 'с': cf_img = "AgACAgIAAxkBAAMMXsGMo98G4qKKKji8dOKncgABIkk7AAJArjEbZxsJSoAjAwAB6dfQzUxoyw4ABAEAAwIAA20AA5nIBQABGQQ" coin_flip_inline_kb_update() coin_flipping = types.InlineQueryResultCachedPhoto( id="1", photo_file_id=cf_img, caption=lg.coin_flipping_inline_description[lg.language], reply_markup=coin_flip_inline_kb, parse_mode=telegram.ParseMode.MARKDOWN_V2 ) bot.answer_inline_query(query.id, [coin_flipping], cache_time=1)
def empty_query(query): try: array = [] query_sql = db.select([photos]) ResultProxy = connection.execute(query_sql) ResultSet = ResultProxy.fetchall() # Result of query for i in ResultSet: array.append( types.InlineQueryResultCachedPhoto(id=i.id, photo_file_id=i.file_id, parse_mode='Markdown')) bot.answer_inline_query(query.id, array, cache_time=2) except Exception as e: print(e)
def inline_mode(query): try: exact_memes = postgres.get_memes_by_name(query.query) memes = postgres.get_memes_by_tag(query.query) if (exact_memes is not None): memes.append(exact_memes) i = 0 result = [] for mem in memes: result.append( types.InlineQueryResultCachedPhoto(id=i, photo_file_id=mem)) i += 1 bot.answer_inline_query(query.id, result, cache_time=10) except Exception as e: print(e)
def empty_query(query): hint = "Enter name or tag for search meme: " memes = postgres.get_last_memes() i = 0 try: result = [] for mem in memes: result.append( types.InlineQueryResultCachedPhoto(id=i, description=hint, photo_file_id=mem)) i += 1 bot.answer_inline_query(query.id, result, cache_time=10) except Exception as e: print(e)
def query_text(inline_query): tex_command = inline_query.query try: lat_str, size, error = parse_command(tex_command) if len(error) != 0: plt.close() plt.clf() r = types.InlineQueryResultArticle('1', 'Ошибка в конвертации', types.InputTextMessageContent("Ошибка в конвертации.")) bot.answer_inline_query(inline_query.id, [r]) return fig = plt.gca(frame_on=False) fig.axes.get_xaxis().set_visible(False) fig.axes.get_yaxis().set_visible(False) if len(lat_str) > 10: plt.close() plt.clf() r = types.InlineQueryResultArticle('1', 'Ошибка, выражение слишком длинное.', types.InputTextMessageContent("Ошибка, выражение слишком длинное.")) bot.answer_inline_query(inline_query.id, [r]) return for id, lat in enumerate(lat_str): hor_pos = 0.5 vert_pos = 1 / (2 * min(len(lat_str), 10)) * (2 * (min(len(lat_str), 10) - id % 10) - 1) if len(lat) != 0: plt.text(hor_pos, vert_pos, lat, fontsize=size, horizontalalignment='center', verticalalignment='center') filename = 'converted' + str(inline_query.id) + '.png' plt.savefig(filename) plt.clf() plt.close() photo_id = bot.send_photo('267362684', open(filename, 'rb')).photo[0].file_id r = types.InlineQueryResultCachedPhoto(id=0, photo_file_id=photo_id) bot.answer_inline_query(inline_query.id, [r], cache_time=1) except Exception as e: print(e) plt.clf() plt.close()
def test_InlineQueryResultCachedPhoto(): iq = types.InlineQueryResultCachedPhoto('aaa', 'Fileid') json_str = iq.to_json() assert 'aa' in json_str assert 'Fileid' in json_str assert 'caption' not in json_str