def get_all_s(): try: return SESSION.query(LydiaAI).all() 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_gmuted(sender_id): try: return SESSION.query(GMute).all() 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_footer(chat_id: int): try: s__ = SESSION.query(Pa).get(str(chat_id)) if s__: return s__.append_foot 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 get_snips(keyword): try: return SESSION.query(Snips).get(keyword) except: 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 get_all_snips(): try: return SESSION.query(Snips).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 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_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 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 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_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 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 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 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 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 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 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()
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 reset_warns(user_id, chat_id): with WARN_INSERTION_LOCK: warned_user = SESSION.query(Warns).get((user_id, str(chat_id))) if warned_user: warned_user.num_warns = 0 warned_user.reasons = [] SESSION.add(warned_user) SESSION.commit() 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 __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 remove_warn_filter(chat_id, keyword): with WARN_FILTER_INSERTION_LOCK: warn_filt = SESSION.query(WarnFilters).get((str(chat_id), keyword)) if warn_filt: if keyword in WARN_FILTERS.get(str(chat_id), []): # sanity check WARN_FILTERS.get(str(chat_id), []).remove(keyword) SESSION.delete(warn_filt) SESSION.commit() return True SESSION.close() return False
def addwelcome_setting(chat_id, previous_welcome, reply, f_mesg_id): to_check = getwelcome(chat_id) if not to_check: adder = JoinWelcome(chat_id, previous_welcome, reply, f_mesg_id) SESSION.add(adder) SESSION.commit() return True rem = SESSION.query(JoinWelcome).get(str(chat_id)) SESSION.delete(rem) SESSION.commit() adder = JoinWelcome(chat_id, previous_welcome, reply, f_mesg_id) SESSION.commit() return False
def set_flood(chat_id, amount): with INSERTION_LOCK: flood = SESSION.query(FloodControl).get(str(chat_id)) if not flood: flood = FloodControl(str(chat_id)) flood.user_id = None flood.limit = amount CHAT_FLOOD[str(chat_id)] = (None, DEF_COUNT, amount) SESSION.add(flood) SESSION.commit()