def check_and_ban(update, user_id, should_message=True):
    chat = update.effective_chat  # type: Optional[Chat]
    try:
        sw_ban = sw.get_ban(int(user_id))
    except AttributeError:
        sw_ban = None
    except (SpamWatchError, Error, UnauthorizedError, NotFoundError, Forbidden,
            TooManyRequests) as e:
        log.warning(f" SpamWatch Error: {e}")
        sw_ban = None

    if sw_ban:
        chat.ban_member(user_id)
        if should_message:
            update.effective_message.reply_text(
                f"This person has been detected as a spammer by @SpamWatch and has been removed!\nReason: <code>{sw_ban.reason}</code>",
                parse_mode=ParseMode.HTML,
            )
        return

    if sql.is_user_gbanned(user_id):
        update.effective_chat.ban_member(user_id)
        if should_message:
            text = (f"<b>Alert</b>: this user is globally banned.\n"
                    f"<code>*bans them from here*</code>.\n"
                    f"<b>Appeal chat</b>: @YorkTownEagleUnion\n"
                    f"<b>User ID</b>: <code>{user_id}</code>")
            user = sql.get_gbanned_user(user_id)
            if user.reason:
                text += f"\n<b>Ban Reason:</b> <code>{html.escape(user.reason)}</code>"
            update.effective_message.reply_text(text,
                                                parse_mode=ParseMode.HTML)
Esempio n. 2
0
def __user_info__(user_id, chat_id):
    is_gbanned = sql.is_user_gbanned(user_id)
    is_gmuted = sql.is_user_gmuted(user_id)

    text = tld(chat_id, "Globally banned: <b>{}</b>")
    if is_gbanned:
        text = text.format(tld(chat_id, "Yes"))
        user = sql.get_gbanned_user(user_id)
        if user.reason:
            text += tld(chat_id,
                        "\nReason: {}").format(html.escape(user.reason))
    else:
        text = text.format(tld(chat_id, "No"))

    text += tld(chat_id, "\nGlobally muted: <b>{}</b>")
    if is_gmuted:
        text = text.format(tld(chat_id, "Yes"))
        user = sql.get_gmuted_user(user_id)
        if user.reason:
            text += tld(chat_id,
                        "\nReason: {}").format(html.escape(user.reason))
    else:
        text = text.format(tld(chat_id, "No"))

    return text
Esempio n. 3
0
def read_item(user_id: int):
    try:
        a = sql1.is_user_gbanned(user_id)
        if a:
            user = sql1.get_gbanned_user(user_id)
            areason = user.reason
        else:
            areason = None

        b = sql2.is_user_blacklisted(user_id)
        breason = sql2.get_reason(user_id) if b else None
        return {
            "status": "ok",
            "user_id": user_id,
            "gbanned": a,
            "gban_reason": areason,
            "blacklisted": b,
            "blacklist_reason": breason
        }
    except Exception:
        a = None
        areason = None
        b = None
        breason = None
        return {
            "status": "ok",
            "user_id": user_id,
            "gbanned": a,
            "gban_reason": areason,
            "blacklisted": b,
            "blacklist_reason": breason
        }
