Esempio n. 1
0
def ungban_quicc(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message
    try:
        user_id = int(args[0])
    except Exception:
        return
    sql.ungban_user(user_id)
    message.reply_text(
        f"Yeety mighty your mom is gay, {user_id} have been ungbanned.")
Esempio n. 2
0
def clear_gbans(bot: Bot, update: Update):
    banned = sql.get_gban_list()
    deleted = 0
    update.message.reply_text(
        "*Beginning to cleanup deleted users from global ban database...*\nThis process might take a while...",
        parse_mode=ParseMode.MARKDOWN)
    for user in banned:
        id = user["user_id"]
        time.sleep(0.1)  # Reduce floodwait
        try:
            bot.get_chat(id)
        except BadRequest:
            deleted += 1
            sql.ungban_user(id)
    update.message.reply_text("Done! {} deleted accounts were removed " \
    "from the gbanlist.".format(deleted), parse_mode=ParseMode.MARKDOWN)
Esempio n. 3
0
def ungban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message
    chat = update.effective_chat

    user_id, reason = extract_user_and_text(message, args)

    reason = html.escape(reason)

    if not user_id:
        message.reply_text(tld(chat.id, "common_err_no_user"))
        return

    user_chat = bot.get_chat(user_id)
    if user_chat.type != 'private':
        message.reply_text(tld(chat.id, "antispam_err_not_usr"))
        return

    if not sql.is_user_gbanned(user_id):
        message.reply_text(tld(chat.id, "antispam_user_not_gbanned"))
        return

    if not reason:
        message.reply_text(
            "Removal of Global Ban requires a reason to do so, why not send me one?"
        )
        return

    banner = update.effective_user

    message.reply_text(
        "<b>Initializing Global Ban Removal</b>\n<b>Sudo Admin:</b> {}\n<b>User:</b> {}\n<b>ID:</b> <code>{}</code>\n<b>Reason:</b> {}"
        .format(mention_html(banner.id, banner.first_name),
                mention_html(user_chat.id, user_chat.first_name), user_chat.id,
                reason),
        parse_mode=ParseMode.HTML)

    try:
        bot.send_message(GBAN_DUMP,
                         tld(chat.id, "antispam_logger_ungban").format(
                             mention_html(banner.id, banner.first_name),
                             mention_html(user_chat.id, user_chat.first_name),
                             user_chat.id, reason),
                         parse_mode=ParseMode.HTML)
    except Exception:
        pass

    # 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(
    #                 tld(chat.id, "antispam_err_ungban").format(excp.message))
    #             bot.send_message(
    #                 OWNER_ID,
    #                 tld(chat.id, "antispam_err_ungban").format(excp.message))
    #             return
    #     except TelegramError:
    #         pass

    sql.ungban_user(user_id)

    message.reply_text("This user have been ungbanned succesfully, they might have to ask 'admins' of chats they were banned to unban manually due to global ban." \
                       "\n\nPlease forward this message to them or let them know about this.")
Esempio n. 4
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.")