Exemple #1
0
async def _(event):
    if event.fwd_from:
        return

    if event.is_group:
        if not await can_ban_users(message=event):
            return
    else:
        return

# Here laying the sanity check
    chat = await event.get_chat()
    admin = chat.admin_rights.ban_users
    creator = chat.creator

    # Well
    if not admin and not creator:
        await event.reply("`I don't have enough permissions!`")
        return

    c = 0
    KICK_RIGHTS = ChatBannedRights(until_date=None, view_messages=True)
    done = await event.reply("Working ...")
    async for i in tbot.iter_participants(event.chat_id):

        if isinstance(i.status, UserStatusLastMonth):
            status = await tbot(
                EditBannedRequest(event.chat_id, i, KICK_RIGHTS))
            if not status:
                return
            c = c + 1

        if isinstance(i.status, UserStatusLastWeek):
            status = await tbot(
                EditBannedRequest(event.chat_id, i, KICK_RIGHTS))
            if not status:
                return
            c = c + 1

    if c == 0:
        await done.edit("Got no one to kick 😔")
        return

    required_string = "Successfully Kicked **{}** users"
    await event.reply(required_string.format(c))
Exemple #2
0
async def _(event):
    if not event.is_group:
        return
    if event.is_group:
        if not await can_ban_users(message=event):
            return

    # Here laying the sanity check
    chat = await event.get_chat()
    admin = chat.admin_rights.ban_users
    creator = chat.creator

    # Well
    if not admin and not creator:
        await event.reply("`I don't have enough permissions!`")
        return

    done = await event.reply("Working ...")
    p = 0
    async for i in tbot.iter_participants(event.chat_id,
                                          filter=ChannelParticipantsBanned,
                                          aggressive=True):
        rights = ChatBannedRights(
            until_date=0,
            send_messages=False,
        )
        try:
            await tbot(
                functions.channels.EditBannedRequest(event.chat_id, i, rights))
        except FloodWaitError as ex:
            logger.warn("sleeping for {} seconds".format(ex.seconds))
            sleep(ex.seconds)
        except Exception as ex:
            await event.reply(str(ex))
        else:
            p += 1

    if p == 0:
        await done.edit("No one is muted in this chat")
        return
    required_string = "Successfully unmuted **{}** users"
    await event.reply(required_string.format(p))
Exemple #3
0
async def get_admin(show):
    if show.is_group:
        if not await is_register_admin(show.input_chat, show.sender_id):
            return
    else:
        return
    info = await tbot.get_entity(show.chat_id)
    title = info.title if info.title else "this chat"
    mentions = f'<b>Admins in {title}:</b> \n'
    try:
        async for user in tbot.iter_participants(
                show.chat_id, filter=ChannelParticipantsAdmins):
            if not user.deleted:
                link_unf = "<a href=\"tg://user?id={}\">{}</a>"
                link = link_unf.format(user.id, user.first_name)
                userid = f"<code>{user.id}</code>"
                mentions += f"\n{link} {userid}"
            else:
                mentions += f"\nDeleted Account <code>{user.id}</code>"
    except ChatAdminRequiredError as err:
        mentions += " " + str(err) + "\n"
    await show.reply(mentions, parse_mode="html")
Exemple #4
0
async def get_users(show):
    if not show.is_group:
        return
    if show.is_group:
        if not await is_register_admin(show.input_chat, show.sender_id):
            return
    info = await tbot.get_entity(show.chat_id)
    title = info.title if info.title else "this chat"
    mentions = "Users in {}: \n".format(title)
    async for user in tbot.iter_participants(show.chat_id):
        if not user.deleted:
            mentions += f"\n[{user.first_name}](tg://user?id={user.id}) {user.id}"
        else:
            mentions += f"\nDeleted Account {user.id}"
    file = open("userslist.txt", "w+")
    file.write(mentions)
    file.close()
    await tbot.send_file(
        show.chat_id,
        "userslist.txt",
        caption="Users in {}".format(title),
        reply_to=show.id,
    )
    os.remove("userslist.txt")
