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 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_filter(chat_id, keyword): try: return SESSION.query(Filters).get((str(chat_id), keyword)) except BaseException: return None finally: SESSION.close()
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 is_chat(chat_id): try: chat = SESSION.query(ChatbotChats).get(str(chat_id)) if chat: return True return False 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 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 fs_settings(chat_id): try: return ( SESSION.query(forceSubscribe) .filter(forceSubscribe.chat_id == chat_id) .one() ) except: return None finally: SESSION.close()
def rm_url_from_blacklist(chat_id, domain): with URL_BLACKLIST_FILTER_INSERTION_LOCK: domain_filt = SESSION.query(URLBlackListFilters).get( (str(chat_id), domain)) if domain_filt: if domain in CHAT_URL_BLACKLISTS.get(str(chat_id), set()): CHAT_URL_BLACKLISTS.get(str(chat_id), set()).remove(domain) SESSION.delete(domain_filt) SESSION.commit() return True SESSION.close() return False
def rm_afk(user_id): with INSERTION_LOCK: curr = SESSION.query(AFK).get(user_id) if curr: if user_id in AFK_USERS: # sanity check del AFK_USERS[user_id] del AFK_USERSS[user_id] SESSION.delete(curr) SESSION.commit() return True SESSION.close() return False
def __load_afk_users(): global AFK_USERS global AFK_USERSS try: all_afk = SESSION.query(AFK).all() AFK_USERS = { user.user_id: user.reason for user in all_afk if user.is_afk } AFK_USERSS = { user.user_id: user.start_time for user in all_afk if user.is_afk } finally: SESSION.close()
def _load_chat_blacklist(): global CHAT_URL_BLACKLISTS try: chats = SESSION.query(URLBlackListFilters.chat_id).distinct().all() for (chat_id, ) in chats: CHAT_URL_BLACKLISTS[chat_id] = [] all_urls = SESSION.query(URLBlackListFilters).all() for url in all_urls: CHAT_URL_BLACKLISTS[url.chat_id] += [url.domain] CHAT_URL_BLACKLISTS = { k: set(v) for k, v in CHAT_URL_BLACKLISTS.items() } finally: SESSION.close()
def is_chat(chat_id): try: chat = SESSION.query(ChatbotChats).get(str(chat_id)) return bool(chat) finally: SESSION.close()
def get_all_nsfw_enabled_chat(): stark = SESSION.query(Nsfwatch).all() SESSION.close() return stark
def check_afk_status(user_id): try: return SESSION.query(AFK).get(user_id) finally: SESSION.close()
def get_all_chat_id(): stark = SESSION.query(Nightmode).all() SESSION.close() return stark
def get_all_chats(): try: return SESSION.query(ChatbotChats.chat_id).all() finally: SESSION.close()