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 get_all_echos(): try: return SESSION.query(ECHOSQL).all() except BaseException: return None finally: SESSION.close()
def is_gmuted(sender_id): try: return SESSION.query(GMute).all() except: return None finally: SESSION.close()
def is_data_indb(chat_id: int): try: s__ = SESSION.query(Cst).get(str(chat_id)) if s__: return s__.sticker_token finally: SESSION.close()
def get_s(user_id, chat_id): try: return SESSION.query(LydiaAI).get((user_id, chat_id)) except BaseException: return None finally: SESSION.close()
def is_fed_indb(feds): try: return SESSION.query(Fed).filter(Fed.feds == feds).one() except: 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 is_gbanned(user_id: int): try: s__ = SESSION.query(Gban).get(str(user_id)) if s__: return s__.reason finally: SESSION.close()
def is_data_indbs(chat_id: int): try: s__ = SESSION.query(Pa).get(str(chat_id)) if s__: return s__.textto_append finally: SESSION.close()
def is_globelmuted(sender_id): try: return SESSION.query(GLOBELMute).all() except BaseException: return None finally: SESSION.close()
def rm_note(chat_id, keyword): note = SESSION.query(Notes).filter( Notes.chat_id == str(chat_id), Notes.keyword == keyword ) if note: note.delete() SESSION.commit()
def is_footer(chat_id: int): try: s__ = SESSION.query(Pa).get(str(chat_id)) if s__: return s__.append_foot 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_snips(): try: return SESSION.query(Snips).all() 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_all_s(): try: return SESSION.query(LydiaAI).all() 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 getcurrent_welcome_settings(chat_id): try: return (SESSION.query(JoinWelcome).filter( JoinWelcome.chat_id == str(chat_id)).one()) except BaseException: return None finally: SESSION.close()
def add_note(chat_id, keyword, reply): adder = SESSION.query(Notes).get((str(chat_id), keyword)) if adder: adder.reply = reply else: adder = Notes(str(chat_id), keyword, reply) SESSION.add(adder) 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 is_approved(chat_id): try: return SESSION.query(PMPermit).filter( PMPermit.chat_id == str(chat_id)).one() 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 num_blacklist_chat_filters(chat_id): try: return ( SESSION.query(BlackListFilters.chat_id) .filter(BlackListFilters.chat_id == str(chat_id)) .count() ) finally: SESSION.close()
def init_locks(chat_id, reset=False): curr_restr = SESSION.query(Locks).get(str(chat_id)) if reset: SESSION.delete(curr_restr) SESSION.flush() restr = Locks(str(chat_id)) SESSION.add(restr) SESSION.commit() return restr
def add_s(user_id, chat_id, session_id, session_expires): adder = SESSION.query(LydiaAI).get((user_id, chat_id)) if adder: adder.session_id = session_id adder.session_expires = session_expires else: adder = LydiaAI(user_id, chat_id, session_id, session_expires) SESSION.add(adder) SESSION.commit()
def __load_chat_warn_filters(): global WARN_FILTERS try: chats = SESSION.query(WarnFilters.chat_id).distinct().all() for (chat_id, ) in chats: # remove tuple by ( ,) WARN_FILTERS[chat_id] = [] all_filters = SESSION.query(WarnFilters).all() for x in all_filters: WARN_FILTERS[x.chat_id] += [x.keyword] WARN_FILTERS = { x: sorted(set(y), key=lambda i: (-len(i), i)) for x, y in WARN_FILTERS.items() } finally: SESSION.close()
def rmwelcome_setting(chat_id): try: rem = SESSION.query(JoinWelcome).get(str(chat_id)) if rem: SESSION.delete(rem) SESSION.commit() return True except BaseException: return False
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 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 get_warn_setting(chat_id): try: setting = SESSION.query(WarnSettings).get(str(chat_id)) if setting: return setting.warn_limit, setting.soft_warn else: return 3, False finally: SESSION.close()