Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
0
def approve(chat_id, user_id):
    with INSERTION_LOCK:
        note = Approvals(str(chat_id), user_id)
        SESSION.add(note)
        SESSION.commit()