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() CHAT_BLACKLISTS.setdefault(str(chat_id), set()).add(trigger)
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
def add_sub(my_fed, fed_id): #LEGENDX22 IS BEST mime = FedSubs(my_fed, fed_id) SESSION.merge(mime) # merge to avoid duplicate key issues SESSION.commit() global MYFEDS_SUBSCRIBER if MYFEDS_SUBSCRIBER.get(my_fed, set()) == set(): MYFEDS_SUBSCRIBER[my_fed] = {fed_id} else: MYFEDS_SUBSCRIBER.get(my_fed, set()).add(fed_id) return True
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
def f_fed(fed_id, owner_id): with FEDS_LOCK: global FEDERATION_BYFEDID, FEDERATION_BYOWNER, FEDERATION_BYNAME fed = SESSION.query(Federations).get(fed_id) if not fed: return False fed.owner_id = owner_id SESSION.merge(fed.owner_id) # Update the dicts oldname = FEDERATION_BYFEDID[str(fed_id)]["owner"] tempdata = FEDERATION_BYOWNER[oldname] FEDERATION_BYOWNER.pop(oldname) FEDERATION_BYFEDID[str(fed_id)]["owner"] = owner_id FEDERATION_BYOWNER[newname] = tempdata return True
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 = 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, fed_log, str({ "owner": str(owner_id), "members": str(members) }), ) SESSION.merge(fed) SESSION.commit() __load_all_feds_chats() return True
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) fed_log = getfed["flog"] # 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, fed_log, str(fed_members)) SESSION.merge(fed) SESSION.commit() return True