Beispiel #1
0
def multi_fban_user(multi_fed_id, multi_user_id, multi_first_name,
                    multi_last_name, multi_user_name, multi_reason):
    if True:  # with FEDS_LOCK:
        counter = 0
        time = 0
        for x in range(len(multi_fed_id)):
            fed_id = multi_fed_id[x]
            user_id = multi_user_id[x]
            first_name = multi_first_name[x]
            last_name = multi_last_name[x]
            user_name = multi_user_name[x]
            reason = multi_reason[x]
            r = SESSION.query(BansF).all()
            for I in r:
                if I.fed_id == fed_id:
                    if 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)
            counter += 1
            if str(str(counter)[-2:]) == "00":
                print(user_id)
                print(first_name)
                print(reason)
                print(counter)
        try:
            SESSION.commit()
        except:
            SESSION.rollback()
            return False
        finally:
            SESSION.commit()
        __load_all_feds_banned()
        print("Done")
        return counter
Beispiel #2
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())
    finally:
        SESSION.close()
Beispiel #3
0
def get_urls(tg_chat_id):
    try:
        return SESSION.query(RSS).filter(RSS.chat_id == tg_chat_id).all()
    finally:
        SESSION.close()
def add_history_conn(user_id, chat_id, chat_name):
    global HISTORY_CONNECT
    with CONNECTION_HISTORY_LOCK:
        conn_time = int(time.time())
        if HISTORY_CONNECT.get(int(user_id)):
            counting = (SESSION.query(ConnectionHistory.user_id).filter(
                ConnectionHistory.user_id == str(user_id)).count())
            getchat_id = {}
            for x in HISTORY_CONNECT[int(user_id)]:
                getchat_id[HISTORY_CONNECT[int(user_id)][x]["chat_id"]] = x
            if chat_id in getchat_id:
                todeltime = getchat_id[str(chat_id)]
                delold = SESSION.query(ConnectionHistory).get(
                    (int(user_id), str(chat_id)), )
                if delold:
                    SESSION.delete(delold)
                    HISTORY_CONNECT[int(user_id)].pop(todeltime)
            elif counting >= 5:
                todel = list(HISTORY_CONNECT[int(user_id)])
                todel.reverse()
                todel = todel[4:]
                for x in todel:
                    chat_old = HISTORY_CONNECT[int(user_id)][x]["chat_id"]
                    delold = SESSION.query(ConnectionHistory).get(
                        (int(user_id), str(chat_old)), )
                    if delold:
                        SESSION.delete(delold)
                        HISTORY_CONNECT[int(user_id)].pop(x)
        else:
            HISTORY_CONNECT[int(user_id)] = {}
        delold = SESSION.query(ConnectionHistory).get(
            (int(user_id), str(chat_id)))
        if delold:
            SESSION.delete(delold)
        history = ConnectionHistory(int(user_id), str(chat_id), chat_name,
                                    conn_time)
        SESSION.add(history)
        SESSION.commit()
        HISTORY_CONNECT[int(user_id)][conn_time] = {
            "chat_name": chat_name,
            "chat_id": str(chat_id),
        }
Beispiel #5
0
def get_gbanned_user(user_id):
    try:
        return SESSION.query(GloballyBannedUsers).get(user_id)
    finally:
        SESSION.close()
Beispiel #6
0
def num_stickers_filter_chats():
    try:
        return SESSION.query(func.count(distinct(
            StickersFilters.chat_id))).scalar()
    finally:
        SESSION.close()
Beispiel #7
0
def num_stickers_chat_filters(chat_id):
    try:
        return SESSION.query(StickersFilters.chat_id).filter(
            StickersFilters.chat_id == str(chat_id)).count()
    finally:
        SESSION.close()
Beispiel #8
0
def get_user_num_chats(user_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.user == int(user_id)).count()
    finally:
        SESSION.close()
Beispiel #9
0
def num_chats():
    try:
        return SESSION.query(Chats).count()
    finally:
        SESSION.close()
Beispiel #10
0
def get_all_chats():
    try:
        return SESSION.query(Chats).all()
    finally:
        SESSION.close()
Beispiel #11
0
def get_all_users():
    try:
        return SESSION.query(Users).all()
    finally:
        SESSION.close()
Beispiel #12
0
def get_chat_members(chat_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.chat == str(chat_id)).all()
    finally:
        SESSION.close()
Beispiel #13
0
def get_name_by_userid(user_id):
    try:
        return SESSION.query(Users).get(Users.user_id == int(user_id)).first()
    finally:
        SESSION.close()
Beispiel #14
0
def get_userid_by_name(username):
    try:
        return SESSION.query(Users).filter(
            func.lower(Users.username) == username.lower()).all()
    finally:
        SESSION.close()
Beispiel #15
0
def rmnightmode(chat_id: str):
    rmnightmoddy = SESSION.query(Nightmode).get(str(chat_id))
    if rmnightmoddy:
        SESSION.delete(rmnightmoddy)
        SESSION.commit()
Beispiel #16
0
def num_users():
    try:
        return SESSION.query(Users).count()
    finally:
        SESSION.close()
Beispiel #17
0
def get_all_chat_id():
    stark = SESSION.query(Nightmode).all()
    SESSION.close()
    return stark
Beispiel #18
0
def ensure_bot_in_db():
    with INSERTION_LOCK:
        bot = Users(dispatcher.bot.id, dispatcher.bot.username)
        SESSION.merge(bot)
        SESSION.commit()
Beispiel #19
0
def num_stickers_filters():
    try:
        return SESSION.query(StickersFilters).count()
    finally:
        SESSION.close()
Beispiel #20
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

        member = SESSION.query(ChatMembers).filter(
            ChatMembers.chat == chat.chat_id,
            ChatMembers.user == user.user_id).first()
        if not member:
            chat_member = ChatMembers(chat.chat_id, user.user_id)
            SESSION.add(chat_member)

        SESSION.commit()
def curr_connection(chat_id):
    try:
        return SESSION.query(Connection).get((str(chat_id)))
    finally:
        SESSION.close()
Beispiel #22
0
def num_chats():
    try:
        return SESSION.query(func.count(distinct(Rules.chat_id))).scalar()
    finally:
        SESSION.close()
def get_connected_chat(user_id):
    try:
        return SESSION.query(Connection).get((int(user_id)))
    finally:
        SESSION.close()
Beispiel #24
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        chat = SESSION.query(Rules).get(str(old_chat_id))
        if chat:
            chat.chat_id = str(new_chat_id)
        SESSION.commit()
Beispiel #25
0
def get_gban_list():
    try:
        return [x.to_dict() for x in SESSION.query(GloballyBannedUsers).all()]
    finally:
        SESSION.close()
Beispiel #26
0
def num_logchannels():
    try:
        return SESSION.query(func.count(distinct(GroupLogs.chat_id))).scalar()
    finally:
        SESSION.close()
Beispiel #27
0
def add_url(tg_chat_id, tg_feed_link, tg_old_entry_link):
    with INSERTION_LOCK:
        action = RSS(tg_chat_id, tg_feed_link, tg_old_entry_link)

        SESSION.add(action)
        SESSION.commit()
Beispiel #28
0
def add_nightmode(chat_id: str):
    nightmoddy = Nightmode(str(chat_id))
    SESSION.add(nightmoddy)
    SESSION.commit()
Beispiel #29
0
def get_all():
    try:
        return SESSION.query(RSS).all()
    finally:
        SESSION.close()
Beispiel #30
0
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:
                if 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