Exemplo n.º 1
0
def add_to_blacklist(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = BlackListFilters(str(chat_id), trigger)

        SESSION.merge(blacklist_filt)  # merge to avoid duplicate key issues
        SESSION.commit()
        CHAT_BLACKLISTS.setdefault(str(chat_id), set()).add(trigger)
Exemplo n.º 2
0
def add_warn_filter(chat_id, keyword, reply):
    with WARN_FILTER_INSERTION_LOCK:
        warn_filt = WarnFilters(str(chat_id), keyword, reply)

        if keyword not in WARN_FILTERS.get(str(chat_id), []):
            WARN_FILTERS[str(chat_id)] = sorted(
                WARN_FILTERS.get(str(chat_id), []) + [keyword],
                key=lambda x: (-len(x), x))

        SESSION.merge(warn_filt)  # merge to avoid duplicate key issues
        SESSION.commit()
Exemplo n.º 3
0
def spam_whitelist(user_id, name):
    with SPAMWATCH_WHITELIST:
        user = SESSION.query(SpamWatchUsers).get(user_id)
        if not user:
            user = SpamWatchUsers(user_id, name)
        else:
            user.name = name

        SESSION.merge(user)
        SESSION.commit()
        __load_spamwatch_userid_list()
Exemplo n.º 4
0
def update_gmute_reason(user_id, name, reason=None):
    with GMUTED_USERS_LOCK:
        user = SESSION.query(GloballyMutedUsers).get(user_id)
        if not user:
            return None
        old_reason = user.reason
        user.name = name
        user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        return old_reason
Exemplo n.º 5
0
def gmute_user(user_id, name, reason=None):
    with GMUTED_USERS_LOCK:
        user = SESSION.query(GloballyMutedUsers).get(user_id)
        if not user:
            user = GloballyMutedUsers(user_id, name, reason)
        else:
            user.name = name
            user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        __load_gmuted_userid_list()
Exemplo n.º 6
0
def ensure_bot_in_db():
    with INSERTION_LOCK:
        bot = Users(dispatcher.bot.id, dispatcher.bot.username)
        SESSION.merge(bot)
        SESSION.commit()