def default_query(inline_query): allowed_users = AllowedUsers().user_list if (inline_query.query == '' or (allowed_users is not None and inline_query.from_user.username not in allowed_users)): return if inline_query.offset == '': offset = 0 else: offset = int(inline_query.offset) search_term = inline_query.query search_results = google_search(search_term, CSE_KEY, CSE_CX, safe="off", num=BATCH, start=(offset * BATCH) + 1) rs = [] if not search_results: rs.append(types.InlineQueryResultPhoto("1", "https://images-na.ssl-images-amazon.com/images/I/41q1QAln%2BQL._AC_UL320_SR248,320_.jpg", "https://images-na.ssl-images$amazon.com/images/I/41q1QAln%2BQL._AC_UL320_SR248,320_.jpg")) else: try: id = 0 for each in search_results: id += 1 rs.append(types.InlineQueryResultPhoto(str(id), each[0], each[1])) except Exception as e: print(e) bot.answer_inline_query(inline_query.id, rs, cache_time=2592000, next_offset=offset + 1)
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') 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]) 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', input_message_content=types.InputTextMessageContent('hi2')) bot.answer_inline_query(inline_query.id, [r, r2], cache_time=1) except Exception as e: print(e)
def watch_wishlist_inline(chosen_inline_result): """ inline-метод, позволяющий публиковать в чате игры из своего вишлиста :param chosen_inline_result: пустая строка """ print('общий инлайнер') try: with session_scope() as session: wishes = Wish.get_all(user_id=chosen_inline_result.from_user.id, session=session) games = [ Game.get(id=wish.game_id, session=session) for wish in wishes ] bot.answer_inline_query( inline_query_id=chosen_inline_result.id, results=[ types.InlineQueryResultPhoto( id=game.id, title=game.name, photo_url=game.poster_url, thumb_url=game.poster_url, caption=str(game), parse_mode='MARKDOWN', input_message_content=types.InputMediaPhoto( caption=str(game), parse_mode='MARKDOWN', media=get_image_bytes(game.poster_url)), ) for i, game in enumerate( sorted(games, key=lambda x: x.name)) ], switch_pm_text='Добавить игр?', switch_pm_parameter='start') except Exception as e: print(e)
def qq(q): text = q.query r = requests.get('https://api.github.com/users/{}'.format(text)) json_data = r.json() if 'avatar_url' in json_data: url_html = json_data['html_url'] typee = json_data['type'] name = json_data['name'] company = json_data['company'] blog = json_data['blog'] location = json_data['location'] bio = json_data['bio'] public_repos = json_data['public_repos'] followers = json_data['followers'] following = json_data['following'] avatar_url = json_data['avatar_url'] tmp = 'http://ntanjerome.org/wp-content/themes/tanji/images/iconmonstr-github-9-icon.png' gitss = types.InlineQueryResultArticle( '1', 'Git username\xE2\x9C\x8F\xEF\xB8\x8F', types.InputTextMessageContent( 'Name : <b>{}</b>\nUrl : <b>{}</b>\nBlog : <b>{}</b>\nLocation : <b>{}</b>\nBio : <i>{}</i>\n\nRepos : <code>{}</code>\nfollowers : <code>{}</code>\nfollowing : <code>{}</code>' .format(name, url_html, blog, location, bio, public_repos, followers, following), parse_mode="HTML"), thumb_url=tmp) avatarr = types.InlineQueryResultPhoto( '2', '{}'.format(avatar_url), '{}'.format(avatar_url), description='avatar', caption= 'Name : {}\nUrl : {}\nBlog : {}\nLocation : {}\nBio : {}\n\nRepos : {}' .format(name, url_html, blog, location, bio, public_repos)) bot.answer_inline_query(q.id, [gitss, avatarr], cache_time=1)
def inline_query(query): # offset = int(query.offset) if query.offset else 0 try: test_connection() except Exception as ex: print(ex) session.rollback() time.sleep(3) try: images = get_image_by_name(query.from_user.id, query.query) except Exception as IE: print(IE) return if images is None: return images = set(images) ans = [] for item in images: try: ans.append( types.InlineQueryResultPhoto(id=item.id, title=item.thumb_url, photo_url=item.image_url, thumb_url=item.thumb_url)) except Exception as ex: print(ex) # next_offset = offset+1 if ans.__len__() == 5 else offset # print(next_offset) bot.answer_inline_query(query.id, ans, cache_time=False)
def menu(inline_query): r = types.InlineQueryResultPhoto( '1', 'Result1', 'https://raw.githubusercontent.com/ignaciobll/CaFIteriaBot/master/menu.jpg', 'https://raw.githubusercontent.com/ignaciobll/CaFIteriaBot/master/menu.jpg', input_message_content=types.InputTextMessageContent('hi')) bot.answer_inline_query(inline_query.id, [r], cache_time=1)
def image(inline_query): r = types.InlineQueryResultPhoto( id='11', photo_url= 'https://images.assettype.com/swarajya/2020-08/a46bd36a-e65b-4b0b-91d9-c0fcac98c518/telegram.jpg?w=1200&h=800', thumb_url= 'https://images.assettype.com/swarajya/2020-08/a46bd36a-e65b-4b0b-91d9-c0fcac98c518/telegram.jpg?w=1200&h=800' ) bot.answer_inline_query(inline_query.id, [r])
def query_text(inline_query): try: ## '_.-' text = urllib.parse.quote_plus(inline_query.query).replace( ".", "%2E").replace("_", "%5F").replace("-", "%2D") print("Texto: " + text + " id: " + inline_query.id) r = types.InlineQueryResultPhoto( '1', 'http://yourweb.com/image_generator/image.php?frase=' + text, 'http://yourweb.com/image_generator/image.php?frase=' + text) bot.answer_inline_query(inline_query.id, [r]) except Exception as e: print(e)
def titre(query): qid = query.id f = browse.get() p = [] for i, j in enumerate(f): p.append( types.InlineQueryResultPhoto(id=i, photo_url=j, thumb_url=j, photo_width=625, photo_height=469)) bot.answer_inline_query(qid, p, cache_time=1)
def query_text(inline_query): try: media_samples = types.InlineQueryResultPhoto( '3', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg', ) media_samples2 = types.InlineQueryResultPhoto( '4', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg' ) media_samples3 = types.InlineQueryResultVideo( '5', 'https://github.com/eternnoir/pyTelegramBotAPI/blob/master/tests/test_data/test_video.mp4?raw=true', 'video/mp4', 'Video', 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg', 'Title') bot.answer_inline_query(inline_query.id, [media_samples, media_samples2], media_samples3) except Exception as e: print(e)
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): try: user = query.from_user.username name = query.from_user.first_name lname = query.from_user.last_name uid = query.from_user.id info = types.InlineQueryResultArticle( '1', '\xE2\x9C\x8F Your Info \xE2\x9C\x8F', types.InputTextMessageContent( '*Username : @{}\nYour Last Name : {}\nYour Last Name : {}\nYour ID : {}*' .format(user, name, lname, uid), parse_mode="Markdown")) 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( '@Taylor_Team')) bot.answer_inline_query(query.id, [info], cache_time="5") except Exception as user: print(user)
def search_query(query): """The handler for an inline query. Enter your query and choose the image to sending. """ url_list = PictureGrabber.get_inline_img_url(query.query.strip()) if len(url_list) == 0: return result_list = [] try: for pic_id, pic_url in enumerate(url_list): result_list.append( types.InlineQueryResultPhoto(id=pic_id, photo_url=pic_url, thumb_url=pic_url)) bot.answer_inline_query(query.id, result_list) except Exception as err: log.exception(f'Error in inline handler: {type(err)} - {str(err)}')
def query_photo(inline_query): try: r2 = types.InlineQueryResultPhoto( '1', 'http://apod.nasa.gov/apod/image/1601/aurora_vetter_2000.jpg', 'http://apod.nasa.gov/apod/image/1601/aurora_vetter_2000.jpg') r3 = types.InlineQueryResultPhoto( '2', 'http://www.menucool.com/slider/prod/image-slider-5.jpg', 'http://www.menucool.com/slider/prod/image-slider-5.jpg') r4 = types.InlineQueryResultPhoto( '3', 'http://www.w3schools.com/css/img_fjords.jpg', 'http://www.w3schools.com/css/img_fjords.jpg') r5 = types.InlineQueryResultPhoto( '4', 'https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/idcs1426.jpg?itok=Gc_-Q58L', 'https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/idcs1426.jpg?itok=Gc_-Q58L' ) r6 = types.InlineQueryResultPhoto( '5', 'http://static1.squarespace.com/static/553a8716e4b0bada3c80ca6b/553a9655e4b03939abece18a/5731fc75f85082142b12b095/1462893710445/mayfourblocknature.jpg', 'http://static1.squarespace.com/static/553a8716e4b0bada3c80ca6b/553a9655e4b03939abece18a/5731fc75f85082142b12b095/1462893710445/mayfourblocknature.jpg' ) r7 = types.InlineQueryResultPhoto( '6', 'https://i.kinja-img.com/gawker-media/image/upload/s--BVBooEGz--/c_scale,fl_progressive,q_80,w_800/vjamorotezzukhdvpccc.jpg', 'https://i.kinja-img.com/gawker-media/image/upload/s--BVBooEGz--/c_scale,fl_progressive,q_80,w_800/vjamorotezzukhdvpccc.jpg' ) r8 = types.InlineQueryResultPhoto( '7', 'http://www.planwallpaper.com/static/images/beautiful-sunset-images-196063.jpg', 'http://www.planwallpaper.com/static/images/beautiful-sunset-images-196063.jpg' ) r9 = types.InlineQueryResultPhoto( '8', 'https://upload.wikimedia.org/wikipedia/commons/0/00/Center_of_the_Milky_Way_Galaxy_IV_%E2%80%93_Composite.jpg', 'https://upload.wikimedia.org/wikipedia/commons/0/00/Center_of_the_Milky_Way_Galaxy_IV_%E2%80%93_Composite.jpg' ) r10 = types.InlineQueryResultPhoto( '9', 'http://s3.freefoto.com/images/9912/01/9912_01_4132_web.jpg', 'http://s3.freefoto.com/images/9912/01/9912_01_4132_web.jpg') r11 = types.InlineQueryResultPhoto( '10', 'http://www.spyderonlines.com/images/wallpapers/nature-image/nature-image-1.jpg', 'http://www.spyderonlines.com/images/wallpapers/nature-image/nature-image-1.jpg' ) r12 = types.InlineQueryResultPhoto( '11', 'https://cdn.eso.org/images/large/eso1209a.jpg', 'https://cdn.eso.org/images/large/eso1209a.jpg') r13 = types.InlineQueryResultPhoto( '12', 'https://upload.wikimedia.org/wikipedia/commons/9/98/UNF_Ospreys_logo.png', 'https://upload.wikimedia.org/wikipedia/commons/9/98/UNF_Ospreys_logo.png' ) bot.answer_inline_query( inline_query.id, [r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13], cache_time=1) except Exception as e: print(e)
def search_game_from_store(inline_query): """ inline-метод, который позволяет искать игры в PSN :param inline_query: текст """ def has_sale_price(game_data: dict): """ Возвращает True, если на игру действует скидка :param game_data: :return: """ logger.info('') try: return game_data['default_sku']['rewards'][0] is not None except Exception: return False logger.info('inline: start') psn_url = f'https://store.playstation.com/store/api/chihiro/00_09_000/tumbler/ru/ru/999/' \ f'{quote(inline_query.query)}?size=5&start=0&gameContentType=bundles&platform=ps4' logger.info(psn_url) search_data = get(psn_url).json() try: games = [{ 'name': game['name'], 'url': f'''https://store.playstation.com/ru-ru/product/{game['id']}''', 'price': game['default_sku']['display_price'], 'sale_price': game['default_sku']['rewards'][0]['bonus_price'] // 100 if has_sale_price(game) else None, 'valid_until': game['default_sku']['rewards'][0]['end_date'] if has_sale_price(game) else None, 'img_url': game['images'][0]['url'] } for game in search_data['links']] bot.answer_inline_query( inline_query_id=inline_query.id, results=[ types.InlineQueryResultPhoto( id=i, title=game['name'], photo_url=game['img_url'], thumb_url=game['img_url'], caption=f'''[{game['name']}]({game['url']}): ''' + (f'''~~{game['price']}~~ {game['sale_price']} till {game['valid_until']}''' \ if game['sale_price'] else f'''{game['price']}'''), parse_mode='MARKDOWN', input_message_content=types.InputMediaPhoto(caption=str(game), parse_mode='MARKDOWN', media=get_image_bytes(game['img_url'])), ) for i, game in enumerate(games) ], switch_pm_text='Добавить игр?', switch_pm_parameter='start' ) except Exception as e: print(e)
data = r.read() pjson = json.loads(data) title = pjson['Title'] year = pjson['Year'] runtime = pjson['Runtime'] genre = pjson['Genre'] language = pjson['Language'] poster = pjson['Poster'] urllib.request.urlretrieve(poster, 'imdb.jpg') resultcap = """Movie name : {} Year of action : {} Movie time : {} Movie sort : {} Language : {}""".format(title, year, runtime, genre, language) result = types.InlineQueryResultPhoto(poster, caption=resultcap) bot.answer_inline_query(m.id, result, cache_time=1) except KeyError: bot.answer_inline_query(m.id, 'Error') @bot.message_handler(commands=['id', 'ids', 'info', 'me']) def id(m): # info menu cid = m.chat.id title = m.chat.title usr = m.chat.username f = m.chat.first_name l = m.chat.last_name t = m.chat.type d = m.date text = m.text p = m.pinned_message
def query_text(inline_query): text = inline_query.query # The text input by the user, where @bot_name [text] is this text offset = inline_query.offset # Checks if there is any offset by the query if offset == '': # If there's no offset off_set = 0 else: # If there's a offset off_set = int(offset) try: if off_set == 0: # All of this is just to work with the API f = 0 # There's nothing really to explain, as it else: # is complicated to me to do so. f = off_set load = Img.search_query( text, pid=int(f)) # Loads a json object with the query nload = len(load) # calculates how much data there's in load if nload == 0: # if there's no data in 'load' msg = """ _Looks like you tried some tag combinations that didn't work properly..._ _But don't worry! just try up another tag combination!_ """ key = types.InlineKeyboardMarkup(row_width=2) k1 = types.InlineKeyboardButton("📢My Channel!", url='t.me/emaproject') k2 = types.InlineKeyboardButton("👁🗨@HαlksNET", url='t.me/halksnet') key.row(k1, k2) fgw = types.InlineQueryResultArticle( '1', 'Nothing here but my cookies!', types.InputTextMessageContent(msg, parse_mode='markdown'), reply_markup=key, description='Looks like you tried some tag combinations that...' ) bot.answer_inline_query(inline_query.id, [fgw]) if text.startswith( "id:" ): # If the query starts with 'id:', which means it came from a "Share" instance result = [] file = load[0]['file_url'] # File url id = load[0]['id'] # File unique identifier in the server dirc = load[0][ 'directory'] # Directory where it is stored in the server hash = load[0]['hash'] # The hash string provided by the server thumb = "http://gelbooru.com/thumbnails/{0}/thumbnail_{1}.jpg".format( dirc, hash) # A complicated thumbnail # builder tags = load[0]["tags"].split() # Splits the tags in a list tags1 = tags[0] # These are just tags2 = tags[1] # to load up to tags3 = tags[2] # three tags kb = types.InlineKeyboardMarkup(row_width=2) kb1 = types.InlineKeyboardButton(text="💾 Download", url=file) kb2 = types.InlineKeyboardButton( text="🔍 Search more", switch_inline_query_current_chat="{0} {1} {2}".format( tags1, tags2, tags3)) kb.row(kb1, kb2) if file.endswith('.gif'): # if the file is a gif gif = types.InlineQueryResultGif( '1', file, file, caption='🔖id: {id}\n'.format(id=id), reply_markup=kb) result.append(gif) # inserts the object in the cache database else: # if the file is any type of image pic = types.InlineQueryResultPhoto( '1', file, thumb, caption='🔖id: {id}\n'.format(id=id), reply_markup=kb) result.append(pic) # inserts the object in the cache database bot.answer_inline_query(inline_query.id, result, is_personal=True) else: # if it is a normal query cache_list = [] # This is the cache database the bot will send af = 0 for i in load: # this 'for' loop inserts on the 'cache_list' up to 50 objects for the query result file = i['file_url'] # file url id = i['id'] # File unique identifier in the server dirc = i[ 'directory'] # Directory where it is stored in the server hash = i['hash'] # The hash string provided by the server thumb = "http://gelbooru.com/thumbnails/{0}/thumbnail_{1}.jpg".format( dirc, hash) # again, the odd # thumbnail stuff kb = types.InlineKeyboardMarkup(row_width=2) kb1 = types.InlineKeyboardButton(text="💾 Download", url=file) kb2 = types.InlineKeyboardButton( text="🔍 Search more", switch_inline_query_current_chat=text) kb.row(kb1, kb2) if file.endswith('.gif'): # if the file is gif gif = types.InlineQueryResultGif( str(int(af)), file, thumb_url=file, caption='🔖id: {id}\n'.format(id=id), reply_markup=kb) cache_list.append(gif) # inserts the object in the cache else: # if the file is any type of image pic = types.InlineQueryResultPhoto( str(int(af)), file, thumb_url=thumb, caption='🔖id: {id}\n'.format(id=id), reply_markup=kb) cache_list.append(pic) # inserts the object in the cache af += 1 # Number of id to be sent to Telegram Server b = 1 + off_set # Complicated stuff, this is for the offset bot.answer_inline_query(inline_query.id, cache_list, next_offset=b, cache_time=120, switch_pm_text="Usage help", switch_pm_parameter="tags") except Exception as e: msg = """ _Looks like you tried some tag combinations that didn't work properly..._ _But don't worry! just try up another tag combination!_ """ key = types.InlineKeyboardMarkup(row_width=2) k1 = types.InlineKeyboardButton("📢My Channel!", url='t.me/emaproject') k2 = types.InlineKeyboardButton("👁🗨@HαlksNET", url='t.me/halksnet') key.row(k1, k2) fgw = types.InlineQueryResultArticle( '1', 'Nothing here but my cookies!', types.InputTextMessageContent(msg, parse_mode='markdown'), reply_markup=key, description='Looks like you tried some tag combinations that...') bot.answer_inline_query(inline_query.id, [fgw]) print( "An error occurred with the query '{0}':".format( inline_query.query), e) pass