Esempio n. 1
0
def enforce_gban(bot: Bot, update: Update):
    # Not using @restrict handler to avoid spamming - just ignore if cant gban.
    try:
        if sql.does_chat_gban(
                update.effective_chat.id) and update.effective_chat.get_member(
                    bot.id).can_restrict_members:
            user = update.effective_user
            chat = update.effective_chat
            msg = update.effective_message

            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id)
                return

            if msg.new_chat_members:
                new_members = update.effective_message.new_chat_members
                for mem in new_members:
                    check_and_ban(update, mem.id)
                    return

            if msg.reply_to_message:
                user = msg.reply_to_message.from_user
                if user and not is_user_admin(chat, user.id):
                    check_and_ban(update, user.id, should_message=False)
                    return
    except Exception as f:
        print(f"Nut {f}")
Esempio n. 2
0
def antispam(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_antispam(chat.id)
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I've enabled antispam security in this group. This will help to protect you "
                    "from spammers, unsavoury characters, and the biggest trolls."
                ))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_antispam(chat.id)
            update.effective_message.reply_text(
                tld(
                    chat.id,
                    "I've disabled antispam security in this group. GBans won't affect your users "
                    "anymore. You'll be less protected from any trolls and spammers "
                    "though!"))
    else:
        update.effective_message.reply_text(
            tld(
                chat.id,
                "Give me some arguments to choose a setting! on/off, yes/no!\n\n"
                "Your current setting is: {}\n"
                "When True, any gbans that happen will also happen in your group. "
                "When False, they won't, leaving you at the possible mercy of "
                "spammers.").format(sql.does_chat_gban(chat.id)))
Esempio n. 3
0
def antispam(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_antispam(chat.id)
            update.effective_message.reply_text(tld(chat.id, "antispam_on"))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_antispam(chat.id)
            update.effective_message.reply_text(tld(chat.id, "antispam_off"))
    else:
        update.effective_message.reply_text(
            tld(chat.id,
                "antispam_err_wrong_arg").format(sql.does_chat_gban(chat.id)))
Esempio n. 4
0
def __chat_settings__(bot, update, chat, chatP, user):
    chat_id = chat.id
    return "This chat is enforcing *gbans*: `{}`.".format(
        sql.does_chat_gban(chat_id))
Esempio n. 5
0
def ungban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message  # type: Optional[Message]

    user_id = extract_user(message, args)
    if not user_id or int(user_id) == 777000:
        message.reply_text("You don't seem to be referring to a user.")
        return

    user_chat = bot.get_chat(user_id)
    if user_chat.type != 'private':
        message.reply_text("That's not a user!")
        return

    if not sql.is_user_gbanned(user_id):
        message.reply_text("This user is not gbanned!")
        return

    banner = update.effective_user  # type: Optional[User]

    # message.reply_text("{}, will be unbanned globally.".format(user_chat.first_name or "Deleted Account"))

    bot.send_message(MESSAGE_DUMP,
                 "<b>Regression of Global Ban</b>" \
                 "\n#UNGBAN" \
                 "\n<b>Sudo Admin:</b> {}" \
                 "\n<b>User:</b> {}" \
                 "\n<b>ID:</b> <code>{}</code>".format(mention_html(banner.id, banner.first_name),
                                                       mention_html(user_chat.id, user_chat.first_name or "Deleted Account"),
                                                                    user_chat.id),
                 parse_mode=ParseMode.HTML)

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id

        # Check if this group has disabled gbans
        if not sql.does_chat_gban(chat_id):
            continue

        try:
            member = bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                bot.unban_chat_member(chat_id, user_id)

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                message.reply_text("Could not un-gban due to: {}".format(
                    excp.message))
                bot.send_message(
                    OWNER_ID,
                    "Could not un-gban due to: {}".format(excp.message))
                return
        except TelegramError:
            pass

    sql.ungban_user(user_id)

    bot.send_message(MESSAGE_DUMP, "un-gban complete!")

    message.reply_text("Person has been un-gbanned.")