<commit_before>import json
import time
import logging
from collections import UserDict
import argparse
import datetime
import re

from pajbot.tbutil import find
from pajbot.models.db import DBManager, Base
from pajbot.models.action import ActionParser, RawFuncAction, FuncAction
from pajbot.managers.redis import RedisManager

import sqlalchemy
from sqlalchemy import orm
from sqlalchemy.orm import relationship, joinedload
from sqlalchemy import Column, Integer, Boolean, DateTime, ForeignKey, String, Enum
from sqlalchemy.dialects.mysql import TEXT

log = logging.getLogger('pajbot')

class Banphrase(Base):
    __tablename__ = 'tb_banphrase'

    id = Column(Integer, primary_key=True)
    name = Column(String(256), nullable=False, default='')
    phrase = Column(String(256), nullable=False)
    length = Column(Integer, nullable=False, default=300)
    permanent = Column(Boolean, nullable=False, default=False)
    warning = Column(Boolean, nullable=False, default=True)
    notify = Column(Boolean, nullable=False, default=True)
    case_sensitive = Column(Boolean, nullable=False, default=False)
    enabled = Column(Boolean, nullable=False, default=True)
    operator = Column(Enum('contains', 'startswith', 'endswith'),
            nullable=False,
            default='contains',
            server_default='contains')

    data = relationship('BanphraseData',
            uselist=False,
            cascade='',
            lazy='joined')

    DEFAULT_TIMEOUT_LENGTH = 300
    DEFAULT_NOTIFY = True

    def __init__(self, **options):
        self.id = None
        self.name = 'No name'
        self.length = self.DEFAULT_TIMEOUT_LENGTH
        self.permanent = False
        self.warning = True
        self.notify = self.DEFAULT_NOTIFY
        self.case_sensitive = False
        self.enabled = True
        self.operator = 'contains'

        self.set(**options)

    def set(self, **options):
        self.name = options.get('name', self.name)
        self.phrase = options.get('phrase', self.phrase)
        self.length = options.get('length', self.length)
        self.permanent = options.get('permanent', self.permanent)
        self.warning = options.get('warning', self.warning)
        self.notify = options.get('notify', self.notify)
        self.case_sensitive = options.get('case_sensitive', self.case_sensitive)
        self.enabled = options.get('enabled', self.enabled)
        self.operator = options.get('operator', self.operator)<commit_msg>Make sure to refresh the operator on newly created banphrases<commit_after>import json
import time
import logging
from collections import UserDict
import argparse
import datetime
import re

from pajbot.tbutil import find
from pajbot.models.db import DBManager, Base
from pajbot.models.action import ActionParser, RawFuncAction, FuncAction
from pajbot.managers.redis import RedisManager

import sqlalchemy
from sqlalchemy import orm
from sqlalchemy.orm import relationship, joinedload
from sqlalchemy import Column, Integer, Boolean, DateTime, ForeignKey, String, Enum
from sqlalchemy.dialects.mysql import TEXT

log = logging.getLogger('pajbot')

class Banphrase(Base):
    __tablename__ = 'tb_banphrase'

    id = Column(Integer, primary_key=True)
    name = Column(String(256), nullable=False, default='')
    phrase = Column(String(256), nullable=False)
    length = Column(Integer, nullable=False, default=300)
    permanent = Column(Boolean, nullable=False, default=False)
    warning = Column(Boolean, nullable=False, default=True)
    notify = Column(Boolean, nullable=False, default=True)
    case_sensitive = Column(Boolean, nullable=False, default=False)
    enabled = Column(Boolean, nullable=False, default=True)
    operator = Column(Enum('contains', 'startswith', 'endswith'),
            nullable=False,
            default='contains',
            server_default='contains')

    data = relationship('BanphraseData',
            uselist=False,
            cascade='',
            lazy='joined')

    DEFAULT_TIMEOUT_LENGTH = 300
    DEFAULT_NOTIFY = True

    def __init__(self, **options):
        self.id = None
        self.name = 'No name'
        self.length = self.DEFAULT_TIMEOUT_LENGTH
        self.permanent = False
        self.warning = True
        self.notify = self.DEFAULT_NOTIFY
        self.case_sensitive = False
        self.enabled = True
        self.operator = 'contains'

        self.set(**options)

    def set(self, **options):
        self.name = options.get('name', self.name)
        self.phrase = options.get('phrase', self.phrase)
        self.length = options.get('length', self.length)
        self.permanent = options.get('permanent', self.permanent)
        self.warning = options.get('warning', self.warning)
        self.notify = options.get('notify', self.notify)
        self.case_sensitive = options.get('case_sensitive', self.case_sensitive)
        self.enabled = options.get('enabled', self.enabled)
        self.operator = options.get('operator', self.operator)

        self.refresh_operator()
{'fraction_non_alphanumeric': 0.10487562189054726, 'fraction_numerical': 0.004776119402985075, 'mean_word_length': 3.4915102770330653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6170453', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1415, 'n_words': 347}