def already_added(chat_id): try: return SESSION.query(Moidata).filter(Moidata.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def is_approved(chat_id): try: return SESSION.query(PMPermit).filter(PMPermit.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def is_he_added(chat_id): try: return SESSION.query(Blockedid).filter(Blockedid.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def get_snips(keyword): try: return SESSION.query(Snips).get(keyword) except: return None finally: SESSION.close()
def get_current_welcome_settings(chat_id): try: return SESSION.query(Welcome).filter(Welcome.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def __load_feds_subscriber(): global FEDS_SUBSCRIBER global MYFEDS_SUBSCRIBER try: feds = SESSION.query(FedSubs.fed_id).distinct().all() for (fed_id, ) in feds: # remove tuple by ( ,) FEDS_SUBSCRIBER[fed_id] = [] MYFEDS_SUBSCRIBER[fed_id] = [] all_fedsubs = SESSION.query(FedSubs).all() for x in all_fedsubs: FEDS_SUBSCRIBER[x.fed_id] += [x.fed_subs] try: MYFEDS_SUBSCRIBER[x.fed_subs] += [x.fed_id] except KeyError: getsubs = SESSION.query(FedSubs).get((x.fed_id, x.fed_subs)) if getsubs: SESSION.delete(getsubs) SESSION.commit() FEDS_SUBSCRIBER = {x: set(y) for x, y in FEDS_SUBSCRIBER.items()} MYFEDS_SUBSCRIBER = {x: set(y) for x, y in MYFEDS_SUBSCRIBER.items()} finally: SESSION.close()
def get_all_snips(): try: return SESSION.query(Snips).all() except: return None finally: SESSION.close()
def his_userid(message_id: int): """ get the user_id from the message_id """ try: s__ = SESSION.query(Users).get(str(message_id)) return int(s__.chat_id), s__.um_id finally: SESSION.close()
def is_gmuted(sender_id): try: return SESSION.query(GMute).all() except: return None finally: SESSION.close()
def get_filter(chat_id, keyword): try: return SESSION.query(Filters).get((str(chat_id), keyword)) except: return None finally: SESSION.close()
def get_all_filters(chat_id): try: return SESSION.query(Filters).filter(Filters.chat_id == str(chat_id)).all() except: return None finally: SESSION.close()
def is_gbanned(chat_id): try: return SESSION.query(GBan).filter(GBan.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def get_all_echos(): try: return SESSION.query(ECHOSQL).all() except BaseException: return None finally: SESSION.close()
def is_echo(user_id, chat_id): try: return SESSION.query(ECHOSQL).get((str(user_id), str(chat_id))) except BaseException: return None finally: SESSION.close()
def __load_all_feds_settings(): global FEDERATION_NOTIFICATION try: getuser = SESSION.query(FedsUserSettings).all() for x in getuser: FEDERATION_NOTIFICATION[str(x.user_id)] = x.should_report finally: SESSION.close()
def gvarstatus(variable): try: return SESSION.query(Globals).filter( Globals.variable == str(variable)).first().value except BaseException: return None finally: SESSION.close()
def is_approved(chat_id): try: return SESSION.query(NOLogPMs).filter( NOLogPMs.chat_id == chat_id).one() except: return None finally: SESSION.close()
def fs_settings(chat_id): try: return (SESSION.query(forceSubscribe).filter( forceSubscribe.chat_id == chat_id).one()) except: return None finally: SESSION.close()
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 getcurrent_wafu_settings(chat_id): try: return ( SESSION.query(Joinwafu).filter(Joinwafu.chat_id == str(chat_id)).one() ) except BaseException: return None finally: SESSION.close()
def migrate_chat(old_chat_id, new_chat_id): with INSERTION_LOCK: flood = SESSION.query(FloodControl).get(str(old_chat_id)) if flood: CHAT_FLOOD[str(new_chat_id)] = CHAT_FLOOD.get( str(old_chat_id), DEF_OBJ) flood.chat_id = str(new_chat_id) SESSION.commit() SESSION.close()
def __load_flood_settings(): global CHAT_FLOOD try: all_chats = SESSION.query(FloodControl).all() CHAT_FLOOD = { chat.chat_id: (None, DEF_COUNT, chat.limit) for chat in all_chats } finally: SESSION.close() return CHAT_FLOOD
def unsubs_fed(fed_id, my_fed): with FEDS_SUBSCRIBER_LOCK: getsubs = SESSION.query(FedSubs).get((fed_id, my_fed)) if getsubs: if my_fed in FEDS_SUBSCRIBER.get(fed_id, set()): # sanity check FEDS_SUBSCRIBER.get(fed_id, set()).remove(my_fed) SESSION.delete(getsubs) SESSION.commit() return True SESSION.close() return False
def rem_sub(my_fed, fed_id): sox = SESSION.query(FedSubs).get((my_fed, fed_id)) if sox: if fed_id in MYFEDS_SUBSCRIBER.get(my_fed, set()): # sanity check MYFEDS_SUBSCRIBER.get(my_fed, set()).remove(fed_id) SESSION.delete(sox) SESSION.commit() return True SESSION.close() return False
def __load_chat_blacklists(): global CHAT_BLACKLISTS try: chats = SESSION.query(BlackListFilters.chat_id).distinct().all() for (chat_id, ) in chats: # remove tuple by ( ,) CHAT_BLACKLISTS[chat_id] = [] all_filters = SESSION.query(BlackListFilters).all() for x in all_filters: CHAT_BLACKLISTS[x.chat_id] += [x.trigger] CHAT_BLACKLISTS = {x: set(y) for x, y in CHAT_BLACKLISTS.items()} finally: SESSION.close()
def rm_from_blacklist(chat_id, trigger): with BLACKLIST_FILTER_INSERTION_LOCK: blacklist_filt = SESSION.query(BlackListFilters).get( (str(chat_id), trigger)) if blacklist_filt: if trigger in CHAT_BLACKLISTS.get(str(chat_id), set()): # sanity check CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger) SESSION.delete(blacklist_filt) SESSION.commit() return True SESSION.close() return False
def is_locked(chat_id, lock_type): curr_perm = SESSION.query(Locks).get(str(chat_id)) SESSION.close() if not curr_perm: return False elif lock_type == "bots": return curr_perm.bots elif lock_type == "commands": return curr_perm.commands elif lock_type == "email": return curr_perm.email elif lock_type == "forward": return curr_perm.forward elif lock_type == "url": return curr_perm.url
def __load_all_feds(): global FEDERATION_BYOWNER, FEDERATION_BYFEDID, FEDERATION_BYNAME try: feds = SESSION.query(Federations).all() for x in feds: # remove tuple by ( ,) # Fed by Owner check = FEDERATION_BYOWNER.get(x.owner_id) if check is None: FEDERATION_BYOWNER[x.owner_id] = [] FEDERATION_BYOWNER[str(x.owner_id)] = { "fid": str(x.fed_id), "fname": x.fed_name, "frules": x.fed_rules, "flog": x.fed_log, "fusers": str(x.fed_users), } # Fed By FedId check = FEDERATION_BYFEDID.get(x.fed_id) if check is None: FEDERATION_BYFEDID[x.fed_id] = [] FEDERATION_BYFEDID[str(x.fed_id)] = { "owner": str(x.owner_id), "fname": x.fed_name, "frules": x.fed_rules, "flog": x.fed_log, "fusers": str(x.fed_users), } # Fed By Name check = FEDERATION_BYNAME.get(x.fed_name) if check is None: FEDERATION_BYNAME[x.fed_name] = [] FEDERATION_BYNAME[x.fed_name] = { "fid": str(x.fed_id), "owner": str(x.owner_id), "frules": x.fed_rules, "flog": x.fed_log, "fusers": str(x.fed_users), } finally: SESSION.close()
def __load_all_feds_chats(): global FEDERATION_CHATS, FEDERATION_CHATS_BYID try: qall = SESSION.query(ChatF).all() FEDERATION_CHATS = {} FEDERATION_CHATS_BYID = {} for x in qall: # Federation Chats check = FEDERATION_CHATS.get(x.chat_id) if check is None: FEDERATION_CHATS[x.chat_id] = {} FEDERATION_CHATS[x.chat_id] = { "chat_name": x.chat_name, "fid": x.fed_id } # Federation Chats By ID check = FEDERATION_CHATS_BYID.get(x.fed_id) if check is None: FEDERATION_CHATS_BYID[x.fed_id] = [] FEDERATION_CHATS_BYID[x.fed_id].append(x.chat_id) finally: SESSION.close()
def __load_all_feds_banned(): global FEDERATION_BANNED_USERID, FEDERATION_BANNED_FULL try: FEDERATION_BANNED_USERID = {} FEDERATION_BANNED_FULL = {} qall = SESSION.query(BansF).all() for x in qall: check = FEDERATION_BANNED_USERID.get(x.fed_id) if check is None: FEDERATION_BANNED_USERID[x.fed_id] = [] if int(x.user_id) not in FEDERATION_BANNED_USERID[x.fed_id]: FEDERATION_BANNED_USERID[x.fed_id].append(int(x.user_id)) check = FEDERATION_BANNED_FULL.get(x.fed_id) if check is None: FEDERATION_BANNED_FULL[x.fed_id] = {} FEDERATION_BANNED_FULL[x.fed_id][x.user_id] = { "first_name": x.first_name, "last_name": x.last_name, "user_name": x.user_name, "reason": x.reason, "time": x.time, } finally: SESSION.close()