def default_query(inline_query: types.InlineQuery): Message = str(inline_query.query) def DisplayArgs(args): Return = [] for value, arg in enumerate(args): Return.append( InlineQueryResultArticle( id=value, title=arg, input_message_content=InputTextMessageContent(arg))) return Return #Ничего не написано if Message == "": Bot.answer_inline_query( inline_query.id, [command.ResultArticle for command in COMMAND_LIST]) #Начал писать что то либо else: Commands = Message.lower().split(" ") SeemIt = [ command for command in COMMAND_LIST if command.name.lower().startswith(Commands[0]) ] #Проверяет закончилась ли название команды if len(SeemIt) == 1 and SeemIt[0].name == Commands[0]: command = SeemIt[0] for LEN in range(0, len(Commands) - 1, 1): # Первый параметр try: ArgSeemLike = [ arg for arg in command.args[LEN] if arg.lower().startswith(Commands[LEN + 1]) ] Bot.answer_inline_query(inline_query.id, DisplayArgs(ArgSeemLike)) except: Bot.answer_inline_query(inline_query.id, [ InlineQueryResultArticle( id=0, title="Команда завершена", input_message_content=InputTextMessageContent( "Отправить команду типа")) ]) #Нет не закончилось так что продолжает показывать правильное написание команды else: Bot.answer_inline_query(inline_query.id, [ InlineQueryResultArticle( id=0, title=command.name, input_message_content=InputTextMessageContent( command.output), description=command.description) for command in SeemIt ])
def product_inline(query): category = Category.objects.get(id=query.query.split('_')[1]) resultes = [] for product in category.get_products(): kb = InlineKeyboardMarkup() button = [ InlineKeyboardButton(text=' + Добавить в корзину', callback_data=f'producttocar_{product.id}') ] kb.add(*button) if int(product.discount_price) < int(product.price): price = f'Акционное предложение: {round((int(product.discount_price)/int(product.price)-1)*100)} % \n {product.discount_price} (Старая цена: {product.price})' else: price = product.price result1 = InlineQueryResultArticle( id=str({product.id}), title=f'{product.title}', description=f'Цена: {price}', thumb_url=f'{product.url_image}'.split(' ')[0], reply_markup=kb, input_message_content=InputTextMessageContent( parse_mode='HTML', disable_web_page_preview=False, message_text= f"<b>{product.title}</b> \n {product.description} \n <b>Цена: {price}</b><a href='{str(product.url_image).split(' ')[0]}'>‌</a>" )) resultes.append(result1) bot.answer_inline_query(query.id, resultes)
def str_nums_and_spec(length: int, lang_code: str) -> InlineQueryResultArticle: return InlineQueryResultArticle( uuid4().hex, get_translated_message('inline_str_nums_and_specs', lang_code=lang_code), InputTextMessageContent(generate_str_nums_and_spec(length)), thumb_url=str_nums_and_spec_pic_url )
def only_numbers(length: int, lang_code: str) -> InlineQueryResultArticle: return InlineQueryResultArticle( uuid4().hex, get_translated_message('inline_only_int', lang_code=lang_code), InputTextMessageContent(generate_only_numbers(length)), thumb_url=only_numbers_pic_url )
def search_response(self, user, text): search = SearchManager(user_id=user.id).get() results = [] if search: jobs = JobManager(user_id=user.id).get_vacations(search) markup = InlineKeyboardMarkup() markup.add( InlineKeyboardButton(text='◀️ Назад', switch_inline_query_current_chat='#jobs')) for job in jobs: text = f'<b>{job.looking_for}</b>\n\n' \ f'<b>Зарплата:</b> {job.wage}\n\n' \ f'<b>Город:</b> ' \ f'{job.city if job.city else "Отдаленная работа"}\n\n' \ f'<b>Опыт работы:</b> {job.experience}\n\n' \ f'<b>Описание вакансии:</b> {job.description}\n\n' \ f'<b>Написать работодателю:</b> {job.write_to_employer}' # noqa results.append( InlineQueryResultArticle( id=job.id, title=job.looking_for, description= f'{job.wage}\n{job.city if job.city else "Отдаленная работа"}', # noqa input_message_content=InputTextMessageContent( message_text=text, parse_mode='HTML'), thumb_url= 'https://telegra.ph/file/c5edf06f95fc5e4bda351.jpg', # noqa thumb_height=30, thumb_width=30, reply_markup=markup)) if results: return self.answer_inline_query(results=results)
def DisplayArgs(args): Return = [] for value, arg in enumerate(args): Return.append( InlineQueryResultArticle( id=value, title=arg, input_message_content=InputTextMessageContent(arg))) return Return
def response(inline_query): """Тестовая инлайновая команда, бесполезная""" results = [ InlineQueryResultArticle('1', 'Тестовый заголовок', InputTextMessageContent("Тестовый текст"), reply_markup=TEST_KEYBOARD) ] answer_inline(inline_query.id, results=results, cache_time=1)
def inline_share_list(lists, me): result = [ *(InlineQueryResultArticle( id=list_.id, title=list_.name, input_message_content=InputTextMessageContent( _("Subscribe to my list {}").format(list_.name)), reply_markup=subscribe_btn(list_.id, me)) for list_ in lists), ] return result
def bot_inline_hand(query: InlineQuery): # inline search track_inline(query.from_user.id, query, 'inline_search') user = User.get_user(query.from_user.id) books = Book.books_by_title(query.query, user) if not books: bot.answer_inline_query(query.id, [ InlineQueryResultArticle( '1', 'Книги не найдены!', InputTextMessageContent('Книги не найдены!')) ]).wait() return book_index = 1 result = list() for book in books[0:min(len(books) - 1, 50 - 1)]: result.append( InlineQueryResultArticle( str(book_index), book.title, InputTextMessageContent(book.to_share_book(), parse_mode='HTML', disable_web_page_preview=True))) book_index += 1 bot.answer_inline_query(query.id, result).wait()
def inline_search(inline_query): key = InlineKeyboardMarkup() channel = InlineKeyboardButton('Перейти бот', url='http://t.me/burgertestbegybot') key.add(channel) products_array = [] products = Product.objects.all() for all in products: inline = InlineQueryResultArticle(all.pk, all.name, InputTextMessageContent(all.name), reply_markup=key) products_array.append(inline) bot.answer_inline_query(inline_query.id, products_array)
def answer_alias(inline_query): username = inline_query.from_user.username myid = inline_query.from_user.id alias_article = InlineQueryResultArticle( id='0', title='Send my nombEr', description='press to me FASST!!!!!', input_message_content=InputTextMessageContent( message_text=f'You`r ali: @{username}')) bot.answer_inline_query(inline_query_id=inline_query.id, results=[alias_article], cache_time=0, switch_pm_parametr='', switch_pm_text='Go to me')
def generate_markup(): variants = [] for num, item in enumerate(AVAILABLE_VARIANTS.items()): k, v = item head = HEAD * v tail = TAIL response = '{}{}'.format(head, tail) variants.append( InlineQueryResultArticle(str(num), k, InputTextMessageContent(response))) return variants
def generate_inline_videos_results(search_results): results = [] for item_num, search_item in enumerate(search_results): item = InlineQueryResultArticle( id=item_num, title=search_item.name, description=search_item.type, input_message_content=InputTextMessageContent( message_text=search_item.caption, parse_mode='HTML' ), thumb_url=search_item.thumbnail ) results.append(item) return results
def bot_inline_share( query: InlineQuery): # share book to others user with use inline query track_inline(query.from_user.id, query, 'share_book') book_id = int(query.query.split('_')[1]) book = Book.book_by_id(book_id) if book is None: return bot.answer_inline_query(query.id, [ InlineQueryResultArticle( '1', 'Поделиться', InputTextMessageContent(book.to_share_book(), parse_mode='HTML', disable_web_page_preview=True), ) ]).wait()
def inline_query_weekday_schedule_handler(inline_query): user = g.current_tbot_user for_date = nf.get_date_by_weekday_title(inline_query.query.title()) answer = user.create_answer_for_date(for_date) r = InlineQueryResultArticle(id="{0}_{1}".format(user.id, for_date), title=answer.split("\n\n")[0], input_message_content=InputTextMessageContent( answer, parse_mode="HTML"), description=user.get_current_status_title()) bot.answer_inline_query(inline_query_id=inline_query.id, results=[r], cache_time=1, is_personal=True)
def inline_query(self, query): data = query.query.lstrip() results = [] if self.mac_addr is not None and self.name is not None: print("\"%s\"" % data) users = Person.select().where(Person.name.contains(data)) for user in users: results.append( InlineQueryResultArticle( id=user.name, title=user.name, input_message_content=InputTextMessageContent( user.name))) return results
def answer_alias_query(inline_query): username=inline_query.from_user.username fforward_from=inline_query.from_user alias_artice=InlineQueryResultArticle( id='0', title='Кто я такой?', description='Я такой кто?', input_message_content=InputTextMessageContent( message_text="Имя: "+fforward_from.first_name+"\nФамилия: "+fforward_from.last_name+"\nID: "+str(fforward_from.id)+"\nUsername: "******"Кто он?", switch_pm_parameter="", cache_time=0 )
def answer_alias_query(inline_query): username = inline_query.from_user.username alias_article = InlineQueryResultArticle( id='0', title='Отправить мой алиас', description='Отправить свой алиас в чат!', input_message_content=InputTextMessageContent( message_text=f'Мой алиас: @{username}' ) ) bot.answer_inline_query( switch_pm_text = '1', switch_pm_parameter = '1', inline_query_id=inline_query.id, results=[alias_article], cache_time=0 )
def inline_search_results(search_results): results = [] if search_results: for item_num, search_item in enumerate(search_results): if search_item.media_type == MediaType.PERSON: replay_markup = markup_util.get_person_inline_search_result_markup(search_item) else: replay_markup = markup_util.get_inline_general_search_result_markup(search_item) item = InlineQueryResultArticle( id=search_item.id, title=search_item.shorten_title, description=search_item.description, reply_markup=replay_markup, input_message_content=InputTextMessageContent( message_text=search_item.caption, parse_mode='HTML' ), thumb_url=search_item.poster_url ) results.append(item) return results
def inline_query_weekday_schedule_handler(inline_query): user_id = inline_query.from_user.id week_day = inline_query.query.title() day_date = func.get_day_date_by_weekday_title(week_day) json_day = func.get_json_day_data(user_id, day_date) full_place = func.is_full_place(user_id) answer = func.create_schedule_answer(json_day, full_place, user_id) group_info = func.get_current_group(user_id) week_num = (datetime.today() + server_timedelta).isocalendar()[1] r = InlineQueryResultArticle( id="{0}_{1}_{2}_{3}".format(user_id, group_info[0], week_num, week_day_number[week_day]), title=answer.split("\n\n")[0], input_message_content=InputTextMessageContent( answer, parse_mode="HTML" ), description=group_info[1] ) bot.answer_inline_query(inline_query.id, [r], cache_time=1, is_personal=True)
def query_text(inline_query): r = InlineQueryResultArticle('1', 'Подтвердить', InputTextMessageContent('Подтверждаю'), thumb_url=THUMB_URL) bot.answer_inline_query(inline_query.id, results=[r])
def ResultArticle(self) -> InlineQueryResultArticle: return InlineQueryResultArticle( id=self.ID, title=self.name, input_message_content=InputTextMessageContent(self.output), description=self.description)