def is_nightmode_indb(chat_id: str): try: s__ = SESSION.query(Nightmode).get(str(chat_id)) if s__: return str(s__.chat_id) finally: SESSION.close()
def get_notes(chat_id, keyword): try: return SESSION.query(NOTES).get((str(chat_id), keyword)) except BaseException: return None finally: SESSION.close()
def add_filter( chat_id, keyword, reply, snip_type, media_id, media_access_hash, media_file_reference, ): adder = SESSION.query(Filters).get((str(chat_id), keyword)) if adder: adder.reply = reply adder.snip_type = snip_type adder.media_id = media_id adder.media_access_hash = media_access_hash adder.media_file_reference = media_file_reference else: adder = Filters( chat_id, keyword, reply, snip_type, media_id, media_access_hash, media_file_reference, ) SESSION.add(adder) SESSION.commit()
def blacklist_url(chat_id, domain): with URL_BLACKLIST_FILTER_INSERTION_LOCK: domain_filt = URLBlackListFilters(str(chat_id), domain) SESSION.merge(domain_filt) SESSION.commit() CHAT_URL_BLACKLISTS.setdefault(str(chat_id), set()).add(domain)
def rem_chat(chat_id): with INSERTION_LOCK: autochat = SESSION.query(ChatbotChats).get(str(chat_id)) if autochat: SESSION.delete(autochat) SESSION.commit()
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 get_filter(chat_id, keyword): try: return SESSION.query(Filters).get((str(chat_id), keyword)) except BaseException: return None finally: SESSION.close()
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 get_current_goodbye_settings(chat_id): try: return SESSION.query(Goodbye).filter(Goodbye.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def get_all_notes(chat_id): try: return SESSION.query(NOTES).filter(NOTES.chat_id == str(chat_id)).all() except BaseException: return None finally: SESSION.close()
def is_nsfwatch_indb(chat_id: str): try: s__ = SESSION.query(Nsfwatch).get(str(chat_id)) if s__: return str(s__.chat_id) finally: SESSION.close()
def get_all_filters(chat_id): try: return SESSION.query(Filters).filter( Filters.chat_id == str(chat_id)).all() 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 get_warn_strength(chat_id): try: setting = SESSION.query(WarnSettings).get(str(chat_id)) if setting: return setting.soft_warn return "ban" finally: SESSION.close()
def is_chat(chat_id): try: chat = SESSION.query(ChatbotChats).get(str(chat_id)) if chat: return True return False 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 get_rules(chat_id): rules = SESSION.query(Rules).get(str(chat_id)) ret = "" if rules: ret = rules.rules SESSION.close() return ret
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 set_rules(chat_id, rules_text): with INSERTION_LOCK: rules = SESSION.query(Rules).get(str(chat_id)) if not rules: rules = Rules(str(chat_id)) rules.rules = rules_text SESSION.add(rules) SESSION.commit()
def set_user_setting(user_id: int, setting: bool): with USER_LOCK: user_setting = SESSION.query(ReportingUserSettings).get(user_id) if not user_setting: user_setting = ReportingUserSettings(user_id) user_setting.should_report = setting SESSION.add(user_setting) SESSION.commit()
def set_chat_setting(chat_id: Union[int, str], setting: bool): with CHAT_LOCK: chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id)) if not chat_setting: chat_setting = ReportingChatSettings(chat_id) chat_setting.should_report = setting SESSION.add(chat_setting) SESSION.commit()
def get_warn_setting(chat_id): try: setting = SESSION.query(WarnSettings).get(str(chat_id)) if setting: return setting.warn_limit, setting.soft_warn return 3, "ban" finally: SESSION.close()
def set_warn_limit(chat_id, warn_limit): with WARN_SETTINGS_LOCK: curr_setting = SESSION.query(WarnSettings).get(str(chat_id)) if not curr_setting: curr_setting = WarnSettings(chat_id, warn_limit=warn_limit) curr_setting.warn_limit = warn_limit SESSION.add(curr_setting) SESSION.commit()
def set_warn_strength(chat_id, soft_warn): with WARN_SETTINGS_LOCK: curr_setting = SESSION.query(WarnSettings).get(str(chat_id)) if not curr_setting: curr_setting = WarnSettings(chat_id, soft_warn=soft_warn) curr_setting.soft_warn = soft_warn SESSION.add(curr_setting) SESSION.commit()
def migrate_chat(old_chat_id, new_chat_id): with CHAT_LOCK: chat_notes = ( SESSION.query(ReportingChatSettings) .filter(ReportingChatSettings.chat_id == str(old_chat_id)) .all() ) for note in chat_notes: note.chat_id = str(new_chat_id) SESSION.commit()
def get_ses(chat_id): autochat = SESSION.query(ChatbotChats).get(str(chat_id)) sesh = "" exp = "" if autochat: sesh = str(autochat.ses_id) exp = str(autochat.expires) SESSION.close() return sesh, exp
def migrate_chat(old_chat_id, new_chat_id): with INSERTION_FLOOD_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()
def get_warns(user_id, chat_id): try: user = SESSION.query(Warns).get((user_id, str(chat_id))) if not user: return None reasons = user.reasons num = user.num_warns return num, reasons finally: 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 else: return 1, "0" finally: SESSION.close()