async def img_sampler(event): """ For .img command, search and return images matching the query. """ await event.edit("`Processing...`") query = event.pattern_match.group(1) lim = findall(r"lim=\d+", query) try: lim = lim[0] lim = lim.replace("lim=", "") query = query.replace("lim=" + lim[0], "") except IndexError: lim = 6 response = googleimagesdownload() # creating list of arguments arguments = { "keywords": query, "limit": lim, "format": "jpg", "no_directory": "no_directory" } # passing the arguments to the function paths = response.download(arguments) lst = paths[0][query] await event.client.send_file( await event.client.get_input_entity(event.chat_id), lst) shutil.rmtree(os.path.dirname(os.path.abspath(lst[0]))) await event.delete()
async def img_sampler(event): await event.edit("`Processing....`") reply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id reply = await event.get_reply_message() if event.pattern_match.group(1): query = event.pattern_match.group(1) elif reply.text: query = reply.message else: await event.edit("`What I am Supposed to Search `") return lim = findall(r"lim=\d+", query) # lim = event.pattern_match.group(1) try: lim = lim[0] lim = lim.replace("lim=", "") query = query.replace("lim=" + lim[0], "") except IndexError: lim = (Config.TG_GLOBAL_ALBUM_LIMIT) response = googleimagesdownload() # creating list of arguments arguments = { "keywords": query, "limit": lim, "format": "jpg", "no_directory": "no_directory" } # passing the arguments to the function paths = response.download(arguments) lst = paths[0][query] await event.client.send_file(await event.client.get_input_entity(event.chat_id), lst,reply_to=reply_to_id) shutil.rmtree(os.path.dirname(os.path.abspath(lst[0]))) await event.delete()