Esempio n. 1
0
def set_flood_strength(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    admin = chat.get_member(int(user.id))
    if (admin.status != 'creator') and (not admin.can_restrict_members) and (
            not int(user.id) in SUDO_USERS):
        update.effective_message.reply_text(
            "You don't have sufficient permissions to restrict users!")
        return ""

    if args:
        if args[0].lower() in ("on", "yes"):
            sql.set_flood_strength(chat.id, False)
            msg.reply_text(
                "Exceeding consecutive flood limit will result in a ban!")
            return "<b>{}:</b>\n" \
                   "<b>• Admin:</b> {}\n" \
                   "Has enabled strong flood and users will be banned.".format(html.escape(chat.title),
                                                                            mention_html(user.id, user.first_name))

        elif args[0].lower() in ("off", "no"):
            sql.set_flood_strength(chat.id, True)
            msg.reply_text(
                "Exceeding consecutive flood limit will result in a kick, Users will able to join back."
            )
            return "<b>{}:</b>\n" \
                   "<b>• Admin:</b> {}\n" \
                   "Has disabled strong flood and users will only be kicked.".format(html.escape(chat.title),
                                                                                  mention_html(user.id,
                                                                                               user.first_name))

        else:
            msg.reply_text("I only understand on/yes/no/off!")
    else:
        soft_flood = sql.get_flood_strength(chat.id)
        if soft_flood == True:
            msg.reply_text(
                "Flood strength is currently set to *kick* users when they exceed the limits. ",
                parse_mode=ParseMode.MARKDOWN)

        elif soft_flood:
            msg.reply_text(
                "The default configuration for flood control is currently set as a ban.",
                parse_mode=ParseMode.MARKDOWN)

        elif soft_flood == False:
            msg.reply_text(
                "Flood strength is currently set to *ban* users when they exceed the limits, "
                "user will be banned.",
                parse_mode=ParseMode.MARKDOWN)
    return ""
Esempio n. 2
0
def set_flood_strength(update: Update, context: CallbackContext):
    if not check_perms(update, 1):
        return
    bot, args = context.bot, context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    if args:
        if args[0].lower() in ("on", "yes"):
            sql.set_flood_strength(chat.id, False)
            msg.reply_text(
                "Exceeding consecutive flood limit will result in a ban!")
            return (
                "<b>{}:</b>\n"
                "<b>• Admin:</b> {}\n"
                "Has enabled strong flood and users will be banned.".format(
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name)))

        if args[0].lower() in ("off", "no"):
            sql.set_flood_strength(chat.id, True)
            msg.reply_text(
                "Exceeding consecutive flood limit will result in a kick, Users will able to join back."
            )
            return ("<b>{}:</b>\n"
                    "<b>• Admin:</b> {}\n"
                    "Has disabled strong flood and users will only be kicked.".
                    format(html.escape(chat.title),
                           mention_html(user.id, user.first_name)))
        msg.reply_text("I only understand on/yes/no/off!")
    else:
        soft_flood = sql.get_flood_strength(chat.id)
        if soft_flood is True:
            msg.reply_text(
                "Flood strength is currently set to *kick* users when they exceed the limits. ",
                parse_mode=ParseMode.MARKDOWN,
            )

        elif soft_flood:
            msg.reply_text(
                "The default configuration for flood control is currently set as a ban.",
                parse_mode=ParseMode.MARKDOWN,
            )

        elif soft_flood is False:
            msg.reply_text(
                "Flood strength is currently set to *ban* users when they exceed the limits, "
                "user will be banned.",
                parse_mode=ParseMode.MARKDOWN,
            )
    return ""