async def _(event):
    if event.is_private:
        return
    if await is_register_admin(event.input_chat, event.message.sender_id):
        return

    chat = event.chat_id
    user = event.sender
    args = event.pattern_match.group(1)

    if not sql.chat_should_report(chat):
        return

    if not event.chat.username:
        await event.reply(
            "Damn, this chat has no username so I can't markup the reported message."
        )
        return

    if event.reply_to_msg_id:
        c = await event.get_reply_message()
        reported_user = c.sender_id
        reported_user_first_name = c.sender.first_name
        if await is_register_admin(event.input_chat, reported_user):
            await event.reply("Why are you reporting an admin ?")
            return

        if not args:
            await event.reply("Add a reason for reporting first.")
            return

        if user.id == reported_user:
            await event.reply("Why are you reporting yourself ?")
            return

        if user.id == BOT_ID:
            await event.reply("Why are you reporting me ?")
            return

        if reported_user == OWNER_ID:
            await event.reply("Hey, don't dare reporting my master !")
            return

        msg = (
            f"<b>⚠️ Report: </b>{html.escape(event.chat.title)}\n"
            f"<b> • Report by:</b> <p><a href='tg://user?id={user.id}'>{user.first_name}</a></p> (<code>{user.id}</code>)\n"
            f"<b> • Reported user:</b> <p><a href='tg://user?id={reported_user}'>{reported_user_first_name}</a></p> (<code>{reported_user}</code>)\n"
            f"<b> • Reason:</b> {args}")
        buttons = [
            [
                Button.url(
                    "➡ Message",
                    url=f"https://t.me/{event.chat.username}/{c.id}",
                )
            ],
            [
                Button.inline(
                    "⚠ Kick",
                    data=f"report_{chat}=kick={reported_user}",
                ),
                Button.inline(
                    "⛔️ Ban",
                    data=f"report_{chat}=banned={reported_user}",
                ),
            ],
            [
                Button.inline(
                    "❎ Delete Message",
                    data=f"report_{chat}=delete={reported_user}={c.id}",
                )
            ],
        ]

        async for userr in tbot.iter_participants(
                event.chat_id, filter=ChannelParticipantsAdmins):
            try:
                if userr.bot:
                    pass
                else:
                    await tbot.send_message(userr.id,
                                            msg,
                                            buttons=buttons,
                                            parse_mode="html")
                    await tbot.send_message(
                        userr.id,
                        "**In case if the original message was deleted by the accused, a copy is sent to you as below 👇**",
                    )
                    await c.forward_to(userr.id)
            except Exception:
                pass

        try:
            await tbot.send_message(
                event.chat_id,
                f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p> reported <p><a href='tg://user?id={reported_user}'>{reported_user_first_name}</a></p> to the admins!",
                parse_mode="html",
            )
        except Exception:
            pass

        await event.delete()

    else:
        await event.reply("Reply to a message to report it to the admins.")
Exemple #6
0
async def rm_deletedacc(show):
    """ For .delusers command, list all the ghost/deleted accounts in a chat. """
    con = show.pattern_match.group(1).lower()
    del_u = 0
    del_status = "`No deleted accounts found, Group is cleaned as Hell`"

    if not show.is_group:
        return

    if show.is_group:
        if not await can_ban_users(message=show):
            return

    # Here laying the sanity check
    chat = await show.get_chat()
    admin = chat.admin_rights.ban_users
    creator = chat.creator

    # Well
    if not admin and not creator:
        await show.reply("`I don't have enough permissions!`")
        return

    if con != "clean":
        await show.reply("`Searching for zombie accounts...`")
        async for user in tbot.iter_participants(show.chat_id):
            if user.deleted:
                del_u += 1

        if del_u > 0:
            del_status = f"Found **{del_u}** deleted account(s) in this group,\
            \nclean them by using `/zombies clean`"

        await show.reply(del_status)
        return

    await show.reply("`Deleting deleted accounts...`")
    del_u = 0
    del_a = 0

    async for user in tbot.iter_participants(show.chat_id):
        if user.deleted:
            try:
                await tbot(
                    EditBannedRequest(show.chat_id, user.id, BANNED_RIGHTS))
            except ChatAdminRequiredError:
                await show.reply("`I don't have ban rights in this group`")
                return
            except UserAdminInvalidError:
                del_u -= 1
                del_a += 1
            await tbot(EditBannedRequest(show.chat_id, user.id, UNBAN_RIGHTS))
            del_u += 1

    if del_u > 0:
        del_status = f"Cleaned **{del_u}** deleted account(s)"

    if del_a > 0:
        del_status = f"Cleaned **{del_u}** deleted account(s) \
        \n**{del_a}** deleted admin accounts are not removed"

    await show.reply(del_status)