def fs_settings(chat_id): try: return SESSION.query(forceSubscribe).filter(forceSubscribe.chat_id == chat_id).one() except: return None finally: SESSION.close()
def is_muted(sender_id): try: return SESSION.query(GMute).all() except: return None finally: SESSION.close()
def get_all_s(): try: return SESSION.query(LydiaAI).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_snips(): try: return SESSION.query(Snips).all() except: return None finally: SESSION.close()
def is_kread(): try: return SESSION.query(KRead).all() except BaseException: return None finally: SESSION.close()
def add_welcome_setting(chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, media_file_id): # adder = SESSION.query(Welcome).get(chat_id) adder = Welcome(chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, media_file_id) SESSION.add(adder) SESSION.commit()
def is_gbanned(chat_id): try: return SESSION.query(GBan).filter(GBan.chat_id == str(chat_id)).one() except BaseException: return None finally: SESSION.close()
def in_channels(chat_id): try: return SESSION.query(ghdb).filter(ghdb.chat_id == str(chat_id)).one() except BaseException: return None finally: SESSION.close()
def is_approved(chat_id): try: return SESSION.query(NOLogPMs).filter(NOLogPMs.chat_id == chat_id).one() 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_fban(chat_id): try: return SESSION.query(FBan).filter(FBan.chat_id == str(chat_id)).one() except: return None finally: SESSION.close()
def get_filter(chat_id, keyword): try: return SESSION.query(Filters).get((chat_id, keyword)) except: return None finally: SESSION.close()
def get_current_welcome_settings(chat_id): try: return SESSION.query(Welcome).filter(Welcome.chat_id == chat_id).one() except: return None finally: SESSION.close()
def addgvar(variable, value): if SESSION.query(Globals).filter( Globals.variable == str(variable)).one_or_none(): delgvar(variable) adder = Globals(str(variable), value) SESSION.add(adder) SESSION.commit()
def get_s(user_id, chat_id): try: return SESSION.query(LydiaAI).get((user_id, chat_id)) except: return None finally: SESSION.close()
def is_muted(chat_id): try: return SESSION.query(Mute).filter(Mute.chat_id == str(chat_id)).all() except: return None finally: SESSION.close()
def get_all_filters(chat_id): try: return SESSION.query(Filters).filter(Filters.chat_id == chat_id).all() except: 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 gvarstatus(variable): try: return SESSION.query(Globals).filter( Globals.variable == str(variable)).first().value except BaseException: return None 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 migrate_chat(old_chat_id, new_chat_id): with GBAN_SETTING_LOCK: chat = SESSION.query(GbanSettings).get(str(old_chat_id)) if chat: chat.chat_id = new_chat_id SESSION.add(chat) SESSION.commit()
def add_channel(chat_id, channel): adder = SESSION.query(forceSubscribe).get(chat_id) if adder: adder.channel = channel else: adder = forceSubscribe(chat_id, channel) SESSION.add(adder) SESSION.commit()
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 remove_s( user_id, chat_id ): note = SESSION.query(LydiaAI).get((user_id, chat_id)) if note: SESSION.delete(note) SESSION.commit()
def ungban_user(user_id): with GBANNED_USERS_LOCK: user = SESSION.query(GloballyBannedUsers).get(user_id) if user: SESSION.delete(user) SESSION.commit() __load_gbanned_userid_list()
def add_filter(chat_id, keyword, f_mesg_id): adder = SESSION.query(Filters).get((chat_id, keyword)) if adder: adder.f_mesg_id = f_mesg_id else: adder = Filters(chat_id, keyword, f_mesg_id) 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 remove_url(tg_chat_id, tg_feed_link): with INSERTION_LOCK: # this loops to delete any possible duplicates for the same TG User ID, TG Chat ID and link for row in check_url_availability(tg_chat_id, tg_feed_link): # add the action to the DB query SESSION.delete(row) SESSION.commit()
def add_snip(keyword, f_mesg_id): adder = SESSION.query(Snips).get(keyword) if adder: adder.f_mesg_id = f_mesg_id else: adder = Snips(keyword, f_mesg_id) SESSION.add(adder) SESSION.commit()