Ejemplo n.º 1
0
async def pmpermit_cq(_, cq):
    user_id = cq.from_user.id
    data, victim = cq.data.split(None, 2)[1], int(cq.data.split(None, 2)[2])

    if data == "approve":
        if user_id != USERBOT_ID:
            await cq.answer("This Button Is Not For You")
            return
        await approve_pmpermit(victim)
        await app.edit_inline_text(cq.inline_message_id,
                                   "User Has Been Approved To PM.")
        return
    if user_id == USERBOT_ID:
        await cq.answer("It's For The Other Person.")
        return

    if data == "to_scam_you":
        async for m in app2.iter_history(user_id, limit=6):
            if m.reply_markup:
                await m.delete()
        await app2.send_message(user_id, "Blocked, Go scam someone else.")
        await app2.block_user(user_id)

    elif data == "approve_me":
        await app2.send_message(
            user_id,
            "I'm busy right now, will approve you shortly, DO NOT SPAM.")
Ejemplo n.º 2
0
async def pmpermit_func(_, message):
    user_id = message.from_user.id
    if await is_pmpermit_approved(user_id):
        return
    async for m in app2.iter_history(user_id, limit=6):
        if m.reply_markup:
            await m.delete()
    if str(user_id) in flood:
        flood[str(user_id)] += 1
    else:
        flood[str(user_id)] = 1
    if flood[str(user_id)] > 5:
        await message.reply_text(
            "SPAM DETECTED, BLOCKED USER AUTOMATICALLY!"
        )
        return await app2.block_user(user_id)
    results = await app2.get_inline_bot_results(
        BOT_ID, f"pmpermit {user_id}"
    )
    await app2.send_inline_bot_result(
        user_id,
        results.query_id,
        results.results[0].id,
        hide_via=True,
    )
Ejemplo n.º 3
0
async def pmpermit_cq(_, cq):
    user_id = cq.from_user.id
    data, victim = (
        cq.data.split(None, 2)[1],
        cq.data.split(None, 2)[2],
    )
    if data == "approve":
        if user_id != USERBOT_ID:
            return await cq.answer("This Button Is Not For You")
        await approve_pmpermit(int(victim))
        return await app.edit_inline_text(
            cq.inline_message_id, "User Has Been Approved To PM."
        )

    if data == "block":
        if user_id != USERBOT_ID:
            return await cq.answer("This Button Is Not For You")
        await cq.answer()
        await app.edit_inline_text(
            cq.inline_message_id, "Successfully blocked the user."
        )
        await app2.block_user(int(victim))
        return await app2.send(
            DeleteHistory(
                peer=(await app2.resolve_peer(victim)),
                max_id=0,
                revoke=False,
            )
        )

    if user_id == USERBOT_ID:
        return await cq.answer("It's For The Other Person.")

    if data == "to_scam_you":
        async for m in app2.iter_history(user_id, limit=6):
            if m.reply_markup:
                await m.delete()
        await app2.send_message(
            user_id, "Blocked, Go scam someone else."
        )
        await app2.block_user(user_id)
        await cq.answer()

    elif data == "approve_me":
        await cq.answer()
        if str(user_id) in flood2:
            flood2[str(user_id)] += 1
        else:
            flood2[str(user_id)] = 1
        if flood2[str(user_id)] > 5:
            await app2.send_message(
                user_id, "SPAM DETECTED, USER BLOCKED."
            )
            return await app2.block_user(user_id)
        await app2.send_message(
            user_id,
            "I'm busy right now, will approve you shortly, DO NOT SPAM.",
        )
Ejemplo n.º 4
0
async def pm_disapprove(_, message):
    if not message.reply_to_message:
        return await eor(message, text="Reply to a user's message to approve.")
    user_id = message.reply_to_message.from_user.id
    if not await is_pmpermit_approved(user_id):
        await eor(message, text="User is already disapproved to pm")
        async for m in app2.iter_history(user_id, limit=6):
            if m.reply_markup:
                try:
                    await m.delete()
                except Exception:
                    pass
        return
    await disapprove_pmpermit(user_id)
    await eor(message, text="User is disapproved to pm")
Ejemplo n.º 5
0
async def iter_edit(message: Message, text: str):
    async for m in app2.iter_history(message.chat.id):

        # If no replies found, reply
        if m.message_id == message.message_id:
            return 0

        if not m.from_user or not m.text or not m.reply_to_message:
            continue

        if ((m.reply_to_message.message_id == message.message_id)
                and (m.from_user.id == message.from_user.id)
                and ("→" in m.text)):
            try:
                return await m.edit(text)
            except MessageNotModified:
                return
Ejemplo n.º 6
0
async def executor(client, message: Message):
    global m, p, r, tasks
    try:
        cmd = message.text.split(" ", maxsplit=1)[1]
    except IndexError:
        return await message.delete()

    if message.chat.type == "channel":
        return

    m = message
    p = print
    loop = get_event_loop()

    for key, value in tasks.items():
        if value.done():
            del tasks[key]

    # To prevent keyboard input attacks
    if m.reply_to_message:
        r = m.reply_to_message
        if r.reply_markup:
            if isinstance(r.reply_markup, ReplyKeyboardMarkup):
                return await eor(m, text="INSECURE!")
    old_stderr = sys.stderr
    old_stdout = sys.stdout
    redirected_output = sys.stdout = StringIO()
    redirected_error = sys.stderr = StringIO()
    stdout, stderr, exc = None, None, None
    try:
        task = loop.create_task(aexec(cmd, client, message))

        # Save it in tasks, so we can cancel it with .cancelTask
        tasks[m.message_id] = task
        await task
    except Exception as e:
        exc = str(e)

    if m.message_id in tasks:
        del tasks[m.message_id]

    stdout = redirected_output.getvalue()
    stderr = redirected_error.getvalue()
    sys.stdout = old_stdout
    sys.stderr = old_stderr
    evaluation = ""
    if exc:
        evaluation = exc
    elif stderr:
        evaluation = stderr
    elif stdout:
        evaluation = stdout
        # Save the last stdout in globals,
        # Can use the it in next calls
        globals()["lstdout"] = stdout
    else:
        evaluation = "Success"
    final_output = f"**→**\n`{escape(evaluation.strip())}`"
    if len(final_output) > 4096:
        filename = "output.txt"
        with open(filename, "w+", encoding="utf8") as out_file:
            out_file.write(str(evaluation.strip()))
        await message.reply_document(
            document=filename,
            caption="`→`\n  **Attached Document**",
            quote=False,
        )
        os.remove(filename)
    else:
        mid = message.message_id

        # Edit the output if input is edited
        if message.edit_date:
            async for m in app2.iter_history(message.chat.id):

                # If no replies found, reply
                if m.message_id == mid:
                    break

                if (not m.from_user or not m.text or not m.reply_to_message):
                    continue

                if m.reply_to_message.message_id == mid:
                    if m.from_user.id == message.from_user.id:

                        if "→" in m.text:
                            try:
                                return await m.edit(final_output)
                            except MessageNotModified:
                                return
        await message.reply(final_output, quote=True)