Ejemplo n.º 1
0
async def print_files(e, files, thash=None):
    msg = f"<a href='tg://user?id={e.sender_id}'>Done</a>\n#uploads\n"
    if len(files) == 0:
        return

    chat_id = e.chat_id

    for i in files.keys():
        link = f'https://t.me/c/{str(chat_id)[4:]}/{files[i]}'
        msg += f'🚩 <a href="{link}">{i}</a>\n'

    await e.reply(msg, parse_mode="html")

    try:
        if thash is not None:
            from .store_info_hash import store_driver  # pylint: disable=import-error
            await store_driver(e, files, thash)
    except:
        pass

    if len(files) < 2:
        return

    ids = list()
    for i in files.keys():
        ids.append(files[i])

    msgs = await e.client.get_messages(e.chat_id, ids=ids)
    for i in msgs:
        index = None
        for j in range(0, len(msgs)):
            index = j
            if ids[j] == i.id:
                break
        nextt, prev = "", ""
        chat_id = str(e.chat_id)[4:]
        buttons = []
        if index == 0:
            nextt = f'https://t.me/c/{chat_id}/{ids[index+1]}'
            buttons.append(types.KeyboardButtonUrl("Next", nextt))
            nextt = f'<a href="{nextt}">Next</a>\n'
        elif index == len(msgs) - 1:
            prev = f'https://t.me/c/{chat_id}/{ids[index-1]}'
            buttons.append(types.KeyboardButtonUrl("Prev", prev))
            prev = f'<a href="{prev}">Prev</a>\n'
        else:
            nextt = f'https://t.me/c/{chat_id}/{ids[index+1]}'
            buttons.append(types.KeyboardButtonUrl("Next", nextt))
            nextt = f'<a href="{nextt}">Next</a>\n'

            prev = f'https://t.me/c/{chat_id}/{ids[index-1]}'
            buttons.append(types.KeyboardButtonUrl("Prev", prev))
            prev = f'<a href="{prev}">Prev</a>\n'

        try:
            #await i.edit("{} {} {}".format(prev,i.text,nextt),parse_mode="html")
            await i.edit(buttons=buttons)
        except:
            pass
        await aio.sleep(1)
async def print_files(e, files, thash=None, path=None):
    msg = f"<a href='tg://user?id={e.sender_id}'>Done</a>\n#uploads\n"

    if path is not None:
        size = 0
        try:
            if os.path.isdir(path):
                size = get_size_fl(path)
            else:
                size = os.path.getsize(path)
        except:
            torlog.warning("Size Calculation Failed.")

        size = human_readable_bytes(size)
        msg += f"Uploaded Size:- {str(size)}\n\n"

    if len(files) == 0:
        return

    chat_id = e.chat_id
    msg_li = []
    for i in files.keys():
        link = f'https://t.me/c/{str(chat_id)[4:]}/{files[i]}'
        if len(msg + f'🚩 <a href="{link}">{i}</a>\n') > 4000:
            msg_li.append(msg)
            msg = f'🚩 <a href="{link}">{i}</a>\n'
        else:
            msg += f'🚩 <a href="{link}">{i}</a>\n'

    for i in msg_li:
        await e.reply(i, parse_mode="html")
        await aio.sleep(1)

    await e.reply(msg, parse_mode="html")

    try:
        if thash is not None:
            from .store_info_hash import store_driver  # pylint: disable=import-error
            await store_driver(e, files, thash)
    except:
        pass

    if len(files) < 2:
        return

    ids = list()
    for i in files.keys():
        ids.append(files[i])

    msgs = await e.client.get_messages(e.chat_id, ids=ids)
    for i in msgs:
        index = None
        for j in range(0, len(msgs)):
            index = j
            if ids[j] == i.id:
                break
        nextt, prev = "", ""
        chat_id = str(e.chat_id)[4:]
        buttons = []
        if index == 0:
            nextt = f'https://t.me/c/{chat_id}/{ids[index+1]}'
            buttons.append(types.KeyboardButtonUrl("Next", nextt))
            nextt = f'<a href="{nextt}">Next</a>\n'
        elif index == len(msgs) - 1:
            prev = f'https://t.me/c/{chat_id}/{ids[index-1]}'
            buttons.append(types.KeyboardButtonUrl("Prev", prev))
            prev = f'<a href="{prev}">Prev</a>\n'
        else:
            nextt = f'https://t.me/c/{chat_id}/{ids[index+1]}'
            buttons.append(types.KeyboardButtonUrl("Next", nextt))
            nextt = f'<a href="{nextt}">Next</a>\n'

            prev = f'https://t.me/c/{chat_id}/{ids[index-1]}'
            buttons.append(types.KeyboardButtonUrl("Prev", prev))
            prev = f'<a href="{prev}">Prev</a>\n'

        try:
            #await i.edit("{} {} {}".format(prev,i.text,nextt),parse_mode="html")
            await i.edit(buttons=buttons)
        except:
            pass
        await aio.sleep(2)