Exemple #1
0
def user_join_fed(fed_id, user_id):
    with FEDS_LOCK:
        r = UserF(user_id, fed_id)
        SESSION.add(r)
        SESSION.commit()
        return r
def get_gdbye_buttons(chat_id):
    try:
        return SESSION.query(GoodbyeButtons).filter(GoodbyeButtons.chat_id == str(chat_id)).order_by(
            GoodbyeButtons.id).all()
    finally:
        SESSION.close()
Exemple #3
0
def curr_connection(chat_id):
    try:
        return SESSION.query(Connection).get((str(chat_id)))
    finally:
        SESSION.close()
Exemple #4
0
def get_gbanned_user(user_id):
    try:
        return SESSION.query(GloballyBannedUsers).get(user_id)
    finally:
        SESSION.close()
Exemple #5
0
def get_restr(chat_id):
    try:
        return SESSION.query(Restrictions).get(str(chat_id))
    finally:
        SESSION.close()
Exemple #6
0
def get_all():
    try:
        return SESSION.query(RSS).all()
    finally:
        SESSION.close()
Exemple #7
0
def fban_user(fed_id, user_id, first_name, last_name, user_name, reason):
    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)

        SESSION.add(r)
        try:
            SESSION.commit()
        except Exception:
            SESSION.rollback()
            return False
        finally:
            SESSION.commit()
        __load_all_feds_banned()
        return r
def get_filter(chat_id, keyword):
    try:
        return SESSION.query(CustomFilters).get((str(chat_id), keyword))
    finally:
        SESSION.close()
def add_note_button_to_db(chat_id, keyword, b_name, url, same_line):
    with BUTTON_LOCK:
        button = Buttons(chat_id, keyword, b_name, url, same_line)
        SESSION.add(button)
        SESSION.commit()
Exemple #10
0
def del_fed(fed_id, chat_id):
    with FEDS_LOCK:
        curr = SESSION.query(Federations).get(fed_id)
        print(curr)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()

        curr = SESSION.query(ChatF).get(str(chat_id))
        if curr:
            SESSION.delete(curr)
            SESSION.commit()

        curr = SESSION.query(UserF).all()
        for I in curr:
            if I.fed_id == fed_id:
                SESSION.delete(I)
                SESSION.commit()

        curr = SESSION.query(RulesF).get(fed_id)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()

        return
Exemple #11
0
def user_demote_fed(fed_id, user_id):
	with FEDS_LOCK:
		global FEDERATION_BYOWNER, FEDERATION_BYFEDID, FEDERATION_BYNAME
		# Variables
		getfed = FEDERATION_BYFEDID.get(str(fed_id))
		owner_id = getfed['owner']
		fed_name = getfed['fname']
		fed_rules = getfed['frules']
		# Temp set
		try:
			members = eval(eval(getfed['fusers'])['members'])
		except ValueError:
			return False
		members.remove(user_id)
		# Set user
		FEDERATION_BYOWNER[str(owner_id)]['fusers'] = str({'owner': str(owner_id), 'members': str(members)})
		FEDERATION_BYFEDID[str(fed_id)]['fusers'] = str({'owner': str(owner_id), 'members': str(members)})
		FEDERATION_BYNAME[fed_name]['fusers'] = str({'owner': str(owner_id), 'members': str(members)})
		# Set on database
		fed = Federations(str(owner_id), fed_name, str(fed_id), fed_rules, str({'owner': str(owner_id), 'members': str(members)}))
		SESSION.merge(fed)
		SESSION.commit()
		return True

		curr = SESSION.query(UserF).all()
		result = False
		for r in curr:
			if int(r.user_id) == int(user_id):
				if r.fed_id == fed_id:
					SESSION.delete(r)
					SESSION.commit()
					result = True

		SESSION.close()
		return result
Exemple #12
0
def new_fed(owner_id, fed_id, fed_name):
    with FEDS_LOCK:
        r = Federations(str(owner_id), fed_id, fed_name)
        SESSION.add(r)
        SESSION.commit()
        return r
Exemple #13
0
def get_fed_info(fed_id):
    q = SESSION.query(Federations).get(str(fed_id))
    SESSION.close()
    return q
