Ejemplo n.º 1
0
async def _(event):
    if event.is_private:
        return
    user = event.sender  # type: Optional[User]
    chat = event.chat_id  # type: Optional[Chat]

    # ignore admins and owner
    if await is_register_admin(chat, user.id) or user.id == OWNER_ID:
        sql.update_flood(chat, None)
        return

    should_ban = sql.update_flood(chat, user.id)
    if not should_ban:
        return

    try:
        getmode, getvalue = sql.get_flood_setting(chat)
        if getmode == 1:
            await tbot(EditBannedRequest(chat, user.id, BANNED_RIGHTS))
            execstrings = "Banned"

        elif getmode == 2:
            await tbot.kick_participant(chat, user.id)
            execstrings = "Kicked"

        elif getmode == 3:
            await tbot(EditBannedRequest(chat, user.id, MUTE_RIGHTS))
            execstrings = "Muted"

        elif getmode == 4:
            bantime = await extract_time(event, getvalue)
            NEW_RIGHTS = ChatBannedRights(
                until_date=bantime,
                view_messages=True,
                send_messages=True,
                send_media=True,
                send_stickers=True,
                send_gifs=True,
                send_games=True,
                send_inline=True,
                embed_links=True,
            )
            await tbot(EditBannedRequest(chat, user.id, NEW_RIGHTS))
            execstrings = "Banned for {}".format(getvalue)

        elif getmode == 5:
            mutetime = await extract_time(event, getvalue)
            print(mutetime)
            NEW_RIGHTS = ChatBannedRights(until_date=mutetime,
                                          send_messages=True)
            await tbot(EditBannedRequest(chat, user.id, NEW_RIGHTS))
            execstrings = "Muted for {}".format(getvalue)

        await event.reply("Spammer Detected !\n{}!".format(execstrings))

    except Exception:
        await event.reply(
            "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood."
        )
        sql.set_flood(chat, 0)
