def __load_log_channels(): global CHANNELS try: all_chats = SESSION.query(GroupLogs).all() CHANNELS = {chat.chat_id: chat.log_channel for chat in all_chats} finally: SESSION.close()
def get_gdbye_buttons(chat_id): try: return SESSION.query(GoodbyeButtons).filter( GoodbyeButtons.chat_id == str(chat_id)).order_by( GoodbyeButtons.id).all() finally: SESSION.close()
def get_welc_buttons(chat_id): try: return SESSION.query(WelcomeButtons).filter( WelcomeButtons.chat_id == str(chat_id)).order_by( WelcomeButtons.id).all() finally: SESSION.close()
def __load_afk_users(): global AFK_USERS try: all_afk = SESSION.query(AFK).all() AFK_USERS = {user.user_id: user.reason for user in all_afk if user.is_afk} finally: SESSION.close()
def get_users_by_chat(chat_id, user_id): try: return SESSION.query(ChatMembers).filter(ChatMembers.user == user_id).all() except: SESSION.close() finally: SESSION.close()
def get_buttons(chat_id, note_name): try: return SESSION.query(Buttons).filter( Buttons.chat_id == str(chat_id), Buttons.note_name == note_name).order_by(Buttons.id).all() finally: SESSION.close()
def get_welc_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.should_welcome, welc.custom_welcome, welc.welcome_type, welc.caption_welcome else: # Welcome by default. return True, DEFAULT_WELCOME, Types.TEXT, None
def welcome_mutes(chat_id): try: welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id)) if welcomemutes: return welcomemutes.welcomemutes return False finally: SESSION.close()
def get_gban_alert(chat_id): with GBAN_SETTING_LOCK: gban_alert = SESSION.query(GbanSettings).get(str(chat_id)) if not gban_alert: SESSION.close() return None SESSION.close() return gban_alert.gban_alert
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 get_gmute_alert(chat_id): with GMUTE_SETTING_LOCK: gmute_alert = SESSION.query(GmuteSettings).get(str(chat_id)) if not gmute_alert: SESSION.close() return None SESSION.close() return gmute_alert.gmute_alert
def get_welc_mutes_pref(chat_id): welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id)) SESSION.close() if welcomemutes: return welcomemutes.welcomemutes return False
def get_chat_rules_pref(chat_id): curr = SESSION.query(Rules).get(str(chat_id)) SESSION.close() if curr: return curr.chat_rules return False
def get_rules(chat_id): rules = SESSION.query(Rules).get(str(chat_id)) ret = "" if rules: ret = rules.rules SESSION.close() return ret
def get_link(chat_id): chat_links = SESSION.query(Links).get(str(chat_id)) ret = "" if chat_links: ret = chat_links.chat_links SESSION.close() return ret
def get_link_mode(chat_id): link_mode = SESSION.query(Links).get(str(chat_id)) ret = "" if link_mode: ret = link_mode.link_mode SESSION.close() return ret
def get_gdbye_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.should_goodbye, welc.custom_leave, welc.leave_type else: # Welcome by default. return True, DEFAULT_GOODBYE, Types.TEXT
def get_rtl_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.rtl_del return False
def get_clean_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.clean_welcome return False
def get_custom_gdbye(chat_id): welcome_settings = SESSION.query(Welcome).get(str(chat_id)) ret = DEFAULT_GOODBYE if welcome_settings and welcome_settings.custom_leave: ret = welcome_settings.custom_leave SESSION.close() return ret
def get_join_event_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.join_event return False
def get_gmute_reason(user_id): with GMUTED_USERS_LOCK: reason = SESSION.query(GloballyMutedUsers).get(user_id) if not reason: SESSION.close() return None SESSION.close() return reason.reason
def get_custom_welcome(chat_id): welcome_settings = SESSION.query(Welcome).get(str(chat_id)) ret = DEFAULT_WELCOME if welcome_settings and welcome_settings.custom_welcome: ret = welcome_settings.custom_welcome SESSION.close() return ret
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_gban_reason(user_id): with GBANNED_USERS_LOCK: reason = SESSION.query(GloballyBannedUsers).get(user_id) if not reason: SESSION.close() return None SESSION.close() return reason.reason
def get_warn_time(chat_id): try: warn_time = SESSION.query(WarnSettings).get(str(chat_id)) if warn_time: return warn_time.warn_time else: return 0, False finally: SESSION.close()
def __load_gmute_stat_list(): global GMUTESTAT_LIST try: GMUTESTAT_LIST = { x.chat_id for x in SESSION.query(GmuteSettings).all() if not x.setting } finally: SESSION.close()
def get_flood_time(chat_id): try: flood_time = SESSION.query(FloodControl).get(str(chat_id)) if flood_time: return flood_time.flood_time else: return False, "0" finally: SESSION.close()
def __load_gmute_alert_list(): global GMUTEALERT_LIST try: GMUTEALERT_LIST = { x.chat_id for x in SESSION.query(GmuteSettings).all() if not x.gmute_alert } finally: SESSION.close()
def __load_disabled_commands(): global DISABLED try: all_chats = SESSION.query(Disable).all() for chat in all_chats: DISABLED.setdefault(chat.chat_id, set()).add(chat.command) finally: SESSION.close()