Esempio n. 1
0
def __chat_settings__(chat_id, user_id):
    limit = sql.get_flood_limit(chat_id)
    soft_flood = sql.get_flood_strength(chat_id)
    if limit == 0:
        return "*Not* currently enforcing flood control."
    else:
        if soft_flood:
            return "Anti-flood is set to `{}` messages and *KICK* if exceeded.".format(
                limit)
        else:
            return "Anti-flood is set to `{}` messages and *BAN* if exceeded.".format(
                limit)
Esempio n. 2
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]

    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. 3
0
def check_flood(bot: Bot, update: Update) -> 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 ""

    soft_flood = sql.get_flood_strength(chat.id)
    if soft_flood:  # kick
        chat.unban_member(user.id)
        reply = "Wonderful, I don't like your flooding. Get out! {} has been kicked!".format(
            mention_html(user.id, user.first_name))

    else:  # ban
        chat.kick_member(user.id)
        reply = "Frankly, I like to leave the flooding to natural disasters. {} has been banned!".format(
            mention_html(user.id, user.first_name))
    try:
        keyboard = []
        msg.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML)
        msg.delete()
        return "<b>{}:</b>" \
               "\n#FLOOD_CTL" \
               "\n<b>• User:</b> {}" \
               "\nFlooded the group.".format(html.escape(chat.title),
                                             mention_html(user.id, user.first_name))

    except BadRequest:
        msg.reply_text(
            "I can't kick 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 kick permissions, so automatically disabled anti-flood.".format(chat.title)
Esempio n. 4
0
def flood(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    limit = sql.get_flood_limit(chat.id)
    if limit == 0:
        update.effective_message.reply_text(
            "I'm not currently enforcing flood control!")
    else:
        soft_flood = sql.get_flood_strength(chat.id)
        if soft_flood:
            msg.reply_text(
                "I'm currently kicking users out if they send more than {} "
                "consecutive messages. They will able to join again!".format(
                    limit, parse_mode=ParseMode.MARKDOWN))
        else:
            msg.reply_text(
                "I'm currently banning users if they send more than {} "
                "consecutive messages.".format(limit,
                                               parse_mode=ParseMode.MARKDOWN))