Ejemplo n.º 1
0
def update_gmute_reason(user_id, name, reason=None):
    with GMUTED_USERS_LOCK:
        user = SESSION.query(GloballyMutedUsers).get(user_id)
        if not user:
            return None
        old_reason = user.reason
        user.name = name
        user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        return old_reason
Ejemplo n.º 2
0
def gban_user(user_id, name, reason=None):
    with GBANNED_USERS_LOCK:
        user = SESSION.query(GloballyBannedUsers).get(user_id)
        if not user:
            user = GloballyBannedUsers(user_id, name, reason)
        else:
            user.name = name
            user.reason = reason

        SESSION.merge(user)
        SESSION.commit()
        __load_gbanned_userid_list()
Ejemplo n.º 3
0
def add_warn_filter(chat_id, keyword, reply):
    with WARN_FILTER_INSERTION_LOCK:
        warn_filt = WarnFilters(str(chat_id), keyword, reply)

        if keyword not in WARN_FILTERS.get(str(chat_id), []):
            WARN_FILTERS[str(chat_id)] = sorted(
                WARN_FILTERS.get(str(chat_id), []) + [keyword],
                key=lambda x: (-len(x), x),
            )

        SESSION.merge(warn_filt)  # merge to avoid duplicate key issues
        SESSION.commit()
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']
        fed_log = getfed['flog']
        # 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, fed_log,
            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
Ejemplo n.º 5
0
def add_birthday(user_id, name, month, day):
	with BIRTHDAY_LOCK:
		user = SESSION.query(Birthdays).get(user_id)
		if not user:
			user = Birthdays(user_id, name, month, day)
		else:
			user.name = name
			user.month = month
			user.day = day

		SESSION.merge(user)
		SESSION.commit()
		__load_birthday_userid_list()
Ejemplo n.º 6
0
def subs_fed(fed_id, my_fed):
    check = get_spec_subs(fed_id, my_fed)
    if check:
        return False
    with FEDS_SUBSCRIBER_LOCK:
        subsfed = FedSubs(fed_id, my_fed)

        SESSION.merge(subsfed)  # merge to avoid duplicate key issues
        SESSION.commit()
        global FEDS_SUBSCRIBER
        if FEDS_SUBSCRIBER.get(fed_id, set()) == set():
            FEDS_SUBSCRIBER[fed_id] = {my_fed}
        else:
            FEDS_SUBSCRIBER.get(fed_id, set()).add(my_fed)
        return True
Ejemplo n.º 7
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"]
        fed_log = getfed["flog"]
        # 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,
            fed_log,
            str({
                "owner": str(owner_id),
                "members": str(members)
            }),
        )
        SESSION.merge(fed)
        SESSION.commit()
        return True
Ejemplo n.º 8
0
def set_frules(fed_id, rules):
	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_members = getfed['fusers']
		fed_rules = str(rules)
		# Set user
		FEDERATION_BYOWNER[str(owner_id)]['frules'] = fed_rules
		FEDERATION_BYFEDID[str(fed_id)]['frules'] = fed_rules
		FEDERATION_BYNAME[fed_name]['frules'] = fed_rules
		# Set on database
		fed = Federations(str(owner_id), fed_name, str(fed_id), fed_rules, str(fed_members))
		SESSION.merge(fed)
		SESSION.commit()
		return True
Ejemplo n.º 9
0
def user_join_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"]
        fed_log = getfed["flog"]
        # Temp set
        members = ast.literal_eval(
            ast.literal_eval(getfed["fusers"])["members"])
        members.append(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,
            fed_log,
            str({
                "owner": str(owner_id),
                "members": str(members)
            }),
        )
        SESSION.merge(fed)
        SESSION.commit()
        __load_all_feds_chats()
        return True
Ejemplo n.º 10
0
def user_join_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
		members = eval(eval(getfed['fusers'])['members'])
		members.append(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()
		__load_all_feds_chats()
		return True
Ejemplo n.º 11
0
def set_fed_log(fed_id, chat_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_members = getfed["fusers"]
        fed_rules = getfed["frules"]
        fed_log = str(chat_id)
        # Set user
        FEDERATION_BYOWNER[str(owner_id)]["flog"] = fed_log
        FEDERATION_BYFEDID[str(fed_id)]["flog"] = fed_log
        FEDERATION_BYNAME[fed_name]["flog"] = fed_log
        # Set on database
        fed = Federations(str(owner_id), fed_name, str(fed_id), fed_rules,
                          fed_log, str(fed_members))
        SESSION.merge(fed)
        SESSION.commit()
        print(fed_log)
        return True
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def approve(chat_id, user_id):
    with INSERTION_LOCK:
        approval = Approval(str(chat_id), str(user_id))
        APPROVALS[str(chat_id)] = APPROVALS[str(chat_id)].append(str(user_id))
        SESSION.merge(approval)
        SESSION.commit()
Ejemplo n.º 14
0
		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
Ejemplo n.º 15
0
def ensure_bot_in_db():
    with INSERTION_LOCK:
        bot = Users(dispatcher.bot.id, dispatcher.bot.username)
        SESSION.merge(bot)
        SESSION.commit()
Ejemplo n.º 16
0
def add_to_blacklist(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = BlackListFilters(str(chat_id), trigger)

        SESSION.merge(blacklist_filt)  # merge to avoid duplicate key issues
        SESSION.commit()
Ejemplo n.º 17
0
def add_warn_filter(chat_id, keyword, reply):
    with WARN_FILTER_INSERTION_LOCK:
        warn_filt = WarnFilters(str(chat_id), keyword, reply)

        SESSION.merge(warn_filt)  # merge to avoid duplicate key issues
        SESSION.commit()