Exemple #14
0
def get_frules(fed_id):
    with FEDS_LOCK:
        r = SESSION.query(RulesF).get(str(fed_id))

        SESSION.close()
        return r
Exemple #15
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()
def num_filters():
    try:
        return SESSION.query(CustomFilters).count()
    finally:
        SESSION.close()
Exemple #17
0
def get_urls(tg_chat_id):
    try:
        return SESSION.query(RSS).filter(RSS.chat_id == tg_chat_id).all()
    finally:
        SESSION.close()
def num_chats():
    try:
        return SESSION.query(func.count(distinct(
            CustomFilters.chat_id))).scalar()
    finally:
        SESSION.close()
Exemple #19
0
def del_fed(fed_id):
    with FEDS_LOCK:
        global FEDERATION_BYOWNER, FEDERATION_BYFEDID, FEDERATION_BYNAME, FEDERATION_CHATS, FEDERATION_CHATS_BYID, FEDERATION_BANNED_USERID, FEDERATION_BANNED_FULL
        getcache = FEDERATION_BYFEDID.get(fed_id)
        if getcache == None:
            return False
        # Variables
        getfed = FEDERATION_BYFEDID.get(fed_id)
        owner_id = getfed['owner']
        fed_name = getfed['fname']
        # Delete from cache
        FEDERATION_BYOWNER.pop(owner_id)
        FEDERATION_BYFEDID.pop(fed_id)
        FEDERATION_BYNAME.pop(fed_name)
        if FEDERATION_CHATS_BYID.get(fed_id):
            for x in FEDERATION_CHATS_BYID[fed_id]:
                delchats = SESSION.query(ChatF).get(str(x))
                if delchats:
                    SESSION.delete(delchats)
                    SESSION.commit()
                FEDERATION_CHATS.pop(x)
            FEDERATION_CHATS_BYID.pop(fed_id)
        # Delete fedban users
        getall = FEDERATION_BANNED_USERID.get(fed_id)
        if getall:
            for x in getall:
                banlist = SESSION.query(BansF).get((fed_id, str(x)))
                if banlist:
                    SESSION.delete(banlist)
                    SESSION.commit()
        FEDERATION_BANNED_USERID.pop(fed_id)
        FEDERATION_BANNED_FULL.pop(fed_id)
        # Delete from database
        curr = SESSION.query(Federations).get(fed_id)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()
        return True
def get_all_filters():
    try:
        return SESSION.query(CustomFilters).all()
    finally:
        SESSION.close()
Exemple #21
0
def get_gban_list():
    try:
        return [x.to_dict() for x in SESSION.query(GloballyBannedUsers).all()]
    finally:
        SESSION.close()
Exemple #22
0
def get_user_me_info(user_id):
    userinfo = SESSION.query(UserInfo).get(user_id)
    SESSION.close()
    if userinfo:
        return userinfo.info
    return None
Exemple #23
0
def get_locks(chat_id):
    try:
        return SESSION.query(Permissions).get(str(chat_id))
    finally:
        SESSION.close()
Exemple #24
0
def get_user_bio(user_id):
    userbio = SESSION.query(UserBio).get(user_id)
    SESSION.close()
    if userbio:
        return userbio.bio
    return None
def get_welc_buttons(chat_id):
    try:
        return SESSION.query(WelcomeButtons).filter(WelcomeButtons.chat_id == str(chat_id)).order_by(
            WelcomeButtons.id).all()
    finally:
        SESSION.close()
Exemple #26
0
def check_afk_status(user_id):
    try:
        return SESSION.query(AFK).get(user_id)
    finally:
        SESSION.close()
Exemple #27
0
def get_connected_chat(user_id):
    try:
        return SESSION.query(Connection).get((int(user_id)))
    finally:
        SESSION.close()
Exemple #28
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()
Exemple #29
0
def get_history(user_id):
    try:
        return SESSION.query(ConnectionHistory).get(str(user_id))
    finally:
        SESSION.close()
Exemple #30
0
def chat_join_fed(fed_id, chat_id):
    with FEDS_LOCK:
        r = ChatF(chat_id, fed_id)
        SESSION.add(r)
        SESSION.commit()
        return r