def location_inline_result(doc: Document) -> InlineQueryResultLocation: content = doc.content return InlineQueryResultLocation( id=doc.internal_id, latitude=content['latitude'], longitude=content['longitude'], title=doc.keywords, horizontal_accuracy=content.get('horizontal_accuracy'), )
def test_equality(self): a = InlineQueryResultLocation(self.id_, self.longitude, self.latitude, self.title) b = InlineQueryResultLocation(self.id_, self.longitude, self.latitude, self.title) c = InlineQueryResultLocation(self.id_, 0, self.latitude, self.title) d = InlineQueryResultLocation('', self.longitude, self.latitude, self.title) e = InlineQueryResultVoice(self.id_, '', '') assert a == b assert hash(a) == hash(b) assert a is not b assert a == c assert hash(a) == hash(c) assert a != d assert hash(a) != hash(d) assert a != e assert hash(a) != hash(e)
def inline_query_result_location(): return InlineQueryResultLocation(TestInlineQueryResultLocation.id, TestInlineQueryResultLocation.latitude, TestInlineQueryResultLocation.longitude, TestInlineQueryResultLocation.title, live_period=TestInlineQueryResultLocation.live_period, thumb_url=TestInlineQueryResultLocation.thumb_url, thumb_width=TestInlineQueryResultLocation.thumb_width, thumb_height=TestInlineQueryResultLocation.thumb_height, input_message_content=TestInlineQueryResultLocation.input_message_content, reply_markup=TestInlineQueryResultLocation.reply_markup)
def inline_query_result_location(): return InlineQueryResultLocation( TestInlineQueryResultLocation.id_, TestInlineQueryResultLocation.latitude, TestInlineQueryResultLocation.longitude, TestInlineQueryResultLocation.title, live_period=TestInlineQueryResultLocation.live_period, thumb_url=TestInlineQueryResultLocation.thumb_url, thumb_width=TestInlineQueryResultLocation.thumb_width, thumb_height=TestInlineQueryResultLocation.thumb_height, input_message_content=TestInlineQueryResultLocation.input_message_content, reply_markup=TestInlineQueryResultLocation.reply_markup, horizontal_accuracy=TestInlineQueryResultLocation.horizontal_accuracy, heading=TestInlineQueryResultLocation.heading, proximity_alert_radius=TestInlineQueryResultLocation.proximity_alert_radius, )
def inlinequery(bot, update): """Handle the inline query.""" print(update) query = update.inline_query.query v = VesselInfo() cursor = v.get_vessel_info_by_keyword(query) res = cursor.fetchall() arr = [] for value in res: text = "{} ({})".format(value[1], value[0]) arr.append( InlineQueryResultLocation(type='location', id=value[0], latitude=value[3], longitude=value[2], title=text)) update.inline_query.answer(arr)
def inlinequery(update, context): """Handle the inline query.""" query = update.inline_query.query.strip() logger.info(query) if "," in query: if logic.is_coordinate_search(query): logger.info("is_coordinate_search True") lat, lon = query.split(",") status_code, title, address = logic.coordinate_search( lat, lon, api_url_base_reverse_geocode, api_key ) logger.info(f"{lat} {lon}\n{status_code}\n{title}\n{address}") if status_code == 200: results = [] results.append( InlineQueryResultLocation( type="location", id="single_location", latitude=float(lat), longitude=float(lon), live_period=60, input_message_content=InputVenueMessageContent( latitude=float(lat), longitude=float(lon), title="You've searched: " + query.capitalize(), address=address, ), title=title, ) ) context.bot.answerInlineQuery(update.inline_query.id, results) return elif status_code == 400: results = [] results.append( InlineQueryResultArticle( id="single_location", title=title, input_message_content=InputTextMessageContent(title), ) ) context.bot.answerInlineQuery(update.inline_query.id, results) else: results = [] results.append( InlineQueryResultArticle( id="single_location", title=title, input_message_content=InputTextMessageContent(title), ) ) context.bot.answerInlineQuery(update.inline_query.id, results) elif query: status_code, locations, _ = logic.get_locations( query, api_url_base_geocode, api_key ) if status_code == 200: inline_result = [] address_venue_str = "" title_str = "" for location in locations: address_venue_str = location.sub_division() title_str = f"{location.address}, {location.country}" if address_venue_str == "": address_venue_str = location.address else: title_str += f" ({address_venue_str})" inline_result.append( InlineQueryResultLocation( type="location", id=location.location_id, latitude=location.latitude, longitude=location.longitude, live_period=60, input_message_content=InputVenueMessageContent( latitude=location.latitude, longitude=location.longitude, title="You've searched: " + query.capitalize(), address=address_venue_str, ), title=title_str, ) ) context.bot.answerInlineQuery(update.inline_query.id, inline_result) elif status_code == 204: inline_result = [] inline_result.append( InlineQueryResultArticle( type="article", id=str(uuid4()), title="What are you searching?", input_message_content=InputTextMessageContent( "You need to add more infos in your inline query." ), thumb_url=image_url, ) ) context.bot.answerInlineQuery(update.inline_query.id, inline_result)
def inlinequery(bot, update): """Handle the inline query.""" query = update.inline_query.query.strip() logger.info(query) if "," in query: if is_coordinate_search(query): logger.info("is_coordinate_search True") lat, lon = query.split(",") status_code, title, address = coordinate_search(lat, lon) logger.info(f"{lat} {lon}\n{status_code}\n{title}\n{address}") if status_code == 200: results = [] results.append( InlineQueryResultLocation( type="location", id="single_location", latitude=float(lat), longitude=float(lon), live_period=60, input_message_content=InputVenueMessageContent( latitude=float(lat), longitude=float(lon), title="You've searched: " + query.capitalize(), address=address, ), title=title, ) ) bot.answerInlineQuery(update.inline_query.id, results) return elif status_code == 400: results = [] results.append( # FIXME this classes are not even imported, why are they here? InlineQueryResultArticle( id="single_location", title=title, input_message_content=InputTextMessageContent(title), ) ) bot.answerInlineQuery(update.inline_query.id, results) else: results = [] results.append( InlineQueryResultArticle( id="single_location", title=title, input_message_content=InputTextMessageContent(title), ) ) bot.answerInlineQuery(update.inline_query.id, results) elif query: ret = get_locations(query) if ret == 200: results = [] address_venue_str = "" title_str = "" for location in locations: address_venue_str = location.subDivision() title_str = f"{location.address}, {location.country}" if address_venue_str == "": address_venue_str = location.address else: title_str += f" ({address_venue_str})" results.append( InlineQueryResultLocation( type="location", id=location.id, latitude=location.latitude, longitude=location.longitude, live_period=60, input_message_content=InputVenueMessageContent( latitude=location.latitude, longitude=location.longitude, title="You've searched: " + query.capitalize(), address=address_venue_str, ), title=title_str, ) ) bot.answerInlineQuery(update.inline_query.id, results)
def inlinequery(bot, update): query = update.inline_query.query.split(' ') if query[0].lower() in ('help', 'h'): result = input_message_content = InlineQueryResultArticle( id=uuid4(), title='HELP', input_message_content=InputTextMessageContent(message_text=f""" Mask Query by cnwang. Ver {VERSION} usage : @rotom406_bot child/adult/distance/maxcount find at least maxcount pharmacies which child and adult mask quanties within distance (km) """)) results = [result] update.inline_query.answer(results) return name = update.inline_query.from_user.username loc = update.inline_query.location if loc is None: loc = {'longitude': 120.997655, 'latitude': 24.776416} #logger.info(f'{name} \'s location is {loc}') masks.setHome([loc['longitude'], loc['latitude']]) if len(query) == 1: sortKey = 'distance' else: sortKey = query[1] fields = query[0].split('/') if len(fields) == 4: #print (query,sortKey, fields) hits = masks.findMasks(child=int(fields[0]), adult=int(fields[1]), distance=float(fields[2]), maxcount=int(fields[3]), sortKey=sortKey) #print (len(hits)) if len(hits) != 0: print(f'doing filter ({len(hits)})...{masks.recordn2Str(0)} ') pass results = [] if len(hits) == 0: results = [ InlineQueryResultArticle( id=uuid4(), title='🈚️🈚️🈚️ NO FOUND 🈚️🈚️🈚️', input_message_content=InputTextMessageContent( u'請重新設定搜尋條件,因為要求太嚴苛了')) ] else: for idx, hit in enumerate(hits): print(hit['name']) # macos, table/map, ios talble/map # InlineQueryResultLocation + input_message_content=InputTextMessageContent O/X,O/X # InlineQueryResultLocation + input_message_content=InputLocationMessageContent O/O,X/X # InlineQueryResultLocation + O/O,X/X # InlineQueryResultLocation + input_message_content=InputTextMessageContent(+URL) O/△,O/△ # result=InlineQueryResultArticle(id=uuid4(), # title=masks.recordn2StrShort(idx),input_message_content=InputTextMessageContent(masks.recordn2Str(idx))) mapurl = f'https://www.google.com/maps/search/?api=1&query={hit["geometry"][1]},{hit["geometry"][0]}' result = InlineQueryResultLocation( id=uuid4(), title=masks.recordn2StrShort(idx), # title=str(idx), latitude=float(hit['geometry'][1]), longitude=float(hit['geometry'][0]), input_message_content=InputTextMessageContent( masks.recordn2Str(idx) + '\n' + mapurl), thumb_width=120, thumb_height=120 #input_message_content=InputLocationMessageContent(latitude=hit['geometry'][1],longitude=hit['geometry'][0], live_period=3600) ) logger.debug( f'{result.latitude},{result.input_message_content}') results.append(result) update.inline_query.answer(results) ret = allUsers.userAccess(name) else: result = input_message_content = InlineQueryResultArticle( id=uuid4(), title='兒童/成人/距離/顯示數量', input_message_content=InputTextMessageContent(message_text=f""" Mask Query by cnwang. Ver {VERSION} usage : @rotom406_bot child/adult/distance/maxcount [key] find at least maxcount pharmacies which child and adult mask quanties within distance (km) key is in (c,child, a,adult,d,distance... 大小寫是順序. 內定是distance') """)) results = [result] update.inline_query.answer(results) return
def inline(bot, update): query = update.inline_query.query if not query: """ If the users sends an empty location request, these capitals of the countries with the most telegram users will be displayed. """ results = [ InlineQueryResultLocation(id=0, latitude=40.7127753, longitude=-74.0059728, title="New York, NY, USA"), InlineQueryResultLocation(id=1, latitude=51.5073509, longitude=-0.1277583, title="London, UK"), InlineQueryResultLocation(id=2, latitude=52.52000659999999, longitude=13.404954, title="Berlin, Germany"), InlineQueryResultLocation(id=3, latitude=55.755826, longitude=37.6172999, title="Moscow, Russia"), InlineQueryResultLocation(id=4, latitude=41.9027835, longitude=12.4963655, title="Rome, Italy"), InlineQueryResultLocation(id=5, latitude=28.6139391, longitude=77.2090212, title="New Delhi, Delhi, India"), InlineQueryResultLocation(id=6, latitude=35.6894875, longitude=139.6917064, title="Tokyo, Japan"), InlineQueryResultLocation(id=7, latitude=-6.17511, longitude=106.8650395, title="Jakarta, Indonesia"), InlineQueryResultLocation(id=8, latitude=35.6891975, longitude=51.3889736, title="Teheran, Iran"), InlineQueryResultLocation(id=9, latitude=-22.9068467, longitude=-43.1728965, title="Rio de Janeiro, Brazil"), InlineQueryResultLocation(id=10, latitude=40.4167754, longitude=-3.7037902, title="Madrid, Spain"), InlineQueryResultLocation(id=11, latitude=24.7135517, longitude=46.6752957, title="Riyadh Saudi Arabia"), InlineQueryResultLocation(id=12, latitude=41.2994958, longitude=69.2400734, title="Tashkent, Uzbekistan"), InlineQueryResultLocation(id=13, latitude=37.566535, longitude=126.9779692, title="Seoul, South Korea"), InlineQueryResultLocation(id=14, latitude=33.3128057, longitude=44.3614875, title="Baghdad, Iraq"), InlineQueryResultLocation(id=15, latitude=52.3702157, longitude=4.895167900000001, title="Amsterdam, Netherlands"), InlineQueryResultLocation(id=16, latitude=8.9806034, longitude=38.7577605, title="Addis Ababa, Ethiopia"), ] if len(update.effective_user.language_code) > 4: """ Telegram provides a country code to the bot. This country code is resolved to the country and to it's capital, so if a user searches with an empty query, the capital of his own country is displayed on the top of the results """ country_code = update.effective_user.language_code[-2:] country = country_codes.codes[country_code] capital = country_codes.capitals[country] coords = GEOCODER.format_output(capital)[0] loc = InlineQueryResultLocation(id=hash(coords[0]), latitude=coords[1], longitude=coords[2], title=coords[0]) results.insert(0, loc) else: locations = GEOCODER.format_output(query) results = [] for res in locations: results.append( InlineQueryResultLocation(id=hash(res[0]), latitude=res[1], longitude=res[2], title=res[0])) if not results: text = InputTextMessageContent( "Can't find that location. Try again!") keyboard = [[ InlineKeyboardButton("Try again", switch_inline_query_current_chat="") ]] results.append( InlineQueryResultArticle( id=-1, title="No location found", input_message_content=text, reply_markup=InlineKeyboardMarkup(keyboard))) bot.answer_inline_query(update.inline_query.id, results, cache_time=20)
def send_inline(bot, update): if update.inline_query is not None and update.inline_query.query == '': loc = update.inline_query.location lat = loc['latitude'] long = loc['longitude'] details = get_details(lat, long) msg = InputTextMessageContent(message_text=details[0], parse_mode="Markdown", disable_web_page_preview=True) guide = InputTextMessageContent( message_text=messages['masksAvailableMsg'], parse_mode="Markdown", disable_web_page_preview=True) results = [ InlineQueryResultLocation( type='location', id=34, latitude=lat, longitude=long, title="Your Location's AQI : " + str(details[1]), input_message_content=msg, thumb_url="https://i.imgur.com/ZtiI8iQ.png"), InlineQueryResultArticle( type='article', id=254, title="Various masks you can consider...", input_message_content=guide, description="Gives you the list of masks you can buy.", thumb_url="https://i.imgur.com/ZeVCqXD.png") ] bot.answerInlineQuery( update.inline_query.id, results=results, switch_pm_text="Pm me for guides and other info...", switch_pm_parameter="test") if update.inline_query is not None and update.inline_query.query: query = update.inline_query.query output = search_place(query) if output: lat = output[0]['lat'] long = output[0]['long'] name = output[0]['name'] details = get_details(lat, long) msg = InputTextMessageContent(message_text=details[0], parse_mode="Markdown", disable_web_page_preview=True) response_list = [ InlineQueryResultLocation(type='location', id=0, latitude=lat, longitude=long, title=name, input_message_content=msg) ] bot.answerInlineQuery( update.inline_query.id, results=response_list, switch_pm_text="Pm me for guides and other info...", switch_pm_parameter="test")