Esempio n. 3
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        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 = update.effective_message, """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 = update.effective_message, """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
        if conn:
            text = msg.reply_text("Exceeding consecutive flood limit will result in {} in {}!".format(settypeflood, chat_name))
        else:
            text = msg.reply_text("Exceeding consecutive flood limit will result in {}!".format(settypeflood))

        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))
    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))
        if conn:
            text = msg.reply_text("Sending more messages than flood limit will result in {} in {}.".format(settypeflood, chat_name))
        else:
            text = msg.reply_text("Sending more message than flood limit will result in {}.".format(settypeflood))

    return ""
Esempio n. 4
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]):
    spam = (update.effective_message.text,
            update.effective_message.from_user.id, update.effective_chat.id,
            update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            update.effective_message.reply_text(
                tl(update.effective_message,
                   "Use This Command in Groups,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 = (update.effective_message, 'Banned')
            sql.set_flood_strength(chat_id, 1, "0")
        elif args[0].lower() == 'kick':
            settypeflood = (update.effective_message, 'Kicked')
            sql.set_flood_strength(chat_id, 2, "0")
        elif args[0].lower() == 'mute':
            settypeflood = (update.effective_message, 'Muted')
            sql.set_flood_strength(chat_id, 3, "0")
        elif args[0].lower() == 'tban':
            if len(args) == 1:
                teks = (
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`.
Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                msg.reply_text(teks, parse_mode="markdown")
                return
            settypeflood = (update.effective_message,
                            "blokir sementara selama {}").format(args[1])
            sql.set_flood_strength(chat_id, 4, str(args[1]))
        elif args[0].lower() == 'tmute':
            if len(args) == 1:
                teks = (
                    update.effective_message,
                    """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`.
Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""")
                msg.reply_text(teks, parse_mode="markdown")
                return
            settypeflood = (update.effective_message,
                            'bisukan sementara selama {}').format(args[1])
            sql.set_flood_strength(chat_id, 5, str(args[1]))
        else:
            msg.reply_text((update.effective_message,
                            "I understand only ban/kick/mute/tban/tmute"))
            return
        if conn:
            text = (
                update.effective_message,
                "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}` pada *{}*!"
            ).format(settypeflood, chat_name)
        else:
            text = (
                update.effective_message,
                "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}`!"
            ).format(settypeflood)
        msg.reply_text(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))
    else:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            settypeflood = (update.effective_message, 'blokir')
        elif getmode == 2:
            settypeflood = (update.effective_message, 'tendang')
        elif getmode == 3:
            settypeflood = (update.effective_message, 'bisukan')
        elif getmode == 4:
            settypeflood = (update.effective_message,
                            'blokir sementara selama {}').format(getvalue)
        elif getmode == 5:
            settypeflood = (update.effective_message,
                            'bisukan sementara selama {}').format(getvalue)
        if conn:
            text = (
                update.effective_message,
                "Jika member mengirim pesan beruntun, maka dia akan *di {}* pada *{}*."
            ).format(settypeflood, chat_name)
        else:
            text = (
                update.effective_message,
                "Jika member mengirim pesan beruntun, maka dia akan *di {}*."
            ).format(settypeflood)
        msg.reply_text(text, parse_mode=ParseMode.MARKDOWN)
    return ""
Esempio n. 5
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            send_message(
                update.effective_message,
                "Perintah ini dimaksudkan untuk digunakan dalam grup bukan di 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 = update.effective_message, """Sepertinya Anda mencoba menyetel nilai waktu untuk antiflood tetapi Anda tidak menentukan waktu; Coba, `/setfloodmode tban <nilai waktu>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu."""
                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 = update.effective_message, """Sepertinya Anda mencoba menyetel nilai waktu untuk antiflood tetapi Anda tidak menentukan waktu; Coba, `/setfloodmode tmute <timevalue>`.

Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu."""
                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,
                         "Saya hanya mengerti ban/kick/mute/tban/tmute!")
            return
        if conn:
            text = msg.reply_text(
                "Melebihi batas flood yang berurutan akan berakibat {} dalam {}!"
                .format(settypeflood, chat_name))
        else:
            text = msg.reply_text(
                "Melebihi batas flood yang berurutan akan berakibat {}!".
                format(settypeflood))

        return "<b>{}:</b>\n" \
                "<b>Admin:</b> {}\n" \
                "Telah mengubah mode antiflood. Pengguna akan {}.".format(settypeflood, html.escape(chat.title),
                                                                            mention_html(user.id, user.first_name))
    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))
        if conn:
            text = msg.reply_text(
                "Mengirim lebih banyak pesan daripada batas banjir akan mengakibatkan {} dalam {}."
                .format(settypeflood, chat_name))
        else:
            text = msg.reply_text(
                "Mengirim pesan lebih dari batas banjir akan menghasilkan {}.".
                format(settypeflood))

    return ""
Esempio n. 6
0
def set_flood_mode(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            update.effective_message.reply_text(
                tld(update.effective_message,
                    "Use This Command in Groups,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 = tld(update.effective_message, 'Banned')
            sql.set_flood_strength(chat_id, 1, "0")
        elif args[0].lower() == 'kick':
            settypeflood = tld(update.effective_message, 'Kicked')
            sql.set_flood_strength(chat_id, 2, "0")
        elif args[0].lower() == 'mute':
            settypeflood = tld(update.effective_message, 'Muted')
            sql.set_flood_strength(chat_id, 3, "0")
        elif args[0].lower() == 'tban':
            if len(args) == 1:
                teks = tld(
                    update.effective_message,
                    """It looks like you tried to set a time value for the anti-flood, but did not specify a time; use `/setfloodmode tban <timevalue>`.
Examples of the value of time: 4m = 4 minute, 3h = 3 Hours, 6d = 6 days, 5w = 5 weeks."""
                )
                msg.reply_text(teks, parse_mode="markdown")
                return
            settypeflood = tld(update.effective_message,
                               "temporarily ban during {}").format(args[1])
            sql.set_flood_strength(chat_id, 4, str(args[1]))
        elif args[0].lower() == 'tmute':
            if len(args) == 1:
                teks = tld(
                    update.effective_message,
                    """It looks like you tried to set a time value for the anti-flood, but did not specify a time; use `/setfloodmode tban <timevalue>`.
Examples of the value of time: 4m = 4 minute, 3h = 3 Hours, 6d = 6 days, 5w = 5 weeks."""
                )
                msg.reply_text(teks, parse_mode="markdown")
                return
            settypeflood = tld(update.effective_message,
                               'temporarily mute during {}').format(args[1])
            sql.set_flood_strength(chat_id, 5, str(args[1]))
        else:
            msg.reply_text(
                tld(update.effective_message,
                    "I understand only ban/kick/mute/tban/tmute"))
            return
        if conn:
            text = tld(
                update.effective_message,
                "Too many sent messages Result Will Be `{}` on *{}*!").format(
                    settypeflood, chat_title)
        else:
            text = tld(update.effective_message,
                       "Too many sent messages Result Will Be `{}`!").format(
                           settypeflood)
        msg.reply_text(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))
    else:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            settypeflood = tld(update.effective_message, 'banned')
        elif getmode == 2:
            settypeflood = tld(update.effective_message, 'kick')
        elif getmode == 3:
            settypeflood = tld(update.effective_message, 'mute')
        elif getmode == 4:
            settypeflood = tld(update.effective_message,
                               'Blocking while during {}'.format(getvalue))
        elif getmode == 5:
            settypeflood = tld(update.effective_message,
                               'temporarily mute during {}'.format(getvalue))
        if conn:
            text = tld(
                update.effective_message,
                "If the member sends a message straight, then he will *di {}* on *{}*."
            ).format(settypeflood, chat_name)
        else:
            text = tld(
                update.effective_message,
                "If the member sends a message straight, then he will *di {}*."
            ).format(settypeflood)
        msg.reply_text(text, parse_mode=ParseMode.MARKDOWN)
    return ""