Esempio n. 1
0
def del_user(user_id):
    with INSERTION_LOCK:
        curr = SESSION.query(Users).get(user_id)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()
            return
Esempio n. 2
0
def update_user(user_id, username, chat_id=None, chat_name=None):
    with INSERTION_LOCK:
        user = SESSION.query(Users).get(user_id)
        if not user:
            user = Users(user_id, username)
            SESSION.add(user)
            SESSION.flush()
        else:
            user.username = username

        if not chat_id or not chat_name:
            SESSION.commit()
            return

        chat = SESSION.query(Chats).get(str(chat_id))
        if not chat:
            chat = Chats(str(chat_id), chat_name)
            SESSION.add(chat)
            SESSION.flush()

        else:
            chat.chat_name = chat_name
        SESSION.commit()
        SESSION.close()
    return
Esempio n. 3
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        old_chat = SESSION.query(Chats).get(str(old_chat_id))
        if old_chat:
            old_chat.chat_id = str(new_chat_id)
            SESSION.merge(old_chat)
        SESSION.commit()
        SESSION.close()
Esempio n. 4
0
def set_chat_setting(chat_id: Union[int, str], setting: bool):
    with CHAT_LOCK:
        chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id))
        if not chat_setting:
            chat_setting = ReportingChatSettings(chat_id)

        chat_setting.should_report = setting
        SESSION.add(chat_setting)
        SESSION.commit()
Esempio n. 5
0
def set_user_setting(user_id: int, setting: bool):
    with USER_LOCK:
        user_setting = SESSION.query(ReportingUserSettings).get(user_id)
        if not user_setting:
            user_setting = ReportingUserSettings(user_id)

        user_setting.should_report = setting
        SESSION.add(user_setting)
        SESSION.commit()
Esempio n. 6
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        try:
            chat = SESSION.query(Rules).get(str(old_chat_id))
            if chat:
                chat.chat_id = str(new_chat_id)
            SESSION.commit()
        finally:
            SESSION.close()
Esempio n. 7
0
def disapprove(chat_id, user_id):
    with INSERTION_LOCK:
        note = SESSION.query(Approvals).get((str(chat_id), user_id))
        if note:
            SESSION.delete(note)
            SESSION.commit()
            return True
        else:
            SESSION.close()
            return False
Esempio n. 8
0
def add_to_blacklist(chat_id, trigger):
    with INSERTION_LOCK:
        try:
            blacklist_filt = BlackListFilters(str(chat_id), trigger)

            SESSION.merge(blacklist_filt)
            SESSION.commit()
            CHAT_BLACKLISTS.setdefault(str(chat_id), set()).add(trigger)
        finally:
            SESSION.close()
Esempio n. 9
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        try:
            chat_filters = (SESSION.query(BlackListFilters).filter(
                BlackListFilters.chat_id == str(old_chat_id)).all())
            for filt in chat_filters:
                filt.chat_id = str(new_chat_id)
            SESSION.commit()
        finally:
            SESSION.close()
Esempio n. 10
0
def migrate_chat(old_chat_id, new_chat_id):
    with CHAT_LOCK:
        chat_notes = (
            SESSION.query(ReportingChatSettings)
            .filter(ReportingChatSettings.chat_id == str(old_chat_id))
            .all()
        )
        for note in chat_notes:
            note.chat_id = str(new_chat_id)
        SESSION.commit()
Esempio n. 11
0
def ungban_user(user_id):
    with GBAN_LOCK:
        user = SESSION.query(GloballyBannedUsers).get(user_id)
        try:
            if user:
                SESSION.delete(user)
                SESSION.commit()
        finally:
            SESSION.close()
            __load_gbanned_userid_list()
    return
Esempio n. 12
0
def rem_chat(chat_id):
    with INSERTION_LOCK:
        chat = SESSION.query(Chats).get(str(chat_id))
        if chat:
            try:
                SESSION.delete(chat)
                SESSION.commit()
            finally:
                SESSION.close()
        else:
            SESSION.close()
Esempio n. 13
0
def clear_rules(chat_id):
    with INSERTION_LOCK:
        try:
            rules = SESSION.query(Rules).get(str(chat_id))
            SESSION.delete(rules)
            SESSION.commit()
        except BaseException:
            return False
        finally:
            SESSION.close()
    return True