Ejemplo n.º 2
0
def set_flood_mode(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

    if update.effective_message.chat.type == "private":
        send_message(
            update.effective_message,
            "This command is meant to use in group not in PM",
        )
        return ""
    chat = update.effective_chat
    chat_id = update.effective_chat.id
    chat_name = update.effective_message.chat.title

    if args:
        if args[0].lower() == "ban":
            settypeflood = "ban"
            sql.set_flood_strength(chat_id, 1, "0")
        elif args[0].lower() == "kick":
            settypeflood = "kick"
            sql.set_flood_strength(chat_id, 2, "0")
        elif args[0].lower() == "mute":
            settypeflood = "mute"
            sql.set_flood_strength(chat_id, 3, "0")
        elif args[0].lower() == "tban":
            if len(args) == 1:
                teks = """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tban <timevalue>`.

    Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return
            settypeflood = "tban for {}".format(args[1])
            sql.set_flood_strength(chat_id, 4, str(args[1]))
        elif args[0].lower() == "tmute":
            if len(args) == 1:
                teks = """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tmute <timevalue>`.

    Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                send_message(update.effective_message,
                             teks,
                             parse_mode="markdown")
                return
            settypeflood = "tmute for {}".format(args[1])
            sql.set_flood_strength(chat_id, 5, str(args[1]))
        else:
            send_message(update.effective_message,
                         "I only understand ban/kick/mute/tban/tmute!")
            return

        text = msg.reply_text(
            "Exceeding consecutive flood limit will result in {}!".format(
                settypeflood))
        send_message(update.effective_message, text, parse_mode="markdown")
        return ("<b>{}:</b>\n"
                "<b>Admin:</b> {}\n"
                "Has changed antiflood mode. User will {}.".format(
                    settypeflood,
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name),
                ))
    getmode, getvalue = sql.get_flood_setting(chat.id)
    if getmode == 1:
        settypeflood = "ban"
    elif getmode == 2:
        settypeflood = "kick"
    elif getmode == 3:
        settypeflood = "mute"
    elif getmode == 4:
        settypeflood = "tban for {}".format(getvalue)
    elif getmode == 5:
        settypeflood = "tmute for {}".format(getvalue)

    text = msg.reply_text(
        "Sending more message than flood limit will result in {}.".format(
            settypeflood))
    send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
    return ""
Ejemplo n.º 3
0
async def _(event):
    try:
        if event.is_private:
            return
        if event.is_group:
            if not await can_change_info(message=event):
                return
        chat_id = event.chat_id
        args = event.pattern_match.group(1)
        time = args.split()
        if time[0]:
            if time[0] == "ban":
                settypeflood = "ban"
                sql.set_flood_strength(chat_id, 1, "0")
            elif time[0] == "kick":
                settypeflood = "kick"
                sql.set_flood_strength(chat_id, 2, "0")
            elif time[0] == "mute":
                settypeflood = "mute"
                sql.set_flood_strength(chat_id, 3, "0")
            elif time[0] == "tban":
                try:
                    ttime = time[1]
                except:
                    await event.reply("Please provide the tban time interval.")
                    return
                if len(ttime) == 1:
                    teks = """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tban <timevalue>`.
Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                    await event.reply(teks, parse_mode="markdown")
                    return
                if not any(ttime.endswith(unit) for unit in ("m", "h", "d")):
                    await event.reply(
                        "Invalid time type specified. Expected m,h, or d, got: {}"
                        .format(ttime))
                    return
                settypeflood = "tban for {}".format(ttime)
                sql.set_flood_strength(chat_id, 4, str(ttime))
            elif time[0] == "tmute":
                try:
                    ttime = time[1]
                except:
                    await event.reply("Please provide the tmute time interval."
                                      )
                    return
                if len(ttime) == 1:
                    teks = """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tmute <timevalue>`.
Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks."""
                    await event.reply(teks, parse_mode="markdown")
                    return
                if not any(ttime.endswith(unit) for unit in ("m", "h", "d")):
                    await event.reply(
                        "Invalid time type specified. Expected m,h, or d, got: {}"
                        .format(ttime))
                    return
                settypeflood = "tmute for {}".format(ttime)
                sql.set_flood_strength(chat_id, 5, str(ttime))
            else:
                await event.reply("I only understand ban/kick/mute/tban/tmute!"
                                  )
                return

            await event.reply(
                "Exceeding consecutive flood limit will result in {}!".format(
                    settypeflood))
        else:
            getmode, getvalue = sql.get_flood_setting(chat_id)
            if getmode == 1:
                settypeflood = "ban"
            elif getmode == 2:
                settypeflood = "kick"
            elif getmode == 3:
                settypeflood = "mute"
            elif getmode == 4:
                settypeflood = "tban for {}".format(getvalue)
            elif getmode == 5:
                settypeflood = "tmute for {}".format(getvalue)

            await event.reply(
                "Sending more message than flood limit will result in {}.".
                format(settypeflood))
    except Exception as e:
        print(e)
Ejemplo n.º 4
0
def check_flood(update, context) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    if not user:  # ignore channels
        return ""

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return ""

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            chat.kick_member(user.id)
            execstrings = "Banned"
            tag = "BANNED"
        elif getmode == 2:
            chat.kick_member(user.id)
            chat.unban_member(user.id)
            execstrings = "Kicked"
            tag = "KICKED"
        elif getmode == 3:
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                permissions=ChatPermissions(can_send_messages=False))
            execstrings = "Muted"
            tag = "MUTED"
        elif getmode == 4:
            bantime = extract_time(msg, getvalue)
            chat.kick_member(user.id, until_date=bantime)
            execstrings = "Banned for {}".format(getvalue)
            tag = "TBAN"
        elif getmode == 5:
            mutetime = extract_time(msg, getvalue)
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False),
            )
            execstrings = "Muted for {}".format(getvalue)
            tag = "TMUTE"
        send_message(
            update.effective_message,
            "Great, I like to leave flooding to natural disasters but you, "
            "you were just a disappointment. {}!".format(execstrings),
        )

        return ("<b>{}:</b>"
                "\n#{}"
                "\n<b>User:</b> {}"
                "\nFlooded the group.".format(
                    tag, html.escape(chat.title),
                    mention_html(user.id, user.first_name)))

    except BadRequest:
        msg.reply_text(
            "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood."
        )
        sql.set_flood(chat.id, 0)
        return (
            "<b>{}:</b>"
            "\n#INFO"
            "\nDon't have enough permission to restrict users so automatically disabled anti-flood"
            .format(chat.title))