示例#1
0
def get_req(user_id):
    user = SESSION.query(ReqUsers).get(str(user_id))
    rep = ''
    if user:
        rep = str(user.username)

    SESSION.close()
    return rep
示例#2
0
def get_whitelist(user_id):
    user = SESSION.query(WhitelistUsers).get(str(user_id))
    rep = ''
    if user:
        rep = str(user.username)

    SESSION.close()
    return rep
示例#3
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()
示例#4
0
def add_fav(user_id, data):
    with FAV_INSERTION_LOCK:
        to_check = check_fav(user_id, data)
        if not to_check:
            adder = Favourites(int(user_id), str(data))
            SESSION.add(adder)
            SESSION.commit()
            return True
        return False
示例#5
0
def remove_fav(user_id):
    with FAV_INSERTION_LOCK:
        to_check = get_fav(user_id)
        if not to_check:
            return False
        rem = SESSION.query(Favourites).filter(Favourites.user_id == user_id)
        rem.delete()
        SESSION.commit()
        return True
示例#6
0
def set_req(user_id, username):
    with INSERTION_LOCK:
        user = SESSION.query(ReqUsers).get(str(user_id))
        if not user:
            user = ReqUsers(str(user_id), str(username))
        else:
            user.username = str(username)

        SESSION.add(user)
        SESSION.commit()
示例#7
0
def set_whitelist(user_id, username):
    with INSERTION_LOCK:
        user = SESSION.query(WhitelistUsers).get(str(user_id))
        if not user:
            user = WhitelistUsers(str(user_id), str(username))
        else:
            user.username = str(username)

        SESSION.add(user)
        SESSION.commit()
示例#8
0
def get_fav(user_id):
    try:
        return (
            SESSION.query(
                Favourites,
            ).filter(
                Favourites.user_id == int(user_id),
            ).all()
        )
    finally:
        SESSION.close()
示例#9
0
def __load_mychats():
    global MY_ALL_CHATS
    try:
        qall = SESSION.query(MyChats).all()
        MY_ALL_CHATS = {
            x.chat_id: {
                'name': x.chat_name,
                'username': x.chat_username,
            }
            for x in qall
        }
    finally:
        SESSION.close()
示例#10
0
def backup_indentity(first_name, last_name, bio):
    cloner_db = SESSION.query(Cloner).get(str(Owner))
    if cloner_db:
        SESSION.delete(cloner_db)
    cloner_db = Cloner(Owner, first_name, last_name, bio)
    SESSION.add(cloner_db)
    SESSION.commit()
示例#11
0
def set_stanim_set(my_id, sticker):
    sticker_db = SESSION.query(StickerAnimationSet).get(my_id)
    if sticker_db:
        SESSION.delete(sticker_db)
    sticker_db = StickerAnimationSet(my_id, sticker)
    SESSION.add(sticker_db)
    SESSION.commit()
示例#12
0
def switch_to_locale(chat_id, locale_name):
    with LOCALES_INSERTION_LOCK:
        prev = SESSION.query(Locales).get(str(chat_id))
        if prev:
            SESSION.delete(prev)
        switch_locale = Locales(str(chat_id), locale_name)
        SESSION.add(switch_locale)
        SESSION.commit()
示例#13
0
def set_afk(afk, reason):
    global MY_AFK
    afk_db = SESSION.query(AFK).get(str(Owner))
    if afk_db:
        SESSION.delete(afk_db)
    afk_db = AFK(Owner, afk, reason)
    SESSION.add(afk_db)
    SESSION.commit()
    MY_AFK[Owner] = {'afk': afk, 'reason': reason}
示例#14
0
def __load_allnotes():
    global SELF_NOTES
    getall = SESSION.query(SelfNotes).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': x.file,
        }
示例#15
0
def del_whitelist(user_id):

    with INSERTION_LOCK:
        user = SESSION.query(WhitelistUsers).get(str(user_id))
        if user:
            SESSION.delete(user)
            SESSION.commit()
        else:
            SESSION.close()
            return False
示例#16
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}
示例#17
0
def rm_selfnote(user_id, note_name):
    global SELF_NOTES
    with INSERTION_LOCK:
        note = SESSION.query(SelfNotes).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
示例#18
0
def save_selfnote(user_id, note_name, note_data, msgtype, file=None):
    global SELF_NOTES
    with INSERTION_LOCK:
        prev = SESSION.query(SelfNotes).get((user_id, note_name))
        if prev:
            SESSION.delete(prev)
        note = SelfNotes(
            user_id,
            note_name,
            note_data,
            msgtype=int(msgtype),
            file=file,
        )
        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': file,
        }
示例#19
0
def get_sticker_set(my_id):
    try:
        return SESSION.query(StickerSet).get(my_id)
    finally:
        SESSION.close()
示例#20
0
def get_all_chats():
    try:
        return SESSION.query(MyChats).all()
    finally:
        SESSION.close()
示例#21
0
def get_stanim_set(my_id):
    try:
        return SESSION.query(StickerAnimationSet).get(my_id)
    finally:
        SESSION.close()
示例#22
0
def restore_identity():
    cloner_db = SESSION.query(Cloner).get(str(Owner))
    return cloner_db.first_name, cloner_db.last_name, cloner_db.bio
示例#23
0
def fav_count():
    try:
        return SESSION.query(Favourites).count()
    finally:
        SESSION.close()
示例#24
0
def prev_locale(chat_id):
    try:
        return SESSION.query(Locales).get(str(chat_id))
    finally:
        SESSION.close()
示例#25
0
def check_fav(user_id, data):
    try:
        return SESSION.query(Favourites).get((int(user_id), str(data)))
    finally:
        SESSION.close()