def query_text(query): kb = types.InlineKeyboardMarkup() # Добавляем колбэк-кнопку с содержимым "test" kb.add(types.InlineKeyboardButton(text="Нажми меня", callback_data="test")) results = [] single_msg = types.InlineQueryResultArticle( id="1", title="Press me", input_message_content=types.InputTextMessageContent( message_text="Я – сообщение из инлайн-режима"), reply_markup=kb) results.append(single_msg) bot.answer_inline_query(query.id, results)
def query_text(query): print(query) try: res = str(int(query.query) ** 2) r = types.InlineQueryResultArticle( id='1', title="Square", description="Result: {0}".format(res), input_message_content=types.InputTextMessageContent( message_text="Square of {0} is {1}".format(query.query, res)) ) bot.answer_inline_query(query.id, [r]) except Exception as e: print(e)
def query_text(inline_query): try: logger.debug(inline_query) send_name, from_id = get_sender_name_and_id(inline_query) greetings_type = get_time_type() update_user(from_id, send_name, greetings_type) if greetings_type == "睡觉" or greetings_type == "晚安": update_user(from_id, send_name, greetings_type) greetings_type = "晚安" message_text = "[{send_name}](tg://user?id={from_id}) 向 大家 道 {txt}~".format( send_name=send_name, from_id=from_id, txt=greetings_type ) inline_greeting_results = types.InlineQueryResultArticle( "1", "向大家问好", types.InputTextMessageContent( message_text, parse_mode="Markdown") ) if len(inline_query.query) != 0: if inline_query.query[0] == "@": inline_greeting_results_text = "{send_name} 向 {reply_name} 道 {txt}~".format( send_name=send_name, reply_name=inline_query.query, txt=greetings_type ) inline_greeting_results_with_someone = types.InlineQueryResultArticle( "2", "向{reply_name}问好".format( reply_name=inline_query.query), types.InputTextMessageContent(inline_greeting_results_text), ) bot.answer_inline_query( inline_query.id, [inline_greeting_results, inline_greeting_results_with_someone], cache_time=0, is_personal=False, ) else: bot.answer_inline_query( inline_query.id, [inline_greeting_results], cache_time=0, is_personal=False ) except Exception as exception: logger.error(exception)
def query_text(query): kb = types.InlineKeyboardMarkup() kb.add(types.InlineKeyboardButton(text="Нажми меня", callback_data="test")) results = [] # Обратите внимание: вместо текста - объект input_message_content c текстом! single_msg = types.InlineQueryResultArticle( id="1", title="Press me", input_message_content=types.InputTextMessageContent( message_text="Я – сообщение из инлайн-режима"), reply_markup=kb) results.append(single_msg) bot.answer_inline_query(query.id, results)
def empty_query(query): hint = "Введите ровно 2 числа и получите результат!" try: r = types.InlineQueryResultArticle( id='1', # parse_mode='Markdown', title="Бот \"Математика\"", description=hint, input_message_content=types.InputTextMessageContent( message_text="Эх, зря я не ввёл 2 числа :(")) bot.answer_inline_query(query.id, [r]) except Exception as e: print(e)
def query_text(inline_query): try: message_text_prepared = inline_query.query.strip() if message_text_prepared!='': god_mode = inline_query.from_user.id==106129214 answer = calcubot_eval(CALCUBOT_SCRIPT_PATH,True,inline_query.query,god_mode,CALCUBOT_WORDS) calcubot.answer_inline_query(inline_query.id, answer) else: answer = ['Empty expression..'] responce = [types.InlineQueryResultArticle('result', answer[0], types.InputTextMessageContent( answer[0] ))] calcubot.answer_inline_query(inline_query.id, responce) except Exception as e: print(str(e))
def on_integer_overflow(query: types.InlineQuery): r = types.InlineQueryResultArticle( id='1', title=localization['inline_mode']['integer_overflow']['title'], description=localization['inline_mode']['integer_overflow'] ['description'], input_message_content=types.InputTextMessageContent( message_text=localization['inline_mode']['integer_overflow'] ['message_text']), thumb_url=localization['inline_mode']['integer_overflow']['thumb_url']) bot.answer_inline_query(query.id, [r], cache_time=environ.get('INLINE_QUERY_CACHE_TIME'))
def query_text(query): hint = "Enter some number!" try: r = types.InlineQueryResultArticle( id='1', title="John bot", description=hint, input_message_content=types.InputTextMessageContent( message_text="Calculating square") ) bot.answer_inline_query(query.id, [r]) except Exception as e: print(e)
def battle_query_inline(q): # print("battle_query_inline") # print(q) user = User(q.from_user.id, q.from_user.first_name, q.from_user.username) log.debug("%s is trying to create battle check" % user) if not hlp.IsUserAdmin(user): # non-admins cannot post votes log.error("Failed (not an admin)") hlp.SendHelpNonAdmin(q) bot.answer_callback_query(q.id) return res, time, comment = hlp.IsCheckTimeQuery(q) if res: if hlp.CanStartNewBattle() or hlp.CanStopCurrentBattle(): # stop current battle as the time is passed anyway # to help admin not doing exact battle stop but start another with auto-stopping the previous if hlp.CanStopCurrentBattle(): q.data = kb.CHECK_CONTROL_OPTIONS[2] q.inline_message_id = common.current_battle.check_id battle_control(q) desc = ICON_CHECK + ICON_RAGE + ICON_FAST + ICON_ARS + ICON_THINK + ICON_CANCEL if comment: desc += "\n" + comment res = types.InlineQueryResultArticle( 'battle', title='[%s] Создать чек на бой' % time, description=desc, input_message_content=types.InputTextMessageContent( ICON_SWORDS + " *Бой*: %s" % time, parse_mode="markdown"), thumb_url="https://i.ibb.co/jb9nVCm/battle.png", reply_markup=kb.KEYBOARD_CHECK) bot.answer_inline_query(q.id, [res], is_personal=True, cache_time=2) else: log.error( "Trying to setup another battle while current is not finished") error_text = "Уже имеется активный бой в %0.2d:%0.2d" % ( *common.current_battle.GetTime(start=True), ) bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2, switch_pm_text=error_text, switch_pm_parameter="existing_battle") else: log.error("Failed (invalid query)") error_text = "Неверный формат запроса" bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2, switch_pm_text=error_text, switch_pm_parameter="existing_battle")
def func_for(arrayGroupsIn): arrayGroupsOut = [] for i in range(0, len(arrayGroupsIn)): date = datetime.datetime.today() strOut = jsonFormatter.search_by_group_and_date( arrayGroupsIn[i], jsonFormatter.week_to_string(date.weekday())) out = types.InlineQueryResultArticle( id=f'{(i+1)}', title=arrayGroupsIn[i], description='Расписание на текущий день.', input_message_content=types.InputTextMessageContent( message_text=strOut)) arrayGroupsOut.append(out) return arrayGroupsOut
def arsenal_query_inline(q): # print("arsenal_query_inline") # print(q) user = User(q.from_user.id, q.from_user.first_name, q.from_user.username) log.debug("%s is trying to create arsenal check" % user) if not hlp.IsUserAdmin(user): # non-admins cannot post votes log.error("Failed (not an admin)") hlp.SendHelpNonAdmin(q) bot.answer_callback_query(q.id) return if hlp.CanStartNewBattle(): log.error("Trying to setup arsenal check with no current battle") error_text = "Отсутствует активный бой" bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2, switch_pm_text=error_text, switch_pm_parameter="existing_battle") return res, time = hlp.IsArsQuery(q) if res: if hlp.CanStartNewArs(): res = types.InlineQueryResultArticle( 'arsenal', title='Добавить прогресс арсенала', description=ICON_ARS + ' |████--| Х/120\nЯрость в %s' % time, input_message_content=types.InputTextMessageContent( ICON_ARS + " *Прогресс арсенала:* 0/120", parse_mode="markdown"), thumb_url="https://i.ibb.co/WfxPRks/arsenal.png", reply_markup=kb.KEYBOARD_ARS) bot.answer_inline_query(q.id, [res], is_personal=True, cache_time=2) else: log.error( "Trying to setup another arsenal check while current has not been fired" ) error_text = "Уже имеется активный чек арсенала" bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2, switch_pm_text=error_text, switch_pm_parameter="existing_arsenal") else: bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2, switch_pm_text="Неверный формат запроса", switch_pm_parameter="existing_arsenal")
def query_text(query): #botan.track(config.botan_key, query.from_user.id, {}, 'inline запрос') kb = types.InlineKeyboardMarkup() # Добавляем колбэк-кнопку с содержимым "test" kb.add(types.InlineKeyboardButton(text="Нажми меня", callback_data="test")) results = [] single_msg = types.InlineQueryResultArticle( id="1", title="Press me", input_message_content=types.InputTextMessageContent( message_text="Решил проверить, что я умею?)"), reply_markup=kb) results.append(single_msg) bot.answer_inline_query(query.id, results)
def query_text(query): data = apiparser.search(query.query) if data: r_inf = [] for i in range(5) if len(data) > 5 else range(len(data)): org = data[i] r_inf.append( types.InlineQueryResultArticle( id=i, title=org['inn'], description=org['name'] if 'name' in org else org['fullName'], input_message_content=types.InputTextMessageContent( message_text=org['inn'], parse_mode='markdown'))) bot.answer_inline_query(query.id, r_inf) else: r_inf = types.InlineQueryResultArticle( id=1, title='', description="Ничего не найдено", input_message_content=types.InputTextMessageContent( message_text=query.query, parse_mode='markdown')) bot.answer_inline_query(query.id, [r_inf])
def query_text(query): if query.query != '': text = query.query search = api + urllib.parse.quote_plus(text.lower()) response = requests.get(search) a = response.json()['list'][0]['definition'] r_sum = types.InlineQueryResultArticle( id='1', title="Result", description="Запрос: {!s}".format(a), input_message_content=types.InputTextMessageContent( message_text=a)) k = False bot.answer_inline_query(query.id, [r_sum])
def query_air(inline_query): try: places_air = [ types.InlineQueryResultArticle( f'{k}', k, description='качество воздуха', input_message_content=types.InputTextMessageContent( weather.get_air_quality(k, v.lat, v.lon)[1])) for k, v in content.places.items() ] bot.answer_inline_query(inline_query.id, places_air, cache_time=3000) except Exception as e: logger.error(e)
def show_keyboard(query): keyboard = types.InlineKeyboardMarkup() for key in bot.get_query_history(query.from_user.id): keyboard.add( types.InlineKeyboardButton(text=f'[{datetime.fromtimestamp(key[2])}] {key[1]}', callback_data=key[1]) ) table = [] msg = types.InlineQueryResultArticle( id='1', title='История поиска', input_message_content=types.InputTextMessageContent(message_text='История поиска:'), reply_markup=keyboard ) table.append(msg) bot.answer_inline_query(query.id, table)
def empty_query(query): hint = "Введите ровно 2 числа и получите результат!" try: r = types.InlineQueryResultArticle( id='1', parse_mode='Markdown', title="Бот \"Математика\"", description=hint, # Текст сообщения, которое будет выводиться при нажатии на подсказку input_message_content=types.InputTextMessageContent( message_text="Эх, зря я не ввёл 2 числа :(")) bot.answer_inline_query(query.id, [r], cache_time=86400) except Exception as e: print(e)
def query_text(query): user = query.from_user.username name = query.from_user.first_name lname = query.from_user.last_name uid = query.from_user.id markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton('\xE2\x9C\x85 {} \xE2\x9C\x85'.format(user), url="https://telegram.me/{}".format(user))) thumb_url = 'http://millingtonlibrary.info/wp-content/uploads/2015/02/Info-I-Logo.png' info = types.InlineQueryResultArticle('1', '\xF0\x9F\x8C\x8E Your Info \xF0\x9F\x8C\x8E', types.InputTextMessageContent('*Username : @{}\nYour First Name : {}\nYour Last Name : {}\nYour ID : {}*'.format(user,name,lname,uid), parse_mode="Markdown"), reply_markup=markup, thumb_url=thumb_url) #pic = types.InlineQueryResultPhoto('2', #'http://vip.opload.ir/vipdl/95/3/negative23/photo-2016-06-09-01-09-41.jpg', #'http://vip.opload.ir/vipdl/95/3/negative23/photo-2016-06-09-01-09-41.jpg', #input_message_content=types.InputTextMessageContent('@TeamTop') #gif = types.InlineQueryResultGif('2', # 'http://andrewtrimmer.com/wp-content/uploads/2014/09/Coming-Soon_Light-Bulbs_Cropped-Animation-Set_03c.gif', #'http://andrewtrimmer.com/wp-content/uploads/2014/09/Coming-Soon_Light-Bulbs_Cropped-Animation-Set_03c.gif', #gif_width=70, #gif_height=40, #title="Soon Update", # input_message_content=types.InputTextMessageContent('New Update #Soon')) tumsss = 'http://images.clipartpanda.com/contact-clipart-contact-phone-md.png' random_text = random.randint(1, 100) tmpp = 'http://sugartin.info/wp-content/uploads/2013/11/logo.png' randowm = types.InlineQueryResultArticle('2', '\xD8\xB9\xD8\xAF\xD8\xAF\x20\xD8\xB4\xD8\xA7\xD9\x86\xD8\xB3\xDB\x8C\x20\xF0\x9F\x99\x88', types.InputTextMessageContent('\xD8\xB9\xD8\xAF\xD8\xAF\x20\xD8\xB4\xD8\xA7\xD9\x86\xD8\xB3\xDB\x8C : {}'.format(random_text)), thumb_url=tmpp) url = req.get('http://api.gpmod.ir/time/') data = url.json() EN = data['ENtime'] time_tmp = 'http://prek-8.com//images/time21.jpg' timesend = types.InlineQueryResultArticle('3', 'Time / \xD8\xB3\xD8\xA7\xD8\xB9\xD8\xAA', types.InputTextMessageContent('`Tehran` : *{}*'.format(EN), parse_mode='Markdown'), thumb_url=time_tmp) bot.answer_inline_query(query.id, [info, randowm, timesend], cache_time=5, switch_pm_text='Start bot')
def empty_query(query: types.InlineQuery): u_id = query.from_user.id api_url = environ.get('API_URL') res = graphql_request(api_url, telegramToUserId.format(u_id), telegram_id=u_id) if res.get('errors', None): on_inline_not_registered(query) return internal_id = res['data']['telegramToUserId'] res = graphql_request(api_url, profile.format(internal_id), telegram_id=u_id)['data']['user'] money = res['money'] balance = types.InlineQueryResultArticle( id='1', title=localization['inline_mode']['balance']['title'].format(money), description=localization['inline_mode']['balance']['description'], input_message_content=types.InputTextMessageContent( message_text=localization['inline_mode']['balance'] ['message_text'].format(money)), thumb_url=localization['inline_mode']['balance']['thumb_url']) instructions = types.InlineQueryResultArticle( id='2', title=localization['inline_mode']['empty']['title'], description=localization['inline_mode']['empty']['description'], input_message_content=types.InputTextMessageContent( message_text=localization['inline_mode']['empty']['message_text']), thumb_url=localization['inline_mode']['empty']['thumb_url']) bot.answer_inline_query(query.id, [balance, instructions], cache_time=environ.get('INLINE_QUERY_CACHE_TIME'))
def query_text(inline_query): try: url = 'http://www.omdbapi.com/?s=' + inline_query.query r = requests.get(url) json_object = r.json() parsed_data = json.dumps(json_object) search_list = json.loads(parsed_data) show_list = [] if search_list["Response"] == 'True': xd = search_list['Search'] for result in xd: idfilm = result['imdbID'] picfilm = result['Poster'] title = result['Title'] if picfilm == 'N/A': title = title.replace(" ", "+") picfilm = 'https://placeholdit.imgix.net/~text?txtsize=90&bg=ffffff&txt=' + title + '&w=512&h=512&fm=jpg&txttrack=0.jpg' url = 'http://www.omdbapi.com/?i=' + idfilm r = requests.get(url) json_object = r.json() parsed_data = json.dumps(json_object) lol = json.loads(parsed_data) capfilm = 'Title: ' + ( lol["Title"]) + '\n' + '\n' + 'IMDb: ' + ( lol["imdbRating"] ) + '/10 (' + lol[ "imdbVotes"] + ' votes)' + '\n' + 'Metacritic: ' + ( lol["Metascore"]) result = types.InlineQueryResultPhoto(idfilm, picfilm, picfilm, caption=capfilm) show_list.append(result) else: r = types.InlineQueryResultArticle( '1', 'Content not found in IMDb!', types.InputTextMessageContent('Content not found in IMDb!')) bot.answer_inline_query(inline_query.id, [r]) bot.answer_inline_query(inline_query.id, show_list, cache_time=1) except Exception as e: print("Exception: ", str(e))
def query_text(query): if isinstance(query.query, str): decoded = change_layout(query.query) r = types.InlineQueryResultArticle( id='1', title="Decoded", description=decoded, input_message_content=types.InputTextMessageContent( message_text=decoded)) else: r = types.InlineQueryResultArticle(id='1', title="Error") bot.answer_inline_query(query.id, [r])
def query_text(query): kb = types.InlineKeyboardMarkup() kb.add(types.InlineKeyboardButton(text="", callback_data="test")) results = [] cache_time = 0 rrr = random.randrange(1, 101, 1) rrrstr = 'I am ' + str(rrr) + '% python!' tyan = 'Tyanochku by' single_msg = types.InlineQueryResultArticle( id="1", title="How python are You?", input_message_content=types.InputTextMessageContent(message_text = rrrstr), reply_markup=kb ) results.append(single_msg) bot.answer_inline_query(query.id, results, cache_time=0)
def add_knopka(self, id, thumb_url, title, price, size): r1 = types.InlineQueryResultArticle( id=id, thumb_url=thumb_url, title=title, description=f'{size}\nЦена {price} ₽', input_message_content=types.InputTextMessageContent( message_text=f"{title}" f"\n{size}\n{price} ₽\n\n" f'Добавки:\nНичего не выбрано' f'\n\nЦена {price} ₽' f"[\xa0]({thumb_url})", parse_mode='Markdown'), reply_markup=mark_up.num_markup1()) return r1
def empty_query(query): try: r = types.InlineQueryResultArticle( id='1', title=settings.KINOHODBOT_NAME, description=settings.FILM_PREVIEW_SHORT, input_message_content=types.InputTextMessageContent( message_text=settings.TEXT_INLINE_EMPTY, parse_mode='Markdown' ) ) # bot_inline.answer_inline_query(query.id, [r], cache_time=CASHE_TIME) except Exception as e: print(e)
def query_photo(inline_query): try: r = types.InlineQueryResultPhoto( '1', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg', input_message_content=types.InputTextMessageContent('hi')) r2 = types.InlineQueryResultPhoto( '2', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg' ) bot.answer_inline_query(inline_query.id, [r, r2], cache_time=1) except Exception as e: print(e)
def empty_query(query): hint = 'Afloat query to support memes movement! Type Kappa until it is too late!' try: q = types.InlineQueryResultArticle( id='0', title='Meme Master', description=hint, input_message_content=types.InputTextMessageContent( message_text= "I'd like you to type Kappa, please. That's what this query is solely about." )) bot.answer_inline_query(query.id, [q], cache_time=3600) except Exception as e: print(e)
def query_text(inline_query): try: print(inline_query) send_name, from_id = get_sender_name_and_id(inline_query) txt = get_time() if txt == "睡觉": txt = "晚安" txt1 = "[{send_name}](tg://user?id={from_id}) 向 大家 道 {txt}~".format( send_name=send_name, from_id=from_id, txt=txt) greeting1 = types.InlineQueryResultArticle( "1", "向大家问好", types.InputTextMessageContent(txt1, parse_mode="Markdown")) if len(inline_query.query) != 0: if inline_query.query[0] == "@": txt2 = "{send_name} 向 {reply_name} 道 {txt}~".format( send_name=send_name, reply_name=inline_query.query, txt=txt) greeting2 = types.InlineQueryResultArticle( "2", "向{reply_name}问好".format( reply_name=inline_query.query), types.InputTextMessageContent(txt2), ) bot.answer_inline_query( inline_query.id, [greeting1, greeting2], cache_time=0, is_personal=False, ) else: bot.answer_inline_query(inline_query.id, [greeting1], cache_time=0, is_personal=False) except Exception as e: print(e)
def inline_query(query): try: chat_id = query.from_user.id num = 1 mark_up.update_key(chat_id, 'num', num) if query.query == 'Кофе': dbworker.set_state(str(chat_id), '2') r = mark_up.cofe_finish(atr='cofe') bot.answer_inline_query(query.id, r, cache_time=0, is_personal=True) if query.query == 'изменить': lots = db_users.change_lot(chat_id) r = [] for lot in lots: id_id = lot[0] a = json.loads(lot[1]) num = a['num'] price = a['price'] dobavka = 'Ничего не выбрано' if a['dobavka'] == ' ' else a[ 'dobavka'] price_dobavka = a['price_dobavka'] size = a['size'] markup = mark_up.top_markup(num) input_content = types.InputTextMessageContent( message_text=f"№{str(id_id)}. {a['name_lot']}" f"\n{size}\n{price} ₽\n\n" f'Добавки:\n{dobavka}' f'\n\nЦена {str((price + price_dobavka ) * num)} ₽' f"[\xa0]({a['pic']})", parse_mode='Markdown') r2 = types.InlineQueryResultArticle( id=str(id_id), thumb_url=a['pic'], title=a['name_lot'], description= f'{size}\n{num} шт.\n{str((price + price_dobavka ) * num)} ₽', input_message_content=input_content, reply_markup=markup) r.append(r2) dbworker.set_state(str(chat_id), 'change') bot.answer_inline_query(query.id, r, cache_time=0, is_personal=True) except Exception as e: print(e)
def query_weather(inline_query): try: places_weather = [ types.InlineQueryResultArticle( f'{k}', k, description='погода сейчас', input_message_content=types.InputTextMessageContent( weather.get_weather(k, v.lat, v.lon))) for k, v in content.places.items() ] bot.answer_inline_query(inline_query.id, places_weather, cache_time=3000) except Exception as e: logger.error(e)
def query_text(query): # func=lambda query: len(query.query) > 0 # https://groosha.gitbook.io/telegram-bot-lessons/chapter7 words = db.get_words(query.from_user.id) answer_list = [ types.InlineQueryResultArticle( id=str(i), title=word['word'], description=word['definition'], input_message_content=types.InputTextMessageContent( message_text=f'*{word["word"]}* - {word["definition"]}', parse_mode='markdown')) for i, word in enumerate(words) ] bot.answer_inline_query(query.id, answer_list, cache_time=1)