Esempio n. 14
0
def set_rules(chat_id, rules_text):
    with INSERTION_LOCK:
        try:
            rules = SESSION.query(Rules).get(str(chat_id))
            if not rules:
                rules = Rules(str(chat_id))
            rules.rules = rules_text

            SESSION.add(rules)
            SESSION.commit()
        finally:
            SESSION.close()
Esempio n. 15
0
def rm_note(chat_id, note_name):
    global CHAT_NOTES
    with INSERTION_LOCK:
        note = SESSION.query(Notes).get((str(chat_id), note_name))
        if note:
            SESSION.delete(note)
            SESSION.commit()
            CHAT_NOTES[str(chat_id)].pop(note_name)
            return True

        else:
            SESSION.close()
            return False
Esempio n. 16
0
def gban_user(user_id, name, reason=None):
    with GBAN_LOCK:
        user = SESSION.query(GloballyBannedUsers).get(user_id)
        try:
            if not user:
                user = GloballyBannedUsers(user_id, name, reason)
            else:
                user.reason = reason
                user.name = name
            SESSION.merge(user)
            SESSION.commit()
        finally:
            SESSION.close()
    __load_gbanned_userid_list()
    return
Esempio n. 17
0
def rm_from_blacklist(chat_id, trigger):
    with INSERTION_LOCK:
        try:
            blacklist_filt = SESSION.query(BlackListFilters).get(
                (str(chat_id), trigger))
            if blacklist_filt:
                if trigger in CHAT_BLACKLISTS.get(str(chat_id), set()):
                    CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger)

                SESSION.delete(blacklist_filt)
                SESSION.commit()
                return True
        finally:
            SESSION.close()
        return False
Esempio n. 18
0
def update_gban_reason(user_id, name, reason=None):
    with GBAN_LOCK:
        try:
            user = SESSION.query(GloballyBannedUsers).get(user_id)
            if not user:
                user = GloballyBannedUsers(user_id, name, reason)
                old_reason = ""
            else:
                old_reason = user.reason
                user.name = name
                user.reason = reason
            SESSION.merge(user)
            SESSION.commit()
        finally:
            SESSION.close()
    return old_reason
Esempio n. 19
0
def rm_all_note(chat_id):
    global CHAT_NOTES
    with INSERTION_LOCK:
        all_notes = get_all_notes(chat_id)
        for note_name in all_notes:
            note = SESSION.query(Notes).get((str(chat_id), note_name))
            if note:
                try:
                    SESSION.delete(note)
                    SESSION.commit()
                    CHAT_NOTES[str(chat_id)].pop(note_name)
                except:
                    pass
            SESSION.close()
        del CHAT_NOTES[str(chat_id)]
    return True
Esempio n. 20
0
def save_note(chat_id, note_name, note_data, msgtype, file=None):
    global CHAT_NOTES
    with INSERTION_LOCK:
        prev = SESSION.query(Notes).get((str(chat_id), note_name))
        if prev:
            SESSION.delete(prev)
        note = Notes(str(chat_id), note_name, note_data, msgtype, file)
        SESSION.add(note)
        SESSION.commit()

        if not CHAT_NOTES.get(chat_id):
            CHAT_NOTES[chat_id] = {}
        CHAT_NOTES[chat_id][note_name] = {
            "value": note_data,
            "type": msgtype,
            "file": file,
        }
Esempio n. 21
0
def disapprove_all(chat_id):
    users_list = []
    try:
        users = (SESSION.query(Approvals).filter(
            Approvals.chat_id == str(chat_id)).order_by(
                Approvals.user_id.asc()).all())
        for i in users:
            users_list.append(int(i.user_id))
        with INSERTION_LOCK:
            for user_id in users_list:
                note = SESSION.query(Approvals).get((str(chat_id), user_id))
                if note:
                    SESSION.delete(note)
                    SESSION.commit()
                else:
                    SESSION.close()
        return True
    except:
        return False
Esempio n. 22
0
def approve(chat_id, user_id):
    with INSERTION_LOCK:
        note = Approvals(str(chat_id), user_id)
        SESSION.add(note)
        SESSION.commit()