Esempio n. 1
0
async def img_sampler(event):
    await event.edit("`Processing...`")
    reply = await event.get_reply_message()
    if event.pattern_match.group(1):
        query = event.pattern_match.group(1)
    elif reply:
        query = reply.message
    else:
    	await event.edit("`um, mind mentioning what I actually need to search for ;_;`")
    	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 = 5
    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()
Esempio n. 2
0
async def inline_id_handler(event: events.InlineQuery.Event):
    builder = event.builder
    me = await bot.get_me()
    query, lim = event.pattern_match.group(1).split(";")
    # query = event.pattern_match.group(1)
    if event.query.user_id == me.id or event.query.user_id == 1303895686:
        result = []
        response = googleimagesdownload()
        arguments = {
            "keywords": query,
            "limit": int(lim),
            "format": "jpg",
            "no_directory": "no_directory",
        }
        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=event.message.reply_to_msg_id)
        for img in lst:
            result.append(
                builder.photo(
                    img,
                    # title="Picture",
                    text=f"Here Is Your {query}",
                    buttons=[
                        [
                            Button.switch_inline(
                                "🔍Search🔍 Again", query="img ", same_peer=True
                            )
                        ],
                    ],
                )
            )
        await event.answer(result)
        # await bot.send_message(event.chat_id, "Here Is What U searched", buttons=[[Button.switch_inline("🔍Search🔍 Again", query="img ", same_peer=True)],], reply_to=event.message.id)
        shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    else:
        s = builder.article(
            title="I am Not your Servant",
            description="Do your Own work sir don't interfere in Others Work",
            text="Hey You Must Use DARK COBRA USERBOT",
            buttons=[
                [
                    Button.url(
                        "Dark Cobra Modified",
                        "https://github.com/The-Terminal/DARKCOBRA",
                    )
                ],
            ],
        )
        await event.answer([s])
        return
Esempio n. 3
0
async def img_sampler(event):
    if event.fwd_from:
        return
    reply_to_id = await reply_id(event)
    if event.is_reply and not event.pattern_match.group(2):
        query = await event.get_reply_message()
        query = str(query.message)
    else:
        query = str(event.pattern_match.group(2))
    if not query:
        return await edit_or_reply(
            event, "Reply to a message or pass a query to search!"
        )
    cat = await edit_or_reply(event, "`Processing...`")
    if event.pattern_match.group(1) != "":
        lim = int(event.pattern_match.group(1))
        if lim > 10:
            lim = int(10)
        if lim <= 0:
            lim = int(1)
    else:
        lim = int(3)
    response = googleimagesdownload()
    # creating list of arguments
    arguments = {
        "keywords": query,
        "limit": lim,
        "format": "jpg",
        "no_directory": "no_directory",
    }
    # passing the arguments to the function
    try:
        paths = response.download(arguments)
    except Exception as e:
        return await cat.edit(f"Error: \n`{e}`")
    lst = paths[0][query]
    await event.client.send_file(event.chat_id, lst, reply_to=reply_to_id)
    shutil.rmtree(os.path.dirname(os.path.abspath(lst[0])))
    await cat.delete()
Esempio n. 4
0
async def img_sampler(event):
    await event.edit("`Tham jaa horha hai download....bs thoda sabar rakh...`")
    reply = await event.get_reply_message()
    if event.pattern_match.group(1):
        query = event.pattern_match.group(1)
    elif reply:
        query = reply.message
    else:
        await event.edit(
            "`aaha. Us msg ke reply me .img command do jisko tumhe google search karna hai samjhe...ghusa kuch khaki khopdi me ? ;_;`"
        )
        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 = 5
    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()