def get_chat_filters(chat_id): try: return (SESSION.query(CustomFilters).filter( CustomFilters.chat_id == str(chat_id)).order_by( func.length(CustomFilters.keyword).desc()).order_by( CustomFilters.keyword.asc()).all()) finally: SESSION.close()
def chat_antiarabic(chat_id: Union[str, int]) -> bool: try: chat_setting = SESSION.query(AntiArabicChatSettings).get(str(chat_id)) if chat_setting: return chat_setting.antiarabic return False finally: SESSION.close()
def is_chat(chat_id): try: chat = SESSION.query(aiChats).get(str(chat_id)) if chat: return True return False finally: SESSION.close()
def get_clean_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.clean_welcome return False
def get_user(user_id): user = SESSION.query(LastFMUsers).get(str(user_id)) rep = "" if user: rep = str(user.username) SESSION.close() return rep
def allow_connect_to_chat(chat_id: Union[str, int]) -> bool: try: chat_setting = SESSION.query(ChatAccessConnectionSettings).get(str(chat_id)) if chat_setting: return chat_setting.allow_connect_to_chat return False finally: SESSION.close()
def get_custom_welcome(chat_id): welcome_settings = SESSION.query(Welcome).get(str(chat_id)) ret = DEFAULT_WELCOME if welcome_settings and welcome_settings.custom_welcome: ret = welcome_settings.custom_welcome SESSION.close() return ret
def get_custom_gdbye(chat_id): welcome_settings = SESSION.query(Welcome).get(str(chat_id)) ret = DEFAULT_GOODBYE if welcome_settings and welcome_settings.custom_leave: ret = welcome_settings.custom_leave SESSION.close() return ret
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 user_should_report(user_id: int) -> bool: try: user_setting = SESSION.query(ReportingUserSettings).get(user_id) if user_setting: return user_setting.should_report return True finally: SESSION.close()
def welcome_mutes(chat_id): try: welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id)) if welcomemutes: return welcomemutes.welcomemutes return False finally: SESSION.close()
def clean_service(chat_id: Union[str, int]) -> bool: try: chat_setting = SESSION.query(CleanServiceSetting).get(str(chat_id)) if chat_setting: return chat_setting.clean_service return False 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 get_welc_mutes_pref(chat_id): welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id)) SESSION.close() if welcomemutes: return welcomemutes.welcomemutes return False
def chat_should_report(chat_id: Union[str, int]) -> bool: try: chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id)) if chat_setting: return chat_setting.should_report return False finally: SESSION.close()
def get_gdbye_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.should_goodbye, welc.custom_leave, welc.leave_type else: # Welcome by default. return True, DEFAULT_GOODBYE, Types.TEXT
def get_reason(user_id): user = SESSION.query(BlacklistUsers).get(str(user_id)) rep = "" if user: rep = user.reason SESSION.close() return rep
def get_rules(chat_id): rules = SESSION.query(Rules).get(str(chat_id)) ret = "" if rules: ret = rules.rules SESSION.close() return ret
def rem_chat(chat_id): with INSERTION_LOCK: chat = SESSION.query(Chats).get(str(chat_id)) if chat: SESSION.delete(chat) SESSION.commit() else: SESSION.close()
def get_flood_setting(chat_id): try: setting = SESSION.query(FloodSettings).get(str(chat_id)) if setting: return setting.flood_type, setting.value return 1, "0" finally: SESSION.close()
def get_blacklist_setting(chat_id): try: setting = CHAT_SETTINGS_BLACKLISTS.get(str(chat_id)) if setting: return setting["blacklist_type"], setting["value"] return 1, "0" finally: SESSION.close()
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()
def __load_gban_stat_list(): global GBANSTAT_LIST try: GBANSTAT_LIST = { x.chat_id for x in SESSION.query(GbanSettings).all() if not x.setting } finally: SESSION.close()
def __load_gbanned_userid_list(): global GBANNED_LIST try: GBANNED_LIST = { x.user_id for x in SESSION.query(GloballyBannedUsers).all() } finally: SESSION.close()
def disconnect(user_id): with CONNECTION_INSERTION_LOCK: disconnect = SESSION.query(Connection).get((int(user_id))) if disconnect: SESSION.delete(disconnect) SESSION.commit() return True SESSION.close() return False
def is_enabled(chat_id): try: resultcurr = SESSION.query(CleanerBlueTextChatSettings).get( str(chat_id)) if resultcurr: return resultcurr.is_enable return False # default finally: SESSION.close()
def get_welc_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.should_welcome, welc.custom_welcome, welc.custom_content, welc.welcome_type else: # Welcome by default. return True, DEFAULT_WELCOME, None, Types.TEXT
def get_note(chat_id, note_name): try: return ( SESSION.query(Notes) .filter(func.lower(Notes.name) == note_name, Notes.chat_id == str(chat_id)) .first() ) finally: SESSION.close()
def get_human_checks(user_id, chat_id): try: human_check = SESSION.query(WelcomeMuteUsers).get((user_id, str(chat_id))) if not human_check: return None human_check = human_check.human_check return human_check finally: SESSION.close()
def disapprove(chat_id, user_id): with APPROVE_INSERTION_LOCK: disapprove_user = SESSION.query(Approvals).get((str(chat_id), user_id)) if disapprove_user: SESSION.delete(disapprove_user) SESSION.commit() return True SESSION.close() return False