def check_and_ban(update, user_id, should_message=True):
    from tg_bot import SPB_MODE
    chat = update.effective_chat  # type: Optional[Chat]
    if SPB_MODE:
        try:
            apst = requests.get(
                f'https://api.intellivoid.net/spamprotection/v1/lookup?query={update.effective_user.id}')
            api_status = apst.status_code
            if api_status == 200:
                try:
                    status = client.raw_output(int(user_id))
                    try:
                        bl_check = (status["results"]["attributes"]["is_blacklisted"])
                    except:
                        bl_check = False

                    if bl_check:
                        bl_res = (status["results"]["attributes"]["blacklist_reason"])
                        update.effective_chat.kick_member(user_id)
                        if should_message:
                            update.effective_message.reply_text(
                                f"This person was blacklisted on @SpamProtectionBot and has been removed!\nReason: <code>{bl_res}</code>",
                                parse_mode=ParseMode.HTML,
                            )
                except HostDownError:
                    log.warning("Spam Protection API is unreachable.")
        except BaseException as e:
            log.info(f'SpamProtection was disabled due to {e}')
    try:
        sw_ban = sw.get_ban(int(user_id))
    except AttributeError:
        sw_ban = None
    except (SpamWatchError, Error, UnauthorizedError, NotFoundError, Forbidden, TooManyRequests) as e:
        log.warning(f" SpamWatch Error: {e}")
        sw_ban = None

    if sw_ban:
        update.effective_chat.kick_member(user_id)
        if should_message:
            update.effective_message.reply_text(
                f"This person has been detected as a spammer by @SpamWatch and has been removed!\nReason: <code>{sw_ban.reason}</code>",
                parse_mode=ParseMode.HTML,
            )
        return

    if sql.is_user_gbanned(user_id):
        update.effective_chat.kick_member(user_id)
        if should_message:
            text = (
                f"<b>Alert</b>: this user is globally banned.\n"
                f"<code>*bans them from here*</code>.\n"
                f"<b>Appeal chat</b>: @zerounions\n"
                f"<b>User ID</b>: <code>{user_id}</code>"
            )
            user = sql.get_gbanned_user(user_id)
            if user.reason:
                text += f"\n<b>Ban Reason:</b> <code>{html.escape(user.reason)}</code>"
            update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
Esempio n. 5
0
def check_and_ban(update, user_id, should_message=True):

    chat = update.effective_chat  # type: Optional[Chat]
    if SPB_MODE:
        try:
            status = client.raw_output(int(user_id))
            try:
                bl_check = (status["results"]["attributes"]["is_blacklisted"])
            except:
                bl_check = False

            if bl_check is True:
                bl_res = (status["results"]["attributes"]["blacklist_reason"])
                update.effective_chat.kick_member(user_id)
                if should_message:
                    update.effective_message.reply_text(
                        f"This person was blacklisted on @SpamProtectionBot and has been removed!\nReason: <code>{bl_res}</code>",
                        parse_mode=ParseMode.HTML,
                    )
        except HostDownError:
            log.warning("Spam Protection API is unreachable.")

    try:
        sw_ban = sw.get_ban(int(user_id))
    except AttributeError:
        sw_ban = None
    except (SpamWatchError, Error, UnauthorizedError, NotFoundError, Forbidden,
            TooManyRequests) as e:
        log.warning(f" SpamWatch Error: {e}")
        sw_ban = None

    if sw_ban:
        update.effective_chat.kick_member(user_id)
        if should_message:
            update.effective_message.reply_text(
                f"This person has been detected as a spammer by @SpamWatch and has been removed!\nReason: <code>{sw_ban.reason}</code>",
                parse_mode=ParseMode.HTML,
            )
        return

    if sql.is_user_gbanned(user_id):
        update.effective_chat.kick_member(user_id)
        if should_message:
            text = (f"<b>Alert</b>: this user is globally banned.\n"
                    f"<code>*bans them from here*</code>.\n"
                    f"<b>Appeal chat</b>: @YorkTownEagleUnion\n"
                    f"<b>User ID</b>: <code>{user_id}</code>")
            user = sql.get_gbanned_user(user_id)
            if user.reason:
                text += f"\n<b>Ban Reason:</b> <code>{html.escape(user.reason)}</code>"
            update.effective_message.reply_text(text,
                                                parse_mode=ParseMode.HTML)
Esempio n. 6
0
def __user_info__(user_id):
    if user_id in (777000, 1087968824):
        return ""

    is_gbanned = sql.is_user_gbanned(user_id)
    text = "Gbanned: <b>{}</b>"
    if user_id in [777000, 1087968824]:
        return ""
    if user_id == dispatcher.bot.id:
        return ""
    if int(user_id) in SUDO_USERS + SARDEGNA_USERS + WHITELIST_USERS:
        return ""
    if is_gbanned:
        text = text.format("Yes")
        user = sql.get_gbanned_user(user_id)
        if user.reason:
            text += f"\n<b>Reason:</b> <code>{html.escape(user.reason)}</code>"
        text += f"\n<b>Appeal Chat:</b> @YorkTownEagleUnion"
    else:
        text = text.format("No")
    return text