Ejemplo n.º 1
0
def blacklist(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message
    chat = update.effective_chat

    update_chat_title = chat.title
    message_chat_title = update.effective_message.chat.title

    if update_chat_title == message_chat_title:
        base_blacklist_string = "Current <b>blacklisted</b> words:\n"
    else:
        base_blacklist_string = f"Current <b>blacklisted</b> words in <b>{update_chat_title}</b>:\n"

    all_blacklisted = sql.get_chat_blacklist(chat.id)

    filter_list = base_blacklist_string

    if len(args) > 0 and args[0].lower() == 'copy':
        for trigger in all_blacklisted:
            filter_list += f"<code>{html.escape(trigger)}</code>\n"
    else:
        for trigger in all_blacklisted:
            filter_list += f" - <code>{html.escape(trigger)}</code>\n"

    split_text = split_message(filter_list)
    for text in split_text:
        if text == base_blacklist_string:
            if update_chat_title == message_chat_title:
                msg.reply_text("There are no blacklisted messages here!")
            else:
                msg.reply_text(
                    f"There are no blacklisted messages in <b>{update_chat_title}</b>!",
                    parse_mode=ParseMode.HTML)
            return
        msg.reply_text(text, parse_mode=ParseMode.HTML)
Ejemplo n.º 2
0
def del_blacklist(update: Update, _):
    chat = update.effective_chat
    message = update.effective_message
    to_match = extract_text(message)

    if not to_match:
        return

    chat_filters = sql.get_chat_blacklist(chat.id)
    for trigger in chat_filters:
        pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])"
        if re.search(pattern, to_match, flags=re.IGNORECASE):
            try:
                message.delete()
            except BadRequest as excp:
                if excp.message != 'Message to delete not found':
                    LOGGER.exception('Error while deleting blacklist message.')
            break
Ejemplo n.º 3
0
def blacklist(update: Update, context: CallbackContext):
    msg = update.effective_message
    chat = update.effective_chat
    args = context.args
    update_chat_title = chat.title
    message_chat_title = update.effective_message.chat.title

    if update_chat_title == message_chat_title:
        base_blacklist_string = "Current <b>blacklisted</b> words:\n"
    else:
        base_blacklist_string = (
            f"Current <b>blacklisted</b> words in <b>{update_chat_title}</b>:\n"
        )

    all_blacklisted = sql.get_chat_blacklist(chat.id)

    filter_list = base_blacklist_string

    if args and args[0].lower() == "copy":
        for trigger in all_blacklisted:
            filter_list += f"<code>{html.escape(trigger)}</code>\n"
    else:
        for trigger in all_blacklisted:
            filter_list += f" - <code>{html.escape(trigger)}</code>\n"

    split_text = split_message(filter_list)
    for text in split_text:
        if text == base_blacklist_string:
            if update_chat_title == message_chat_title:
                msg.reply_text("There are no blacklisted messages here!")
            else:
                msg.reply_text(
                    f"There are no blacklisted messages in <b>{update_chat_title}</b>!",
                    parse_mode=ParseMode.HTML,
                )
            return
        msg.reply_text(text, parse_mode=ParseMode.HTML)