def fban_user(fed_id, user_id, first_name, last_name, user_name, reason, time):
    with FEDS_LOCK:
        r = SESSION.query(BansF).all()
        for I in r:
            if I.fed_id == fed_id and int(I.user_id) == int(user_id):
                SESSION.delete(I)

        r = BansF(
            str(fed_id),
            str(user_id),
            first_name,
            last_name,
            user_name,
            reason,
            time,
        )

        SESSION.add(r)
        try:
            SESSION.commit()
        except:
            SESSION.rollback()
            return False
        finally:
            SESSION.commit()
        __load_all_feds_banned()
        return r
Example #2
0
def get_note(chat_id, note_name):
    try:
        return SESSION.query(Notes).get((str(chat_id), note_name))
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #3
0
def num_blacklist_filters():
    try:
        return SESSION.query(BlackListFilters).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #4
0
def num_chats():
    try:
        return SESSION.query(func.count(distinct(Rules.chat_id))).scalar()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #5
0
def num_chats():
    try:
        return SESSION.query(Chats).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #6
0
def get_all_filters():
    try:
        return SESSION.query(CustomFilters).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #7
0
def num_users():
    try:
        return SESSION.query(Users).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #8
0
def get_filter(chat_id, keyword):
    try:
        return SESSION.query(CustomFilters).get((str(chat_id), keyword))
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #9
0
def num_filters():
    try:
        return SESSION.query(CustomFilters).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #10
0
def get_restr(chat_id):
    try:
        return SESSION.query(Restrictions).get(str(chat_id))
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #11
0
def get_locks(chat_id):
    try:
        return SESSION.query(Permissions).get(str(chat_id))
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #12
0
def num_disabled():
    try:
        return SESSION.query(Disable).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #13
0
def get_all_chats():
    try:
        return SESSION.query(Chats).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #14
0
def num_logchannels():
    try:
        return SESSION.query(func.count(distinct(GroupLogs.chat_id))).scalar()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #15
0
def num_notes():
    try:
        return SESSION.query(Notes).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #16
0
def get_gban_list():
    try:
        return [x.to_dict() for x in SESSION.query(GloballyBannedUsers).all()]
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #17
0
def get_name_by_userid(user_id):
    try:
        return SESSION.query(Users).get(Users.user_id == int(user_id)).first()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #18
0
def get_gbanned_user(user_id):
    try:
        return SESSION.query(GloballyBannedUsers).get(user_id)
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #19
0
def get_urls(tg_chat_id):
    try:
        return SESSION.query(RSS).filter(RSS.chat_id == tg_chat_id).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #20
0
def get_chat_members(chat_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.chat == str(chat_id)).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #21
0
def get_userid_by_name(username):
    try:
        return SESSION.query(Users).filter(
            func.lower(Users.username) == username.lower()).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #22
0
def __load_gban_stat_list():
    global GBANSTAT_LIST
    try:
        GBANSTAT_LIST = {x.chat_id for x in SESSION.query(GbanSettings).all() if not x.setting}
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #23
0
def __load_gbanned_userid_list():
    global GBANNED_LIST
    try:
        GBANNED_LIST = {x.user_id for x in SESSION.query(GloballyBannedUsers).all()}
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #24
0
def check_url_availability(tg_chat_id, tg_feed_link):
    try:
        return SESSION.query(RSS).filter(RSS.feed_link == tg_feed_link,
                                         RSS.chat_id == tg_chat_id).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #25
0
def num_blacklist_filter_chats():
    try:
        return SESSION.query(func.count(distinct(
            BlackListFilters.chat_id))).scalar()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #26
0
def get_user_num_chats(user_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.user == int(user_id)).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #27
0
def num_blacklist_chat_filters(chat_id):
    try:
        return SESSION.query(BlackListFilters.chat_id).filter(
            BlackListFilters.chat_id == str(chat_id)).count()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #28
0
def get_all_chat_notes(chat_id):
    try:
        return SESSION.query(Notes).filter(
            Notes.chat_id == str(chat_id)).order_by(Notes.name.asc()).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #29
0
def __load_log_channels():
    global CHANNELS
    try:
        all_chats = SESSION.query(GroupLogs).all()
        CHANNELS = {chat.chat_id: chat.log_channel for chat in all_chats}
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()
Example #30
0
def get_gdbye_buttons(chat_id):
    try:
        return SESSION.query(GoodbyeButtons).filter(
            GoodbyeButtons.chat_id == str(chat_id)).order_by(
                GoodbyeButtons.id).all()
    except:
        SESSION.rollback()
        raise
    finally:
        SESSION.close()