Ejemplo n.º 1
0
def get_whitelist(user_id):
    user = SESSION.query(PMTable).get(user_id)
    rep = ""
    if user:
        rep = str(user.boolvalue)
    SESSION.close()
    return rep
Ejemplo n.º 2
0
def get_credential(chat_id):
    with INSERTION_LOCK:
        saved_cred = SESSION.query(gDriveCreds).get(chat_id)
        creds = None
        if saved_cred is not None:
            creds = pickle.loads(saved_cred.credential_string)
        return creds
Ejemplo n.º 3
0
def save_note(user_id, note_name, note_data, msgtype, file_id=None, file_ref=None):
    global SELF_NOTES
    with INSERTION_LOCK:
        prev = SESSION.query(Notes).get((user_id, note_name))
        if prev:
            SESSION.delete(prev)
        note = Notes(
            user_id,
            note_name,
            note_data,
            msgtype=int(msgtype),
            file_id=file_id,
            file_ref=file_ref,
        )
        SESSION.add(note)
        SESSION.commit()

        if not SELF_NOTES.get(user_id):
            SELF_NOTES[user_id] = {}
        SELF_NOTES[user_id][note_name] = {
            "value": note_data,
            "type": msgtype,
            "file_id": file_id,
            "file_ref": file_ref,
        }
Ejemplo n.º 4
0
def __load_mychats():
    global MY_ALL_CHATS, MY_ADMIN_CHATS
    try:
        MY_ALL_CHATS = {}
        qall = SESSION.query(MyChats).all()
        for x in qall:
            MY_ALL_CHATS[x.chat_id] = {"name": x.chat_name, "username": x.chat_username}
    finally:
        SESSION.close()
Ejemplo n.º 5
0
def get_msg_id(user_id):
    try:
        user = SESSION.query(MsgID).get(user_id)
        msg_id = None
        if user:
            msg_id = user.msg_id
            return msg_id
    finally:
        SESSION.close()
Ejemplo n.º 6
0
def ungmute(sender):
    global GMUTE_USERS
    with INSERTION_LOCK:
        rem = SESSION.query(GMute).get(sender)
        if rem:
            GMUTE_USERS.remove(sender)
            SESSION.delete(rem)
            SESSION.commit()
        return
Ejemplo n.º 7
0
def get_antiservice(chat_id):
    try:
        x = SESSION.query(AntiService).get(str(chat_id))
        if x.is_enabled:
            return True
        else:
            return False
    finally:
        SESSION.close()
Ejemplo n.º 8
0
def __load_afk():
    global MY_AFK
    try:
        MY_AFK = {}
        qall = SESSION.query(AFK).all()
        for x in qall:
            MY_AFK[int(x.user_id)] = {"afk": x.is_afk, "reason": x.reason}
    finally:
        SESSION.close()
Ejemplo n.º 9
0
def set_afk(afk, reason):
    global MY_AFK
    afk_db = SESSION.query(AFK).get(str(OWNER_ID))
    if afk_db:
        SESSION.delete(afk_db)
    afk_db = AFK(OWNER_ID, afk, reason)
    SESSION.add(afk_db)
    SESSION.commit()
    MY_AFK[OWNER_ID] = {"afk": afk, "reason": reason}
Ejemplo n.º 10
0
def set_credential(chat_id, credential_string):
    with INSERTION_LOCK:
        saved_cred = SESSION.query(gDriveCreds).get(chat_id)
        if not saved_cred:
            saved_cred = gDriveCreds(chat_id)

        saved_cred.credential_string = pickle.dumps(credential_string)

        SESSION.add(saved_cred)
        SESSION.commit()
Ejemplo n.º 11
0
def __load_mychats():
    global ANTISERVICE_CHATS
    try:
        ANTISERVICE_CHATS = []
        qall = SESSION.query(AntiService).all()
        for x in qall:
            if x.is_enabled:
                ANTISERVICE_CHATS.append(x.chat_id)
    finally:
        SESSION.close()
Ejemplo n.º 12
0
def disable_antiservice(chat_id, vbool=False):
    try:
        enabled = SESSION.query(AntiService).get(str(chat_id))
        if enabled:
            SESSION.delete(enabled)
        enabled = AntiService(chat_id, vbool)
        SESSION.add(enabled)
        SESSION.commit()
    finally:
        SESSION.close()
Ejemplo n.º 13
0
def del_whitelist(user_id):
    with INSERTION_LOCK:
        user = SESSION.query(PMTable).get(user_id)
        try:
            if user:
                SESSION.delete(user)
                SESSION.commit()
        finally:
            SESSION.close()
        return False
Ejemplo n.º 14
0
def rm_note(user_id, note_name):
    global SELF_NOTES
    with INSERTION_LOCK:
        note = SESSION.query(Notes).get((user_id, note_name))
        if note:
            SESSION.delete(note)
            SESSION.commit()
            SELF_NOTES[user_id].pop(note_name)
            return True
        else:
            SESSION.close()
            return False
Ejemplo n.º 15
0
def __load_all_notes():
    global SELF_NOTES
    getall = SESSION.query(Notes).distinct().all()
    for x in getall:
        if not SELF_NOTES.get(x.user_id):
            SELF_NOTES[x.user_id] = {}
        SELF_NOTES[x.user_id][x.name] = {
            "value": x.value,
            "type": x.msgtype,
            "file_id": x.file_id,
            "file_ref": x.file_ref,
        }
Ejemplo n.º 16
0
def set_last_msg_id(user_id, msg_id):
    with INSERTION_LOCK:
        try:
            user = SESSION.query(MsgID).get(user_id)
            if not user:
                user = MsgID(user_id, msg_id)
            else:
                user.msg_id = msg_id
            SESSION.merge(user)
            SESSION.commit()
        finally:
            SESSION.close()
Ejemplo n.º 17
0
def update_chat(chat):
    global MY_ALL_CHATS
    if (chat.id in list(MY_ALL_CHATS) and MY_ALL_CHATS.get(chat.id)
            and MY_ALL_CHATS[chat.id].get("name") == chat.title
            and MY_ALL_CHATS[chat.id].get("username") == chat.username):
        return
    chat_db = SESSION.query(MyChats).get(str(chat.id))
    if chat_db:
        SESSION.delete(chat_db)
    chat_db = MyChats(str(chat.id), chat.title, chat.username)
    SESSION.add(chat_db)
    SESSION.commit()
    MY_ALL_CHATS[chat.id] = {"name": chat.title, "username": chat.username}
Ejemplo n.º 18
0
def set_whitelist(user_id, boolvalue):
    with INSERTION_LOCK:
        user = SESSION.query(PMTable).get(user_id)
        try:
            if not user:
                user = PMTable(user_id, boolvalue)
            else:
                user.boolvalue = str(boolvalue)
            SESSION.add(user)
            SESSION.commit()
        finally:
            SESSION.close()
    return user_id
Ejemplo n.º 19
0
def clear_credential(chat_id):
    with INSERTION_LOCK:
        saved_cred = SESSION.query(gDriveCreds).get(chat_id)
        if saved_cred:
            SESSION.delete(saved_cred)
            SESSION.commit()
Ejemplo n.º 20
0
def get_all_chats():
    try:
        return SESSION.query(MyChats).all()
    finally:
        SESSION.close()
Ejemplo n.º 21
0
def __load_all_gmute_users():
    global GMUTE_USERS
    getall = SESSION.query(GMute).all()
    for x in getall:
        GMUTE_USERS.append(x)
    return
Ejemplo n.º 22
0
def get_num_notes(user_id):
    try:
        num_notes = SESSION.query(Notes).count()
        return num_notes
    finally:
        SESSION.close()